Skip to content

Latest commit

 

History

History
712 lines (659 loc) · 67.1 KB

File metadata and controls

712 lines (659 loc) · 67.1 KB

TSLint Migration Guide

This document serves as a guide to help you migrate from TSLint. It lists all TSLint rules along side rules from the ESLint ecosystem that are the same or similar.

TSLint rules

✅ = done
🌟 = in ESLint core
🔌 = in another plugin
🌓 = implementations differ or ESLint version is missing functionality
🛑 = unimplemented

TypeScript-specific

TSLint rule ESLint rule
adjacent-overload-signatures @typescript-eslint/adjacent-overload-signatures
ban-ts-ignore @typescript-eslint/ban-ts-comment
ban-types 🌓 @typescript-eslint/ban-types[1]
invalid-void @typescript-eslint/no-invalid-void-type
member-access @typescript-eslint/explicit-member-accessibility
member-ordering @typescript-eslint/member-ordering
no-any @typescript-eslint/no-explicit-any
no-empty-interface @typescript-eslint/no-empty-interface
no-import-side-effect 🔌 import/no-unassigned-import
no-inferrable-types @typescript-eslint/no-inferrable-types
no-internal-module @typescript-eslint/prefer-namespace-keyword
no-magic-numbers @typescript-eslint/no-magic-numbers
no-namespace @typescript-eslint/no-namespace
no-non-null-assertion @typescript-eslint/no-non-null-assertion
no-parameter-reassignment no-param-reassign
no-reference @typescript-eslint/triple-slash-reference
no-unnecessary-type-assertion @typescript-eslint/no-unnecessary-type-assertion
no-var-requires @typescript-eslint/no-var-requires
only-arrow-functions 🔌 prefer-arrow/prefer-arrow-functions
prefer-for-of @typescript-eslint/prefer-for-of
promise-function-async @typescript-eslint/promise-function-async
typedef-whitespace @typescript-eslint/type-annotation-spacing
typedef @typescript-eslint/typedef
unified-signatures @typescript-eslint/unified-signatures

[1] The ESLint rule only supports exact string matching, rather than regular expressions

Functionality

TSLint rule ESLint rule
await-promise @typescript-eslint/await-thenable
ban-comma-operator 🌟 no-sequences
ban 🌟 no-restricted-globals & no-restricted-properties
curly 🌟 curly
forin 🌟 guard-for-in
function-constructor 🌟 no-new-func
import-blacklist 🌟 no-restricted-imports
label-position 🌟 no-unused-labels (similar)
no-arg 🌟 no-caller (also blocks arguments.caller)
no-async-without-await @typescript-eslint/require-await
no-bitwise 🌟 no-bitwise
no-conditional-assignment 🌟 no-cond-assign[1]
no-console 🌟 no-console (configuration works slightly differently)
no-construct 🌟 no-new-wrappers
no-debugger 🌟 no-debugger
no-duplicate-super 🌟 constructor-super
no-duplicate-switch-case 🌟 no-duplicate-case
no-duplicate-variable 🌟 no-redeclare
no-dynamic-delete @typescript-eslint/no-dynamic-delete
no-empty 🌟 no-empty
no-eval 🌟 no-eval
no-floating-promises @typescript-eslint/no-floating-promises
no-for-in-array @typescript-eslint/no-for-in-array
no-implicit-dependencies 🔌 import/no-extraneous-dependencies
no-inferred-empty-object-type 🛑 N/A
no-invalid-template-strings 🌟 no-template-curly-in-string
no-invalid-this 🌟 no-invalid-this
no-misused-new @typescript-eslint/no-misused-new
no-null-keyword 🔌 no-null/no-null (doesn’t handle null type)
no-null-undefined-union 🛑 N/A
no-object-literal-type-assertion @typescript-eslint/consistent-type-assertions
no-promise-as-boolean @typescript-eslint/no-misused-promises
no-restricted-globals no-restricted-globals
no-return-await 🌟 no-return-await
no-shadowed-variable 🌟 no-shadow
no-sparse-arrays 🌟 no-sparse-arrays
no-string-literal 🌟 dot-notation
no-string-throw @typescript-eslint/no-throw-literal
no-submodule-imports 🌓 import/no-internal-modules (slightly different)
no-switch-case-fall-through 🌟 no-fallthrough
no-tautology-expression 🛑 N/A
no-this-assignment @typescript-eslint/no-this-alias
no-unbound-method @typescript-eslint/unbound-method
no-unnecessary-class @typescript-eslint/no-extraneous-class
no-unsafe-any 🌓 @typescript-eslint/no-unsafe-member-access[2]
no-unsafe-finally 🌟 no-unsafe-finally
no-unused-expression 🌟 no-unused-expressions
no-unused-variable 🌓 @typescript-eslint/no-unused-vars
no-use-before-declare @typescript-eslint/no-use-before-define
no-var-keyword 🌟 no-var
no-void-expression @typescript-eslint/no-confusing-void-expression
prefer-conditional-expression 🛑 N/A
prefer-object-spread 🌟 prefer-object-spread
radix 🌟 radix
restrict-plus-operands @typescript-eslint/restrict-plus-operands
static-this 🛑 N/A
strict-boolean-expressions @typescript-eslint/strict-boolean-expressions
strict-string-expressions @typescript-eslint/restrict-plus-operands & @typescript-eslint/restrict-template-expressions
strict-type-predicates 🛑 N/A
switch-default 🌟 default-case
triple-equals 🌟 eqeqeq
typeof-compare 🌟 valid-typeof
unnecessary-constructor 🌟 no-useless-constructor
use-default-type-parameter @typescript-eslint/no-unnecessary-type-arguments
use-isnan 🌟 use-isnan

[1] The ESLint rule also supports silencing with an extra set of parentheses (if ((foo = bar)) {})
[2] Only checks member expressions

Maintainability

TSLint rule ESLint rule
cyclomatic-complexity 🌟 complexity
deprecation 🔌 deprecation/deprecation
eofline 🌟 eol-last
indent @typescript-eslint/indent or Prettier
linebreak-style 🌟 linebreak-style or Prettier
max-classes-per-file 🌟 max-classes-per-file
max-file-line-count 🌟 max-lines
max-line-length 🌟 max-len or Prettier
no-default-export 🔌 import/no-default-export
no-default-import 🛑 N/A
no-duplicate-imports 🔌 import/no-duplicates
no-mergeable-namespace 🛑 N/A
no-require-imports @typescript-eslint/no-require-imports
object-literal-sort-keys 🌓 sort-keys [2]
prefer-const 🌟 prefer-const
prefer-readonly @typescript-eslint/prefer-readonly
trailing-comma 🌓 comma-dangle or Prettier

[2] Missing support for blank-line-delimited sections

Style

TSLint rule ESLint rule
align 🛑 N/A
array-type @typescript-eslint/array-type
arrow-parens 🌟 arrow-parens
arrow-return-shorthand 🌟 arrow-body-style
binary-expression-operand-order 🌟 yoda
callable-types @typescript-eslint/prefer-function-type
class-name @typescript-eslint/naming-convention
comment-format 🌟 capitalized-comments & spaced-comment
comment-type 🛑 N/A
completed-docs 🔌 jsdoc/require-jsdoc
encoding 🛑 N/A
file-header 🔌 eslint-plugin-header or -file-header
file-name-casing 🔌 unicorn/filename-case
import-spacing 🔌 Use Prettier
increment-decrement 🌟 no-plusplus
interface-name @typescript-eslint/interface-name-prefix
interface-over-type-literal @typescript-eslint/consistent-type-definitions
jsdoc-format 🌓 valid-jsdoc or eslint-plugin-jsdoc
match-default-export-name 🛑 N/A
newline-before-return 🌟 padding-line-between-statements [1]
newline-per-chained-call 🌟 newline-per-chained-call
new-parens 🌟 new-parens
no-angle-bracket-type-assertion @typescript-eslint/consistent-type-assertions
no-boolean-literal-compare @typescript-eslint/no-unnecessary-boolean-literal-compare
no-consecutive-blank-lines 🌟 no-multiple-empty-lines
no-irregular-whitespace 🌟 no-irregular-whitespace with skipStrings: false
no-parameter-properties @typescript-eslint/no-parameter-properties
no-redundant-jsdoc 🔌 jsdoc/no-types
no-reference-import @typescript-eslint/triple-slash-reference
no-trailing-whitespace 🌟 no-trailing-spaces
no-unnecessary-callback-wrapper 🛑 N/A and this might be unsafe (i.e. with forEach)
no-unnecessary-else 🌟 no-else-return [2]
no-unnecessary-initializer 🌟 no-undef-init
no-unnecessary-qualifier @typescript-eslint/no-unnecessary-qualifier
number-literal-format 🛑 N/A
object-literal-key-quotes 🌟 quote-props
object-literal-shorthand 🌟 object-shorthand
one-line 🌟 brace-style or Prettier
one-variable-per-declaration 🌟 one-var
ordered-imports 🌓 import/order
prefer-function-over-method 🌟 class-methods-use-this
prefer-method-signature @typescript-eslint/method-signature-style
prefer-switch 🛑 N/A
prefer-template 🌟 prefer-template
prefer-while 🛑 N/A
quotemark 🌟 quotes
return-undefined 🛑 N/A
semicolon 🌓 @typescript-eslint/semi
space-before-function-paren 🌟 space-before-function-paren
space-within-parens 🌟 space-in-parens
switch-final-break 🛑 N/A
type-literal-delimiter @typescript-eslint/member-delimiter-style
unnecessary-bind 🌟 no-extra-bind
variable-name @typescript-eslint/naming-convention
whitespace 🔌 Use Prettier

[1] Recommended config: ["error", { blankLine: "always", prev: "*", next: "return" }]
[2] Doesn't check other control flow statements, such as break or continue.

tslint-microsoft-contrib rules

Rule listing is here. Deprecated rules are excluded (missing-jsdoc, missing-optional-annotation, no-duplicate-case, no-duplicate-parameter-names, no-function-constructor-with-string-args, no-increment-decrement, no-empty-interfaces, no-missing-visibility-modifiers, no-multiple-var-decl, no-reserved-keywords, no-stateless-class, no-var-self, no-unnecessary-bind, and valid-typeof). See the docs in the link above to find out what to use instead.

Testing

Relevant plugins: chai-expect-keywords, chai-expect, chai-friendly, mocha, and jest

tslint-microsoft-contrib rule ESLint rule
chai-prefer-contains-to-index-of 🛑 N/A
chai-vague-errors 🛑 N/A
mocha-avoid-only 🔌 jest/no-focused-tests
mocha-unneeded-done 🛑 N/A

TypeScript

tslint-microsoft-contrib rule ESLint rule
prefer-array-literal 🌓 @typescript-eslint/no-array-constructor [1]
prefer-type-cast 🛑 N/A

[1] ESLint rule is slightly less strict, allowing new Array<Foo>() and Array(2).

Miscellaneous

tslint-microsoft-contrib rule ESLint rule
export-name 🛑 N/A (relevant plugin)
function-name 🛑 N/A
import-name 🛑 N/A (relevant plugin)
informative-docs 🛑 N/A
insecure-random 🔌 custom implementation
max-func-body-length 🌟 max-statements
no-banned-terms 🌟 no-caller & no-eval
no-constant-condition 🌟 no-constant-condition
no-control-regex 🌟 no-control-regex
no-delete-expression @typescript-eslint/no-dynamic-delete
no-empty-line-after-opening-brace 🌟 padded-blocks [1] or Prettier
no-for-in 🌟 no-restricted-syntax [2]
no-function-expression 🌟 func-style [3]
no-invalid-regexp 🌟 no-invalid-regexp
no-multiline-string 🌟 no-multi-str
no-octal-literal 🌟 no-octal-escape, see also no-octal
no-regex-spaces 🌟 no-regex-spaces
no-relative-imports 🛑 N/A, Not recommended by the maintainers
no-single-line-block-comment 🛑 N/A
no-suspicious-comment 🌟 no-warning-comments [4]
no-typeof-undefined 🛑 N/A (this actually has a valid use: checking if a variable is defined)
no-unexternalized-strings 🛑 N/A
no-unnecessary-field-initialization 🌓 no-undef-init [5]
no-unnecessary-local-variable 🛑 N/A
no-unnecessary-override 🛑 N/A
no-unnecessary-semicolons 🌟 no-extra-semi or Prettier
no-useless-files 🛑 N/A
no-with-statement 🌟 no-with
promise-must-complete 🛑 N/A
underscore-consistent-invocation 🔌 lodash/chaining
use-named-parameter 🛑 N/A
use-simple-attributes 🛑 N/A

[1] Enforces blank lines both at the beginning and end of a block
[2] Recommended config: ["error", "ForInStatement"]
[3] Recommended config: ["error", "declaration", { "allowArrowFunctions": true }]
[4] Recommended config: ["error", { "terms": ["BUG", "HACK", "FIXME", "LATER", "LATER2", "TODO"], "location": "anywhere" }]
[5] Does not check class fields.

Security

tslint-microsoft-contrib rule ESLint rule
no-disable-auto-sanitization 🛑 N/A
no-document-domain 🌓 Use no-restricted-syntax
no-http-string 🛑 N/A
no-inner-html 🛑 N/A
no-string-based-set-immediate 🛑 N/A
no-string-based-set-interval 🛑 N/A
no-string-based-set-timeout 🛑 N/A
react-iframe-missing-sandbox 🛑 N/A
react-no-dangerous-html 🔌 react/no-danger
non-literal-fs-path 🔌 security/detect-non-literal-fs-filename
non-literal-require 🔌 security/detect-non-literal-require
possible-timing-attack 🔌 security/detect-possible-timing-attacks

Browser

tslint-microsoft-contrib rule ESLint rule
jquery-deferred-must-complete 🛑 N/A
no-backbone-get-set-outside-model 🛑 N/A
no-cookies 🌓 Use no-restricted-syntax
no-document-write 🌓 Use no-restricted-syntax
no-exec-script 🌓 Use no-restricted-syntax
no-jquery-raw-elements 🛑 N/A
no-unsupported-browser-code 🛑 N/A
react-this-binding-issue 🛑 N/A
react-tsx-curly-spacing 🔌 react/jsx-curly-spacing
react-unused-props-and-state 🌓 react/no-unused-state

React A11y

tslint-microsoft-contrib rule ESLint rule
react-a11y-accessible-headings 🌓 jsx-a11y/heading-has-content [1]
react-a11y-anchors 🔌 jsx-a11y/anchor-is-valid
react-a11y-aria-unsupported-elements 🔌 jsx-a11y/aria-unsupported-elements
react-a11y-event-has-role 🌓 jsx-a11y/no-static-element-interactions [2]
react-a11y-image-button-has-alt 🔌 jsx-a11y/alt-text
react-a11y-img-has-alt 🔌 jsx-a11y/alt-text
react-a11y-input-elements 🛑 N/A
react-a11y-lang 🔌 jsx-a11y/lang
react-a11y-meta 🛑 N/A
react-a11y-no-onchange 🔌 jsx-a11y/no-onchange
react-a11y-props 🔌 jsx-a11y/aria-props
react-a11y-proptypes 🔌 jsx-a11y/aria-proptypes
react-a11y-required 🛑 N/A
react-a11y-role-has-required-aria-props 🔌 jsx-a11y/role-has-required-aria-props
react-a11y-role-supports-aria-props 🔌 jsx-a11y/role-supports-aria-props
react-a11y-role 🔌 jsx-a11y/aria-role
react-a11y-tabindex-no-positive 🔌 jsx-a11y/tabindex-no-positive
react-a11y-titles 🛑 N/A
react-anchor-blank-noopener 🛑 N/A

[1] TSLint rule is more strict
[2] ESLint rule only reports for click handlers