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
In your tslint.json
file, add the rulesDirectory
property, e.g:
{
"rulesDirectory": "node_modules/tslint-eslint-rules/dist/rules",
"rules": {
"no-constant-condition": true
}
}
You can also pass an array of strings to the rulesDirectory
property to combine this plugin with other community custom 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 | no-duplicate-key | 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 | no-irregular-whitespace | disallow irregular whitespace outside of strings and comments (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 | 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 | no-unreachable | disallow unreachable statements after a return, throw, continue, or break statement (recommended) |
✅ | use-isnan | use-isnan | disallow comparisons with the value NaN (recommended) |
✅ | valid-jsdoc | valid-jsdoc | Ensure JSDoc comments are valid |
✅ | 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 | accessor-pairs | treat var statements as if they were block scoped |
❌ | complexity | 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 | no-alert | disallow the use of alert , confirm , and prompt |
☑️ | 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-function | 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 | no-labels | 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-new | 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-new-wrappers | 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 | no-proto | disallow Usage 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 | 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 | 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-throw-literal | 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 | yoda | require or disallow Yoda conditions |
These rules relate to using strict mode.
❔ | ESLint | TSLint | Description |
---|---|---|---|
❌ | strict | strict | 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 declaration of variables that are not used in the code (recommended) |
☑️ | no-use-before-define | no-use-before-define | 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 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 | 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 | eol-last | enforce newline at the end of file, with no multiple empty lines |
❌ | 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 | indent | specify tab or space width for your code |
❌ | 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 |
❌ | keyword-spacing | keyword-spacing | enforce spacing before and after keywords |
❌ | 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 | max-len | specify the maximum length of a line in your program |
❌ | 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 | 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-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 | ident | disallow mixed spaces and tabs for indentation (recommended) |
❌ | no-multiple-empty-lines | no-multiple-empty-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-var | 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 | padded-blocks | enforce padding within blocks |
❌ | quote-props | quote-props | require quotes around object literal property names |
❌ | quotes | quote-props | specify whether backticks, double or single quotes should be used |
❌ | require-jsdoc | require-jsdoc | Require JSDoc comment |
❌ | semi | semi | 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 |
❌ | space-unary-ops | space-unary-ops | require or disallow spaces before/after unary operators |
❌ | spaced-comment | spaced-comment | require or disallow a space immediately following the // or /* in a comment |
❌ | wrap-regex | wrap-regex | require regex literals to be wrapped in parentheses |
These rules are only relevant to ES6 environments.
❔ | ESLint | TSLint | Description |
---|---|---|---|
❌ | arrow-body-style | arrow-body-style | require braces in arrow function body |
❌ | arrow-parens | arrow-parens | require parens in arrow function arguments |
❌ | arrow-spacing | arrow-spacing | require space before/after arrow function's arrow |
❌ | constructor-super | constructor-super | 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 | no-const-assign | 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 | no-this-before-super | 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-shorthand | require method and property shorthand syntax for object literals |
❌ | prefer-arrow-callback | prefer-arrow-callback | suggest using arrow functions as callbacks |
❌ | prefer-const | prefer-const | suggest using const declaration for variables that are never modified after declared |
❌ | 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 a new rule or fix/improve some existing rule you can fork this repository and follow the instructions below.
- Open an issue asking for the rule or bug.
- Create a branch with the rule name, e.g: no-if-usage
- Run
npm install
- Create your rule tests at
./src/test/rules
and your rule in./src/rules
with the convention:- Name: rule-name (hyphenated, e.g: no-if-usage)
- Rule File: ruleNameRule.ts (camelCased and with the
Rule
suffix, e.g: noIfUsageRule.ts) - Test File: ruleNameRuleTests.ts (camelCased and with the
RuleTests
suffix, e.g: noIfUsageRuleTests.ts)
- Check if your rule is passing with
gulp test --single rule-name
(hyphenated, e.g no-inner-declarations)- During development you may have some linting errors that won't let you run the test. You can
disable the linting process with the
--no-lint
flag. That is rungulp test --single rule-name --no-lint
- During development you may have some linting errors that won't let you run the test. You can
disable the linting process with the
- Make sure that all the tests are passing with
gulp test
. - Update the file
src/readme/rules.ts
with the rule information. - To update the README file with the information you just updated run
gulp readme
. This will also update/create the rule documentation indocs/rules
. You may add more details about the rule in this file. - Commit the changes to your repo with the following convention:
- Example:
[feat] added use-isnan rule (closes #20)
- Example:
- Finally, open a Pull Request.
You can also contribute with PRs for fixing bugs, or improving documentation, performance. The commit convention for these are, respectively:
- Example:
[bug] fixed no-constant-condition rule (closes #9)
- Example:
[docs] improved README.md file (closes #32)
- Example:
[perf] improved valid-typeof rule (closes #48)
MIT