1.13.10 • Published 3 years ago

tslint-etc v1.13.10

Weekly downloads
28,922
License
MIT
Repository
github
Last release
3 years ago

tslint-etc

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

TSLint is deprecated. All of the rules in this package have equivalent ESLint rules in the eslint-plugin-etc package or have 'official' ESLint equivalents.

And ESLint implementations this package's dtslint-related rules can be found in the eslint-plugin-dtslint package.

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):

RuleDescriptionFixerOptions
ban-importsDisallows the use of banned imports.NoSee below
expect-deprecationAsserts deprecations with $ExpectDeprecation and $ExpectNoDeprecation.NoNone
expect-typeAsserts types with $ExpectType and presence of errors with $ExpectError. You can use ESLint and this rule to perform your type tests without having to install or run dtslint.NoNone
no-assign-mutated-arrayDisallows the assignment of returned, mutated arrays. Useful for those times you forget that sort and reverse mutate the array upon which they are called.NoNone
no-const-enumDisallows the use of const enum. Constant enums are not compatible with isolated modules.NoSee below
no-dtslint-typoDisallows dtslint-like expectations that have typographical errors.NoNone
no-enumDisallows the use of enum.NoNone
no-implicit-any-catchLike the no-implicit-any-catch rule in @typescript-eslint/eslint-plugin, but for Promise rejections, too.
no-tDisallows single-character type parameters.NoNone
no-unsafe-callback-scopeDisallows the use of variables/properties from unsafe/outer scopes in callbacks.NoSee below
no-unused-declarationDisallows unused declarations.Yes, but see belowSee below
throw-errorEnforces the use of Error values when throwing or rejecting.NoNone

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-const-enum

This rule takes an optional object with an optional allowLocal property - which defaults to false. If allowLocal is true, only exported const enums are forbidden.

For example, to following configuration would local (i.e. non-exported) const enums:

"rules": {
  "no-const-enum": {
    "options": [{
      "allowLocal": true
    }],
    "severity": "error"
  }
}

no-unsafe-callback-scope

This rule takes an optional object with optional allowMethods, allowParameters and allowProperties properties.

If the allowMethods option is true, calling methods via this is allowed.

If the allowParameters option is true, referencing function parameters from outer scopes is allowed.

If the allowProperties option is true, accessing properties via this is allowed.

The following options are equivalent to the rule's default configuration:

"rules": {
  "no-unsafe-callback-scope": {
    "options": [{
      "allowMethods": true,
      "allowParameters": true,
      "allowProperties": 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, declarations and ignored properties. The imports and declarations properties are booleans and determine whether or not unused imports or declarations are allowed. They default to true. The ignored property is an object containing keys that are regular expressions and values that are booleans - indicating whether or not matches are ignored.

For example:

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

3 years ago

1.13.9

3 years ago

1.13.8

3 years ago

1.13.7

4 years ago

1.13.6

4 years ago

1.13.5

4 years ago

1.13.4

4 years ago

1.13.3

4 years ago

1.13.2

4 years ago

1.13.1

4 years ago

1.13.0

4 years ago

1.12.0

4 years ago

1.11.1

4 years ago

1.11.0

4 years ago

1.10.1

4 years ago

1.10.0

4 years ago

1.9.2

4 years ago

1.9.1

4 years ago

1.9.0

4 years ago

1.8.0

4 years ago

1.7.1

5 years ago

1.6.1

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.6

5 years ago

1.5.5

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.12

5 years ago

1.2.11

5 years ago

1.2.10

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-rc.1

6 years ago

1.0.0-rc.0

6 years ago