New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-typelint

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-typelint

ESlint rule for optional typing in JavaScript, based on JSDoc

  • 1.0.1
  • npm
  • Socket score

Version published
Weekly downloads
144
decreased by-28.36%
Maintainers
1
Weekly downloads
 
Created
Source

TypeLint

TypeLint is an ESlint plugin for optional typing in JavaScript, based on JSDoc.

Every application manages data, which is usually described in some way.

For example:

  • Swagger definitions
  • JSON based database schemas (MongoDB, RethinkDB, CouchDB etc)
  • Redux store (folded reducers)
  • GraphQL schemas

Mission of TypeLint is to provide complex type checking, based on already described data structures of your app.

Demo

Installation

npm i eslint && npm i eslint-plugin-typelint

If you use eslint globally, you should install typelint globally as well.

Put typelint to eslint plugins array and add needed rules:

  • typelint/composite - checks composite types, based on models
  • typelint/primitive - checks access to JavaScript primitive types properties

For example, your .eslintrc can look as following:

{
  "env": {
    "node": true,
    "es6": true
  },
  "rules": {
    "no-console": 0,
    "no-param-reassign": 2,
    "typelint/composite": 2,
    "typelint/primitive": 2
  },
  "settings": {
      "typelint": {
          "models": {
              "json": {
                  "dir": "./models"
              }
          }
      }
  }
}

# Usage

Extend your JSDoc comments with TypeLint notations <typeName>:

/**
 * @param movieObject <movie>
 */
function getDirector(movieObject) {

Now TypeLint knows, that movieObject parameter has type of movie

Run ESLint from terminal

./node_modules/.bin/eslint .

or enable ESLint tools in your IDE, e.g WebStorm:

Features

Currently TypeLint supports JSON Schema for describing data interfaces.

JSON Schema is advanced, popular and well documented format for describing JSON data.

For example if you use Swagger for your API, you already have JSON Schema definitions, that you can use.

Also you can bind Mongoose schemas using TypeLint adapters.

To bind your models to TypeLint, put the following settings block to the root of your .eslintrc:

  "settings": {
      "typelint": {
          "models": {
              "json": {
                  "dir": "./models"
              }
          }
      }
  }

Models are expected as files, where each of them contains one definition.

Name of the file is a name of the model.

Supported formats:

  • JSON
  • YAML
  • JS files as common.js modules (export object is a schema)

What it is and what it is not

TypeLint is a helper, but not a full-fledged typed system for js.

If you want to make your code 100% typed, please use any of existing static typed languages, which can be transpiled to JavaScript (TypeScript, Flow etc)

The goal of TypeLint is to help developer avoid undefined errors, but optionally and staying all the speed and flexibility of pure JavaScript developement.

BTW TypeLint was written with help of TypeLint 😊️

All .eslinrc typelint settings options

  • models.json.dir - {String} path to your models dir. Every file is a separate model
  • models.json.exclude - {Array} array of paths, that models finder should ignore while loading models
  • adapters - {Array} array of paths to modules, which exports functions :: yourSchema -> JSONSchema.
  • useCache - {Boolean} caches all models (will work faster, but changes in models will not affect). Default: false

See also settings schema, that TypeLint is using for typing check itself.

Planned features

  • Support Redux store shape
  • Support GraphQL schemas
  • Possibility to use /@var/ definitions everywhere
  • Handle passing typed variables (partially including)
  • Detect when variable was reassigned
  • Other types of models bindings

License

MIT.

Keywords

FAQs

Package last updated on 05 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc