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