Giter Site home page Giter Site logo

tslint-etc's Introduction

tslint-etc

GitHub License NPM version Downloads Build status dependency status devDependency Status peerDependency Status Greenkeeper badge

What is it?

tslint-etc is set of TSLint rules to enforce policies that cannot be specified - or easily specified - with the built-in rules.

Install

Install the package using NPM:

npm install tslint-etc --save-dev

Update your tslint.json file to extend this package and add any rules you want to configure to the rules object:

{
  "extends": [
    "tslint-etc"
  ],
  "rules": {
    "throw-error": { "severity": "error" }
  }
}

Rules

WARNING: Before configuring any of the following rules, you should ensure that TSLint's no-unused-variable rule is not enabled in your configuration (or in any configuration that you extend). That rule has caused problems in the past - as it leaves the TypeScript program in an unstable state - and has a significant number of still-open issues. Consider using this package's no-unused-declaration rule instead.

The package includes the following rules (none of which are enabled by default):

Rule Description Fixer Options
ban-imports Disallows the use of banned imports. No See below
no-assign-mutated-array Disallows the assignment of returned, mutated arrays. Useful for those times you forget that sort and reverse mutate the array upon which they are called. No None
no-missing-dollar-expect Disallows dtslint $ExpectType and $ExpectError expectations if the $ is missing. No None
no-unsafe-callback-scope Disallows the use of variables/properties from unsafe/outer scopes in callbacks. No None
no-unused-declaration Disallows unused declarations. Yes, but see below See below
throw-error Enforces the use of Error values when throwing or rejecting. No None

Options and notes

ban-imports

The ban-imports rule takes an object containing keys that are regular expressions and values that are either booleans or strings containing the explanation for the ban.

For example, to following configuration would disallow "foo" with an explanation, would disallow "bar" without an explanation and would allow "baz":

"rules": {
  "ban-imports": {
    "options": [{
      "^foo$": "'foo' has been deprecated; use 'baz'",
      "^bar$": true,
      "^baz$": false
    }],
    "severity": "error"
  }
}

no-unused-declaration

This rule has a fixer. However, the fixer will only remove unused import declarations. It will not remove other kinds of declarations, as doing so could be potentially destructive.

For example, having it remove a function that you've spent time writing - just because you've not yet exported or called it - would be too dispiriting, so the rule will just flag it as a failure and leave the function untouched.

The rule takes an optional object with optional imports and declarations properties. The properties are booleans and determine whether or unused imports or declarations are allowed. The properties default to true.

For example:

"rules": {
  "no-unused-declaration": {
    "options": [{
      "declarations": true,
      "imports": true
    }],
    "severity": "error"
  }
}

tslint-etc's People

Contributors

cartant avatar greenkeeper[bot] avatar scottarver avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.