ESLint rules for TSLint
Improve your TSLint with the missing ESLint Rules
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!
WARN: this project is still under development.
You can see what rules were already migrated in the eslint_tslint.json file
Usage
Install from NPM to your Dev Dependencies
npm install --save-dev tslint-eslint-rules
Configure TSLint to use tslint-eslint-rules
folder:
-
TSLint CLI
tslint [file] -r node_modules/tslint-eslint-rules/dist/rules
-
Gulp (gulp-tslint
)
gulp
.src()
.pipe(tslint({
rulesDirectory: 'node_modules/tslint-eslint-rules/dist/rules'
}));
-
Grunt (grunt-tslint
)
grunt.initConfig({
tslint: {
options: {
configuration: grunt.file.readJSON('tslint.json'),
rulesDirectory: 'node_modules/tslint-eslint-rules/dist/rules'
},
files: {
src: []
}
}
})
-
WebStorm
Open File > Settings
and follow the example below:
-
Atom (linter-tslint
)
It's not possible to use custom rules using the linter-tslint
plugin at this moment.
We already created an issue for them, but unfortunately, the codebase is in CoffeeScript, and we can't help with a pull request.
-
Sublime Text (SublimeLinter-contrib-tslint
)
In your Packages/User/SublimeLinter.sublime-settings
file, you can configure tslint
options, similar to the example bellow:
{
"user": {
"linters": {
"tslint": {
"args": [
"--r=node_modules/tslint-eslint-rules/dist/rules"
]
}
}
}
}
Configure your rules
Then, in your tslint.json
file, insert the rules as described below.
The list below shows all the existing ESLint rules and the similar rules available in TSLint.
Possible Errors
The following rules point out areas where you might have made mistakes.
-
comma-dangle => trailing-comma (native)
-
Description: disallow or enforce trailing commas (recommended)
-
Usage
"trailing-comma": [
true,
{
"multiline": "always",
"singleline": "never"
}
]
-
no-cond-assign => no-conditional-assignment (native)
-
no-console => no-console (native)
-
Description: disallow use of console
in the node environment (recommended)
-
Usage
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
]
-
no-constant-condition => no-constant-condition (tslint-eslint-rules)
-
no-control-regex => no-control-regex (tslint-eslint-rules) TODO
-
no-debugger => no-debugger (native)
-
no-dupe-args => not applicable to TypeScript
- Description: disallow duplicate arguments in functions (recommended)
-
no-dupe-keys => no-duplicate-key (native)
-
no-duplicate-case => no-duplicate-case (tslint-eslint-rules)
-
no-empty-character-class => no-empty-character-class (tslint-eslint-rules) TODO
-
no-empty => no-empty (native)
-
no-ex-assign => no-ex-assign (tslint-eslint-rules) TODO
-
no-extra-boolean-cast => no-extra-boolean-cast (tslint-eslint-rules)
-
no-extra-parens => no-extra-parens (tslint-eslint-rules) TODO (low priority)
-
Description: disallow unnecessary parentheses
-
Usage
"no-extra-parens": [
true,
"functions"
]
"no-extra-parens": [
true,
"all"
]
-
no-extra-semi => no-extra-semi (tslint-eslint-rules)
-
no-func-assign => not applicable to TypeScript
- Description: disallow overwriting functions written as function declarations (recommended)
-
no-inner-declarations => no-inner-declarations (tslint-eslint-rules) TODO
-
Description: disallow function or variable declarations in nested blocks (recommended)
-
Usage
"no-inner-declarations": [
true,
"functions"
]
"no-inner-declarations": [
true,
"both"
]
-
no-invalid-regexp => no-invalid-regex (tslint-eslint-rules) TODO
-
no-irregular-whitespace => no-irregular-whitespace (tslint-eslint-rules) TODO
-
no-negated-in-lhs => not applicable to TypeScript
- Description: disallow negation of the left operand of an
in
expression (recommended)
-
no-obj-calls => not applicable to TypeScript
- Description: disallow the use of object properties of the global object (
Math
and JSON
) as functions (recommended)
-
no-regex-spaces => no-regex-spaces (tslint-eslint-rules) TODO
-
no-sparse-arrays => no-sparse-arrays (tslint-eslint-rules)
-
no-unexpected-multiline => no-unexpected-multiline (tslint-eslint-rules) TODO
-
no-unreachable => no-unreachable (native)
-
Description: disallow unreachable statements after a return, throw, continue, or break statement (recommended)
-
Usage
"no-unreachable": true
-
use-isnan => use-isnan (tslint-eslint-rules)
-
valid-jsdoc => valid-jsdoc (tslint-eslint-rules) TODO
-
Description: Ensure JSDoc comments are valid
-
Usage
"valid-jsdoc": [
true,
{
"prefer": {
"return": "returns"
},
"requireReturn": false,
"requireParamDescription": true,
"requireReturnDescription": true,
"matchDescription": "^[A-Z][A-Za-z0-9\\s]*[.]$"
}
]
-
valid-typeof => valid-typeof (tslint-eslint-rules)
Best Practices
These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing something or help you avoid footguns.
- accessor-pairs =>
- block-scoped-var =>
- complexity =>
-
Description: specify the maximum cyclomatic complexity allowed in a program
-
Usage
"complexity": [
true,
{
}
]
- consistent-return =>
-
Description: require return
statements to either always or never specify values
-
Usage
"consistent-return": [
true,
{
}
]
- curly =>
- default-case =>
- dot-location =>
- dot-notation =>
- eqeqeq =>
- guard-for-in =>
- no-alert =>
-
Description: disallow the use of alert
, confirm
, and prompt
-
Usage
"no-alert": [
true,
{
}
]
- no-caller =>
- no-case-declarations =>
- no-div-regex =>
-
Description: disallow division operators explicitly at beginning of regular expression
-
Usage
"no-div-regex": [
true,
{
}
]
- no-else-return =>
- no-empty-label =>
-
Description: disallow use of labels for anything other than loops and switches
-
Usage
"no-empty-label": [
true,
{
}
]
- no-empty-pattern =>
- no-eq-null =>
-
Description: disallow comparisons to null without a type-checking operator
-
Usage
"no-eq-null": [
true,
{
}
]
- no-eval =>
- no-extend-native =>
- no-extra-bind =>
- no-fallthrough =>
- no-floating-decimal =>
-
Description: disallow the use of leading or trailing decimal points in numeric literals
-
Usage
"no-floating-decimal": [
true,
{
}
]
- no-implicit-coercion =>
-
Description: disallow the type conversions with shorter notations
-
Usage
"no-implicit-coercion": [
true,
{
}
]
- no-implied-eval =>
- no-invalid-this =>
-
Description: disallow this
keywords outside of classes or class-like objects
-
Usage
"no-invalid-this": [
true,
{
}
]
- no-iterator =>
- no-labels =>
- no-lone-blocks =>
- no-loop-func =>
- no-magic-numbers =>
- no-multi-spaces =>
- no-multi-str =>
- no-native-reassign =>
- no-new-func =>
- no-new-wrappers =>
-
Description: disallows creating new instances of String
,Number
, and Boolean
-
Usage
"no-new-wrappers": [
true,
{
}
]
- no-new =>
- no-octal-escape =>
-
Description: disallow use of octal escape sequences in string literals, such as var foo = "Copyright \251";
-
Usage
"no-octal-escape": [
true,
{
}
]
- no-octal =>
- no-param-reassign =>
- no-process-env =>
- no-proto =>
- no-redeclare =>
- no-return-assign =>
- no-script-url =>
- no-self-compare =>
-
Description: disallow comparisons where both sides are exactly the same
-
Usage
"no-self-compare": [
true,
{
}
]
- no-sequences =>
- no-throw-literal =>
- no-unused-expressions =>
-
Description: disallow Usage
of expressions in statement position
-
Usage
"no-unused-expressions": [
true,
{
}
]
- no-useless-call =>
- no-useless-concat =>
-
Description: disallow unnecessary concatenation of literals or template literals
-
Usage
"no-useless-concat": [
true,
{
}
]
- no-void =>
- no-warning-comments - disallow Usage
of configurable warning terms in comments =>
- no-with =>
- radix =>
- vars-on-top =>
-
Description: require declaration of all vars at the top of their containing scope
-
Usage
"vars-on-top": [
true,
{
}
]
- wrap-iife =>
-
Description: require immediate function invocation to be wrapped in parentheses
-
Usage
"wrap-iife": [
true,
{
}
]
- yoda =>
Strict Mode
These rules relate to using strict mode.
Variables
These rules have to do with variable declarations.
- init-declarations =>
-
Description: enforce or disallow variable initializations at definition
-
Usage
"init-declarations": [
true,
{
}
]
- no-catch-shadow =>
-
Description: disallow the catch clause parameter name being the same as a variable in the outer scope
-
Usage
"no-catch-shadow": [
true,
{
}
]
- no-delete-var =>
- no-label-var =>
- no-shadow-restricted-names =>
-
Description: disallow shadowing of names such as arguments
-
Usage
"no-shadow-restricted-names": [
true,
{
}
]
- no-shadow =>
-
Description: disallow declaration of variables already declared in the outer scope
-
Usage
"no-shadow": [
true,
{
}
]
- no-undef-init =>
- no-undef =>
-
Description: disallow use of undeclared variables unless mentioned in a /*global */
block (recommended)
-
Usage
"no-undef": [
true,
{
}
]
- no-undefined =>
- no-unused-vars =>
-
Description: disallow declaration of variables that are not used in the code (recommended)
-
Usage
"no-unused-vars": [
true,
{
}
]
- no-use-before-define =>
Node.js and CommonJS
These rules are specific to JavaScript running on Node.js or using CommonJS in the browser.
Stylistic Issues
These rules are purely matters of style and are quite subjective.
- array-bracket-spacing =>
- block-spacing =>
- brace-style =>
- camelcase =>
- comma-spacing =>
- comma-style =>
- computed-property-spacing =>
-
Description: require or disallow padding inside computed properties
-
Usage
"computed-property-spacing": [
true,
{
}
]
- consistent-this =>
-
Description: enforce consistent naming when capturing the current execution context
-
Usage
"consistent-this": [
true,
{
}
]
- eol-last =>
-
Description: enforce newline at the end of file, with no multiple empty lines
-
Usage
"eol-last": [
true,
{
}
]
- func-names =>
- func-style =>
- id-length =>
-
Description: this option enforces minimum and maximum identifier lengths (variable names, property names etc.)
-
Usage
"id-length": [
true,
{
}
]
- id-match =>
- indent =>
- jsx-quotes =>
-
Description: specify whether double or single quotes should be used in JSX attributes
-
Usage
"jsx-quotes": [
true,
{
}
]
- key-spacing =>
-
Description: enforce spacing between keys and values in object literal properties
-
Usage
"key-spacing": [
true,
{
}
]
- linebreak-style =>
- lines-around-comment =>
- max-nested-callbacks =>
- new-cap =>
- new-parens =>
-
Description: disallow the omission of parentheses when invoking a constructor with no arguments
-
Usage
"new-parens": [
true,
{
}
]
- newline-after-var =>
-
Description: require or disallow an empty newline after variable declarations
-
Usage
"newline-after-var": [
true,
{
}
]
- no-array-constructor =>
- no-continue =>
- no-inline-comments =>
- no-lonely-if =>
- no-mixed-spaces-and-tabs =>
-
Description: disallow mixed spaces and tabs for indentation (recommended)
-
Usage
"no-mixed-spaces-and-tabs": [
true,
{
}
]
- no-multiple-empty-lines =>
- no-negated-condition =>
- no-nested-ternary =>
- no-new-object =>
- no-restricted-syntax =>
- no-spaced-func =>
-
Description: disallow space between function identifier and application
-
Usage
"no-spaced-func": [
true,
{
}
]
- no-ternary =>
- no-trailing-spaces =>
- no-underscore-dangle =>
- no-unneeded-ternary =>
-
Description: disallow the use of ternary operators when a simpler alternative exists
-
Usage
"no-unneeded-ternary": [
true,
{
}
]
- object-curly-spacing =>
- one-var =>
- operator-assignment =>
-
Description: require assignment operator shorthand where possible or prohibit it entirely
-
Usage
"operator-assignment": [
true,
{
}
]
- operator-linebreak =>
-
Description: enforce operators to be placed before or after line breaks
-
Usage
"operator-linebreak": [
true,
{
}
]
- padded-blocks =>
- quote-props =>
- quotes =>
- require-jsdoc =>
- semi-spacing =>
- semi =>
- sort-vars =>
- space-after-keywords =>
- space-before-blocks =>
- space-before-function-paren =>
-
Description: require or disallow a space before function opening parenthesis
-
Usage
"space-before-function-paren": [
true,
{
}
]
- space-before-keywords =>
- space-in-parens =>
- space-infix-ops =>
- space-return-throw-case =>
-
Description: require a space after return
, throw
, and case
-
Usage
"space-return-throw-case": [
true,
{
}
]
- space-unary-ops =>
-
Description: require or disallow spaces before/after unary operators
-
Usage
"space-unary-ops": [
true,
{
}
]
- spaced-comment =>
-
Description: require or disallow a space immediately following the //
or /*
in a comment
-
Usage
"spaced-comment": [
true,
{
}
]
- wrap-regex =>
ECMAScript 6
These rules are only relevant to ES6 environments.
Legacy
The following rules are included for compatibility with JSHint and JSLint. While the names of the rules may not match up with the JSHint/JSLint counterpart, the functionality is the same.
- max-depth =>
- max-len =>
- max-params =>
-
Description: limits the number of parameters that can be used in the function declaration.
-
Usage
"max-params": [
true,
{
}
]
- max-statements =>
-
Description: specify the maximum number of statement allowed in a function
-
Usage
"max-statements": [
true,
{
}
]
- no-bitwise =>
- no-plusplus =>
-
Description: disallow use of unary operators, ++
and --
-
Usage
"no-plusplus": [
true,
{
}
]
Contributing
Bugs, rules requests, doubts etc., open a Github Issue.
If you didn't find the rule, you can also create an ESLint custom rule for TSLint:
- Forking this repo
- Run
npm isntall
- Run
gulp
to run the tests and watch for file changes - Create your rule tests at
./src/test/rules
and your rule in ./src/rules
with the convetion:
- Name: rule-name (hyphenated)
- File: ruleNameRule.ts (camelCased and with the
Rule
suffix) - Test File: ruleNameRuleTests.ts (camelCased and with the
RuleTests
suffix)
- Check if all the tests are passing
- Commit the changes to your repo and open a Pull Request
LICENSE
MIT