I originally created this project because it was impossible to run ESLint on a TypeScript codebase. Today you can use https://github.com/typescript-eslint/typescript-eslint for that purpose, so this project is unmaintained and deprecated.
You want to code in TypeScript but miss all the rules available in ESLint?
Now you can combine both worlds by using this TSLint plugin!
npm install --save-dev tslint-eslint-rules
yarn add tslint-eslint-rules --dev
In your tslint.json
file, source the rules from this package, e.g:
{
"rules": {
"no-constant-condition": true
},
"rulesDirectory": [
"node_modules/tslint-eslint-rules/dist/rules"
]
}
You can also add other tslint config packages to combine these rules with other custom community rules.
In your tslint.json
file, insert the rules as described below.
Rules (copied from the ESLint website)
The following tables shows all the existing ESLint rules and the similar rules available in TSLint. Please refer to the following icons as they provide the status of the rule.
Icon | Description |
---|---|
🚫 | The rule is not applicable to Typescript. |
☑️ | The rule is provided natively by TSLint. |
✅ | The rule is available via tslint-eslint-rules. |
❌ | The rule is currently unavailable. |
The following rules point out areas where you might have made mistakes.
❔ | ESLint | TSLint | Description |
---|---|---|---|
☑️ | comma-dangle | trailing-comma | disallow or enforce trailing commas (recommended) |
☑️ | no-cond-assign | no-conditional-assignment | disallow assignment in conditional expressions (recommended) |
☑️ | no-console | no-console | disallow use of console in the node environment (recommended) |
✅ | no-constant-condition | no-constant-condition | disallow use of constant expressions in conditions (recommended) |
✅ | no-control-regex | no-control-regex | disallow control characters in regular expressions (recommended) |
☑️ | no-debugger | no-debugger | disallow use of debugger (recommended) |
🚫 | no-dupe-args | Not applicable | disallow duplicate arguments in functions (recommended) |
🚫 | no-dupe-keys | Not applicable | disallow duplicate keys when creating object literals (recommended) |
✅ | no-duplicate-case | no-duplicate-case | disallow a duplicate case label. (recommended) |
☑️ | no-empty | no-empty | disallow empty statements (recommended) |
✅ | no-empty-character-class | no-empty-character-class | disallow the use of empty character classes in regular expressions (recommended) |
✅ | no-ex-assign | no-ex-assign | disallow assigning to the exception in a catch block (recommended) |
✅ | no-extra-boolean-cast | no-extra-boolean-cast | disallow double-negation boolean casts in a boolean context (recommended) |
❌ | no-extra-parens | no-extra-parens | disallow unnecessary parentheses |
✅ | no-extra-semi | no-extra-semi | disallow unnecessary semicolons (recommended) |
🚫 | no-func-assign | Not applicable | disallow overwriting functions written as function declarations (recommended) |
✅ | no-inner-declarations | no-inner-declarations | disallow function or variable declarations in nested blocks (recommended) |
✅ | no-invalid-regexp | no-invalid-regexp | disallow invalid regular expression strings in the RegExp constructor (recommended) |
✅ | no-irregular-whitespace | ter-no-irregular-whitespace | disallow irregular whitespace (recommended) |
🚫 | no-negated-in-lhs | Not applicable | disallow negation of the left operand of an in expression (recommended) |
🚫 | no-obj-calls | Not applicable | disallow the use of object properties of the global object (Math and JSON ) as functions (recommended) |
✅ | no-regex-spaces | no-regex-spaces | disallow multiple spaces in a regular expression literal (recommended) |
✅ | no-sparse-arrays | ter-no-sparse-arrays | disallow sparse arrays (recommended) |
✅ | no-unexpected-multiline | no-unexpected-multiline | Avoid code that looks like two expressions but is actually one |
🚫 | no-unreachable | Not applicable | disallow unreachable statements after a return, throw, continue, or break statement (recommended) |
☑️ | no-unsafe-finally | no-unsafe-finally | disallow control flow statements in finally blocks (recommended) |
☑️ | use-isnan | use-isnan | disallow comparisons with the value NaN (recommended) |
✅ | valid-jsdoc | valid-jsdoc | enforce valid JSDoc comments |
✅ | valid-typeof | valid-typeof | Ensure that the results of typeof are compared against a valid string (recommended) |
These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing something or help you avoid footguns.
❔ | ESLint | TSLint | Description |
---|---|---|---|
❌ | accessor-pairs | accessor-pairs | Enforces getter/setter pairs in objects |
❌ | array-callback-return | array-callback-return | Enforce return statements in callbacks of array’s methods |
❌ | block-scoped-var | block-scoped-var | treat var statements as if they were block scoped |
☑️ | complexity | cyclomatic-complexity | specify the maximum cyclomatic complexity allowed in a program |
❌ | consistent-return | consistent-return | require return statements to either always or never specify values |
☑️ | curly | curly | specify curly brace conventions for all control statements |
☑️ | default-case | switch-default | require default case in switch statements |
❌ | dot-location | dot-location | enforces consistent newlines before or after dots |
❌ | dot-notation | dot-notation | encourages use of dot notation whenever possible |
☑️ | eqeqeq | triple-equals | require the use of === and !== |
☑️ | guard-for-in | forin | make sure for-in loops have an if statement |
☑️ | no-alert | ban | disallow the use of alert , confirm , and prompt can be achieved using the "ban": [true, ["alert"]] tslint rule |
☑️ | no-caller | no-arg | disallow use of arguments.caller or arguments.callee |
❌ | no-case-declarations | no-case-declarations | disallow lexical declarations in case clauses |
❌ | no-div-regex | no-div-regex | disallow division operators explicitly at beginning of regular expression |
❌ | no-else-return | no-else-return | disallow else after a return in an if |
☑️ | no-empty-function | no-empty | disallow use of empty functions |
❌ | no-empty-pattern | no-empty-pattern | disallow use of empty destructuring patterns |
❌ | no-eq-null | no-eq-null | disallow comparisons to null without a type-checking operator |
☑️ | no-eval | no-eval | disallow use of eval() |
❌ | no-extend-native | no-extend-native | disallow adding to native types |
❌ | no-extra-bind | no-extra-bind | disallow unnecessary function binding |
❌ | no-extra-label | no-extra-label | disallow unnecessary labels |
☑️ | no-fallthrough | no-switch-case-fall-through | disallow fallthrough of case statements (recommended) |
❌ | no-floating-decimal | no-floating-decimal | disallow the use of leading or trailing decimal points in numeric literals |
❌ | no-implicit-coercion | no-implicit-coercion | disallow the type conversions with shorter notations |
❌ | no-implicit-globals | no-implicit-globals | disallow var and named functions in global scope |
❌ | no-implied-eval | no-implied-eval | disallow use of eval() -like methods |
☑️ | no-invalid-this | no-invalid-this | disallow this keywords outside of classes or class-like objects |
❌ | no-iterator | no-iterator | disallow Usage of __iterator__ property |
☑️ | no-labels | label-position | disallow use of labeled statements |
❌ | no-lone-blocks | no-lone-blocks | disallow unnecessary nested blocks |
❌ | no-loop-func | no-loop-func | disallow creation of functions within loops |
☑️ | no-magic-numbers | no-magic-numbers | disallow the use of magic numbers |
✅ | no-multi-spaces | no-multi-spaces | disallow use of multiple spaces |
❌ | no-multi-str | no-multi-str | disallow use of multiline strings |
🚫 | no-native-reassign | Not applicable | disallow reassignments of native objects |
☑️ | no-new | no-unused-expression | disallow use of the new operator when not part of an assignment or comparison |
❌ | no-new-func | no-new-func | disallow use of new operator for Function object |
☑️ | no-new-wrappers | no-construct | disallows creating new instances of String ,Number , and Boolean |
🚫 | no-octal | Not applicable | disallow use of octal literals (recommended) |
❌ | no-octal-escape | no-octal-escape | disallow use of octal escape sequences in string literals, such as var foo = "Copyright \251"; |
❌ | no-param-reassign | no-param-reassign | disallow reassignment of function parameters |
✅ | no-proto | ter-no-proto | disallow the use of __proto__ property |
☑️ | no-redeclare | no-duplicate-variable | disallow declaring the same variable more than once (http://eslint.org/docs/rules/recommended) |
❌ | no-return-assign | no-return-assign | disallow use of assignment in return statement |
✅ | no-script-url | ter-no-script-url | disallow use of javascript: urls. |
❌ | no-self-assign | no-self-assign | disallow assignments where both sides are exactly the same |
✅ | no-self-compare | ter-no-self-compare | disallow comparisons where both sides are exactly the same |
❌ | no-sequences | no-sequences | disallow use of the comma operator |
☑️ | no-throw-literal | no-string-throw | restrict what can be thrown as an exception |
❌ | no-unmodified-loop-condition | no-unmodified-loop-condition | disallow unmodified conditions of loops |
☑️ | no-unused-expressions | no-unused-expression | disallow Usage of expressions in statement position |
❌ | no-unused-labels | no-unused-labels | disallow unused labels |
❌ | no-useless-call | no-useless-call | disallow unnecessary .call() and .apply() |
❌ | no-useless-concat | no-useless-concat | disallow unnecessary concatenation of literals or template literals |
❌ | no-useless-escape | no-useless-escape | disallow unnecessary usage of escape character |
❌ | no-void | no-void | disallow use of the void operator |
❌ | no-warning-comments | no-warning-comments | disallow Usage of configurable warning terms in comments e.g. TODO or FIXME |
❌ | no-with | no-with | disallow use of the with statement |
☑️ | radix | radix | require use of the second argument for parseInt() |
❌ | vars-on-top | vars-on-top | require declaration of all vars at the top of their containing scope |
❌ | wrap-iife | wrap-iife | require immediate function invocation to be wrapped in parentheses |
☑️ | yoda | binary-expression-operand-order | disallow Yoda conditions |
These rules relate to using strict mode.
❔ | ESLint | TSLint | Description |
---|---|---|---|
🚫 | strict | Not applicable | require effective use of strict mode directives |
These rules have to do with variable declarations.
❔ | ESLint | TSLint | Description |
---|---|---|---|
❌ | init-declarations | init-declarations | enforce or disallow variable initializations at definition |
❌ | no-catch-shadow | no-catch-shadow | disallow the catch clause parameter name being the same as a variable in the outer scope |
🚫 | no-delete-var | Not applicable | disallow deletion of variables (recommended) |
❌ | no-label-var | no-label-var | disallow labels that share a name with a variable |
☑️ | no-shadow | no-shadowed-variable | disallow declaration of variables already declared in the outer scope |
❌ | no-shadow-restricted-names | no-shadow-restricted-names | disallow shadowing of names such as arguments |
🚫 | no-undef | Not applicable | disallow use of undeclared variables unless mentioned in a /*global */ block (recommended) |
❌ | no-undef-init | no-undef-init | disallow use of undefined when initializing variables |
❌ | no-undefined | no-undefined | disallow use of undefined variable |
☑️ | no-unused-vars | no-unused-variable | disallow unused variables (recommended). |
☑️ | no-use-before-define | no-use-before-declare | disallow use of variables before they are defined |
These rules are specific to JavaScript running on Node.js or using CommonJS in the browser.
❔ | ESLint | TSLint | Description |
---|---|---|---|
❌ | callback-return | callback-return | enforce return after a callback |
❌ | global-require | global-require | enforce require() on top-level module scope |
✅ | handle-callback-err | handle-callback-err | enforce error handling in callbacks |
❌ | no-mixed-requires | no-mixed-requires | disallow mixing regular variable and require declarations |
❌ | no-new-require | no-new-require | disallow use of new operator with the require function |
❌ | no-path-concat | no-path-concat | disallow string concatenation with __dirname and __filename |
❌ | no-process-env | no-process-env | disallow use of process.env |
❌ | no-process-exit | no-process-exit | disallow process.exit() |
❌ | no-restricted-modules | no-restricted-modules | restrict Usage of specified node modules |
❌ | no-sync | no-sync | disallow use of synchronous methods |
These rules are purely matters of style and are quite subjective.
❔ | ESLint | TSLint | Description |
---|---|---|---|
✅ | array-bracket-spacing | array-bracket-spacing | enforce consistent spacing inside array brackets |
✅ | block-spacing | block-spacing | disallow or enforce spaces inside of single line blocks |
✅ | brace-style | brace-style | enforce one true brace style |
☑️ | camelcase | variable-name | require camel case names |
❌ | comma-spacing | comma-spacing | enforce spacing before and after comma |
❌ | comma-style | comma-style | enforce one true comma style |
✅ | computed-property-spacing | ter-computed-property-spacing | require or disallow padding inside computed properties |
❌ | consistent-this | consistent-this | enforce consistent naming when capturing the current execution context |
☑️ | eol-last | eofline | enforce newline at the end of file, with no multiple empty lines |
✅ | func-call-spacing | ter-func-call-spacing | require or disallow spacing between function identifiers and their invocations |
❌ | func-names | func-names | require function expressions to have a name |
❌ | func-style | func-style | enforce use of function declarations or expressions |
❌ | id-blacklist | id-blacklist | disallow certain identifiers to prevent them being used |
❌ | id-length | id-length | this option enforces minimum and maximum identifier lengths (variable names, property names etc.) |
❌ | id-match | id-match | require identifiers to match the provided regular expression |
✅ | indent | ter-indent | enforce consistent indentation |
❌ | jsx-quotes | jsx-quotes | specify whether double or single quotes should be used in JSX attributes |
❌ | key-spacing | key-spacing | enforce spacing between keys and values in object literal properties Tslint's whitespace can partially be used |
❌ | keyword-spacing | keyword-spacing | enforce spacing before and after keywords Tslint's whitespace can partially be used |
☑️ | linebreak-style | linebreak-style | disallow mixed 'LF' and 'CRLF' as linebreaks |
❌ | lines-around-comment | lines-around-comment | enforce empty lines around comments |
❌ | max-depth | max-depth | specify the maximum depth that blocks can be nested |
✅ | max-len | ter-max-len | enforce a maximum line length |
☑️ | max-lines | max-file-line-count | enforce a maximum number of lines per file |
❌ | max-nested-callbacks | max-nested-callbacks | specify the maximum depth callbacks can be nested |
❌ | max-params | max-params | specify the number of parameters that can be used in the function declaration |
❌ | max-statements | max-statements | specify the maximum number of statement allowed in a function |
❌ | max-statements-per-line | max-statements-per-line | specify the maximum number of statements allowed per line |
🚫 | new-cap | Not applicable | require a capital letter for constructors |
☑️ | new-parens | new-parens | disallow the omission of parentheses when invoking a constructor with no arguments |
✅ | newline-after-var | ter-newline-after-var | require or disallow an empty newline after variable declarations |
❌ | newline-before-return | newline-before-return | require newline before return statement |
❌ | newline-per-chained-call | newline-per-chained-call | enforce newline after each call when chaining the calls |
❌ | no-array-constructor | no-array-constructor | disallow use of the Array constructor |
☑️ | no-bitwise | no-bitwise | disallows bitwise operators |
❌ | no-continue | no-continue | disallow use of the continue statement |
❌ | no-inline-comments | no-inline-comments | disallow comments inline after code |
❌ | no-lonely-if | no-lonely-if | disallow if as the only statement in an else block |
✅ | no-mixed-spaces-and-tabs | ter-no-mixed-spaces-and-tabs | disallow mixed spaces and tabs for indentation (recommended) |
☑️ | no-multiple-empty-lines | no-consecutive-blank-lines | disallow multiple empty lines |
❌ | no-negated-condition | no-negated-condition | disallow negated conditions |
❌ | no-nested-ternary | no-nested-ternary | disallow nested ternary expressions |
❌ | no-new-object | no-new-object | disallow the use of the Object constructor |
❌ | no-restricted-syntax | no-restricted-syntax | disallow use of certain syntax in code |
❌ | no-spaced-func | no-spaced-func | disallow space between function identifier and application |
❌ | no-ternary | no-ternary | disallow the use of ternary operators |
☑️ | no-trailing-spaces | no-trailing-whitespace | disallow trailing whitespace at the end of lines |
❌ | no-underscore-dangle | no-underscore-dangle | disallow dangling underscores in identifiers |
❌ | no-unneeded-ternary | no-unneeded-ternary | disallow the use of ternary operators when a simpler alternative exists |
❌ | no-whitespace-before-property | no-whitespace-before-property | disallow whitespace before properties |
✅ | object-curly-spacing | object-curly-spacing | require or disallow padding inside curly braces |
☑️ | one-var | one-variable-per-declaration | require or disallow one variable declaration per function |
❌ | one-var-declaration-per-line | one-var-declaration-per-line | require or disallow a newline around variable declarations |
❌ | operator-assignment | operator-assignment | require assignment operator shorthand where possible or prohibit it entirely |
❌ | operator-linebreak | operator-linebreak | enforce operators to be placed before or after line breaks |
✅ | padded-blocks | ter-padded-blocks | enforce padding within blocks |
☑️ | quote-props | object-literal-key-quotes | require quotes around object literal property names |
☑️ | quotes | quotemark | specify whether backticks, double or single quotes should be used |
❌ | require-jsdoc | require-jsdoc | Require JSDoc comment |
☑️ | semi | semicolon | require or disallow use of semicolons instead of ASI |
❌ | semi-spacing | semi-spacing | enforce spacing before and after semicolons |
✅ | sort-imports | sort-imports | enforce sorting import declarations within module |
❌ | sort-vars | sort-vars | sort variables within the same declaration block |
❌ | space-before-blocks | space-before-blocks | require or disallow a space before blocks |
❌ | space-before-function-paren | space-before-function-paren | require or disallow a space before function opening parenthesis |
✅ | space-in-parens | space-in-parens | require or disallow spaces inside parentheses |
❌ | space-infix-ops | space-infix-ops | require spaces around operators Tslint's whitespace can partially be used |
❌ | space-unary-ops | space-unary-ops | require or disallow spaces before/after unary operators |
☑️ | spaced-comment | comment-format | require or disallow a space immediately following the // or /* in a comment |
❌ | wrap-regex | wrap-regex | require regex literals to be wrapped in parentheses |
✅ | no-tabs | ter-no-tabs | disallow all tabs |
These rules are only relevant to ES6 environments.
❔ | ESLint | TSLint | Description |
---|---|---|---|
✅ | arrow-body-style | ter-arrow-body-style | require braces in arrow function body |
✅ | arrow-parens | ter-arrow-parens | require parens in arrow function arguments |
✅ | arrow-spacing | ter-arrow-spacing | require space before/after arrow function's arrow |
🚫 | constructor-super | Not applicable | verify calls of super() in constructors |
❌ | generator-star-spacing | generator-star-spacing | enforce spacing around the * in generator functions |
❌ | no-class-assign | no-class-assign | disallow modifying variables of class declarations |
❌ | no-confusing-arrow | no-confusing-arrow | disallow arrow functions where they could be confused with comparisons |
🚫 | no-const-assign | Not applicable | disallow modifying variables that are declared using const |
🚫 | no-dupe-class-members | Not applicable | disallow duplicate name in class members |
❌ | no-duplicate-imports | no-duplicate-imports | disallow duplicate module imports |
❌ | no-new-symbol | no-new-symbol | disallow use of the new operator with the Symbol object |
❌ | no-restricted-imports | no-restricted-imports | restrict usage of specified modules when loaded by import declaration |
🚫 | no-this-before-super | Not applicable | disallow use of this /super before calling super() in constructors. |
❌ | no-useless-constructor | no-useless-constructor | disallow unnecessary constructor |
☑️ | no-var | no-var-keyword | require let or const instead of var |
☑️ | object-shorthand | object-literal-shorthand | require method and property shorthand syntax for object literals |
✅ | prefer-arrow-callback | ter-prefer-arrow-callback | require arrow functions as callbacks |
☑️ | prefer-const | prefer-const | suggest using const declaration for variables that are never modified after declared |
❌ | prefer-destructuring | prefer-destructuring | require using destructuring when assigning to variables from arrays and objects |
❌ | prefer-reflect | prefer-reflect | suggest using Reflect methods where applicable |
❌ | prefer-rest-params | prefer-rest-params | suggest using the rest parameters instead of arguments |
❌ | prefer-spread | prefer-spread | suggest using the spread operator instead of .apply() . |
❌ | prefer-template | prefer-template | suggest using template literals instead of strings concatenation |
❌ | require-yield | require-yield | disallow generator functions that do not have yield |
❌ | template-curly-spacing | template-curly-spacing | enforce spacing around embedded expressions of template strings |
❌ | yield-star-spacing | yield-star-spacing | enforce spacing around the * in yield* expressions |
Bugs, rules requests, doubts etc., open a Github Issue. If you want to create one of the missing rules or fix/improve some existing rule please check out the contribution guide.
MIT