Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

tslint-etc

cartant34.2kMIT1.13.10TypeScript support: included

More rules for TSLint

lint, rules, tslint

readme

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

Rule Description Fixer Options
ban-imports Disallows the use of banned imports. No See below
expect-deprecation Asserts deprecations with $ExpectDeprecation and $ExpectNoDeprecation. No None
expect-type Asserts 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. No None
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-const-enum Disallows the use of const enum. Constant enums are not compatible with isolated modules. No See below
no-dtslint-typo Disallows dtslint-like expectations that have typographical errors. No None
no-enum Disallows the use of enum. No None
no-implicit-any-catch Like the no-implicit-any-catch rule in @typescript-eslint/eslint-plugin, but for Promise rejections, too.
no-t Disallows single-character type parameters. No None
no-unsafe-callback-scope Disallows the use of variables/properties from unsafe/outer scopes in callbacks. No See below
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-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"
  }
}

changelog

1.13.10 (2021-05-19)

Fixes

  • Support Array constructors in the no-assign-mutated-array rule. (e86d200)

1.13.9 (2020-11-28)

Fixes

  • Add index.js to files in package.json. (836cf8f)

1.13.8 (2020-11-28)

Changes

  • Use files in package.json instead of .npmignore. (f5fdb0e)

1.13.7 (2020-09-08)

Changes

  • Widen the TypeScript peer dependency range. (417f224)

1.13.6 (2020-08-25)

Fixes

  • Use the correct DOMException capitalization. (93fe131)

1.13.5 (2020-08-25)

Changes

  • Relax throw-error to allow throwing or rejecting a DomException. (b57d3bb)

1.13.4 (2020-08-23)

Changes

  • Don't include the TypeScript version in expect-type failure messages. (405c129)

1.13.3 (2020-08-23)

Fixes

  • In expect-type, ignore diagnostics that don't have lines. (2fe12e3)

1.13.2 (2020-08-23)

Changes

  • Remove newlines from expect-type failure message. (2391839)

1.13.1 (2020-08-10)

Fixes

  • In the no-assign-mutated-array rule, treat splice as an array creator - it returns an array containing the deleted elements. (2298a6f)

1.13.0 (2020-07-18)

Features

  • Added the no-array-foreach rule. (afea026)

1.12.0 (2020-07-12)

Features

  • Added the no-implicit-any-catch rule. (b9aeb5a)

1.11.1 (2020-06-24)

Changes

  • Don't distribute the yarn.lock file.

1.11.0 (2020-06-08)

Features

  • Support ImportEqualsDeclaration nodes in the no-unused-dependency rule. (db44d74)

1.10.1 (2020-02-29)

Fixes

  • Widen tslint peer dependency. (23b03d1)

1.10.0 (2019-12-07)

Features

  • Add a prefix option to the no-t rule. (fd63c43)

1.9.2 (2019-11-05)

Fix

  • Use a more relaxed RegExp in no-dtslint-typo. (50b4fac)

1.9.1 (2019-11-04)

Fix

  • Pass the actual version of the local typescript package in the expect-type rule. (19a35c2)

1.9.0 (2019-11-04)

Features

1.8.0 (2019-11-04)

Features

  • Add the expect-deprecation rule. (92488a4)
  • Add the no-dtslint-typo rule. (df1d697)

Changes

  • Deprecate the no-missing-dollar-expect rule. (8300eb5)

1.7.1 (2019-10-28)

Fixes

  • Don't delete a file's leading comment when removing the first unused import. (6b3beba)

1.7.0 (2019-08-28)

Features

1.6.1 (2019-10-26)

Notes

  • Published by accident. This should have been 1.7.1.

1.6.0 (2019-07-20)

Features

  • Add an ignored option to no-unused-declaration. (8f83c76)

1.5.6 (2019-06-28)

Fixes

  • Ignore qualified names in no-unsafe-callback-scope. (0a92549)

1.5.5 (2019-06-19)

Fixes

  • Add console to the no-unsafe-callback-scope whitelist. (a4a766a)

1.5.4 (2019-06-19)

Fixes

  • Fixed problems with no-unsafe-callback-scope and property-access expressions. (93d5fc0)

1.5.3 (2019-05-22)

Fixes

  • Fix no-unused-declaration fixer for situations in which default and named imports are (un)used together - see #21. (a68d3c0)

1.5.2 (2019-04-26)

Fixes

  • Fix a bug with imports and the no-unused-declaration rule - see #19. (4bbf6cc)

1.5.1 (2019-04-13)

Fixes

  • Support interfaces and type aliases in the no-unused-declaration rule. (bdc71ba)

1.5.0 (2019-03-31)

Features

  • Add an allowLocal option to the no-const-enum rule. (1637c8d)

1.4.4 (2019-03-30)

Fixes

  • Don't delete imports more than once when fixing no-unused-declaration failures. (a8b634d)

1.4.3 (2019-03-29)

Fixes

  • Allow removal of props via destructing with no-unused-declaration enabled. (e0699a7)

1.4.2 (2019-03-29)

Fixes

  • Fix a problem with no-unused-declaration and defaultProps. (2235987)

1.4.1 (2019-03-27)

Fixes

  • Don't use typed rules for no-enum and no-const-enum. (58ac299)

1.4.0 (2019-03-27)

Features

  • Add no-enum and no-const-enum rules. (06f2f59)

1.3.2 (2019-02-25)

Fixes

  • Allow throwing and rethrowing any. (6146d14)

1.3.1 (2019-02-23)

Changes

  • Replaced util.ts with tsutils-etc.

1.3.0 (2019-02-15)

Features

  • Added options to the no-unused-declaration rule. (e592d9d)

1.2.12 (2018-12-24)

Fixes

  • The no-unused-declaration rule now supports overload signatures. (a9fd1d8)
  • The no-unused-declaration rule now supports hoisting functions into object shorthand. (2bc3eb9)

1.2.11 (2018-12-22)

Fixes

  • no-unsafe-callback-scope rule now supports readonly, static class properties and parameter destructuring. (85f0801)

1.2.10 (2018-12-21)

Fixes

  • no-unsafe-callback-scope rule now considers instanceof constructors safe. (604aee3)

1.2.9 (2018-12-15)

Fixes

  • Apply fixes - from rxjs-tslint-rules - to no-unsafe-callback-scope rule. (956d7fd)

1.2.8 (2018-12-14)

Fixes

  • Supported pre/postfix operators in the no-unused-declaration rule. (788bb3a)

1.2.7 (2018-10-24)

Features

  • Added no-assign-mutated-array rule. (c4e8504)

1.2.6 (2018-09-12)

Features

  • Added no-missing-dollar-expect for dtslint expectations.

1.2.5 (2018-09-06)

Fixes

  • Fixed a problem with no-unused-declaration false positives when using functions and object-shorthand properties. (2dcdfac)
  • Fixed a problem with no-unused-declaration false positives when using self-closing JSX elements. (7948bc7)

1.2.4 (2018-09-01)

Fixes

  • Fixed a problem with no-unused-declaration false positives for exports. (600ce3c)
  • Fixed a problem with no-unused-declaration false positives for hoisted functions. (5d17a2b)
  • Fixed a problem with no-unused-declaration false positives for JSX-related imports. (a46596d)

1.2.3 (2018-07-31)

Build

  • Widen TypeScript peer semver to allow for version 3.0. (fb28cb1)

1.2.2 (2018-05-07)

Fixes

  • Fixed a problem in which the no-unused-declaration rule throw errors when inspecting variables typed as any. (b07c760)

1.2.1 (2018-05-07)

Fixes

  • Fixed a problem in which the no-unused-declaration rule did not recognise usage via object shorthand. (cc86c2e)

1.2.0 (2018-05-07)

Features

  • Added a fixer to the no-unused-declaration rule for unused imports. Other unused declarations must be fixed manually, as their automated removal would be considerably more destructive and could result in lost work. (95c221d)

Fixes

  • The no-unused-declaration rule now detects unused default imports. (cc70e40)

Build

  • The TSLint testing infrastructure is now used instead of Mocha. (1076253)

1.1.0 (2018-05-06)

Features

  • Added a no-unused-declaration rule. It's similar to TSLint's built-in no-unused-variable rule, but has a simpler implementation and fewer problems. Hopefully.