ter

tslint-eslint-rules

Improve your TSLint with the missing ESLint rules

Showing:

Popularity

Downloads/wk

287K

GitHub Stars

724

Maintenance

Last Commit

4mos ago

Contributors

49

Package

Dependencies

3

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Build Status Downloads per Month NPM Version ZenHub Shields.io License

DEPRECATED

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.

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!

Usage

Install from NPM to your Dev Dependencies

npm install --save-dev tslint-eslint-rules

Or install from Yarn to your Dev Dependencies

yarn add tslint-eslint-rules --dev

Configure TSLint to use tslint-eslint-rules:

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.

Configure your 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.

IconDescription
🚫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.

Possible Errors

The following rules point out areas where you might have made mistakes.

ESLintTSLintDescription
☑️comma-dangletrailing-commadisallow or enforce trailing commas (recommended)
☑️no-cond-assignno-conditional-assignmentdisallow assignment in conditional expressions (recommended)
☑️no-consoleno-consoledisallow use of console in the node environment (recommended)
no-constant-conditionno-constant-conditiondisallow use of constant expressions in conditions (recommended)
no-control-regexno-control-regexdisallow control characters in regular expressions (recommended)
☑️no-debuggerno-debuggerdisallow use of debugger (recommended)
🚫no-dupe-argsNot applicabledisallow duplicate arguments in functions (recommended)
🚫no-dupe-keysNot applicabledisallow duplicate keys when creating object literals (recommended)
no-duplicate-caseno-duplicate-casedisallow a duplicate case label. (recommended)
☑️no-emptyno-emptydisallow empty statements (recommended)
no-empty-character-classno-empty-character-classdisallow the use of empty character classes in regular expressions (recommended)
no-ex-assignno-ex-assigndisallow assigning to the exception in a catch block (recommended)
no-extra-boolean-castno-extra-boolean-castdisallow double-negation boolean casts in a boolean context (recommended)
no-extra-parensno-extra-parensdisallow unnecessary parentheses
no-extra-semino-extra-semidisallow unnecessary semicolons (recommended)
🚫no-func-assignNot applicabledisallow overwriting functions written as function declarations (recommended)
no-inner-declarationsno-inner-declarationsdisallow function or variable declarations in nested blocks (recommended)
no-invalid-regexpno-invalid-regexpdisallow invalid regular expression strings in the RegExp constructor (recommended)
no-irregular-whitespaceter-no-irregular-whitespacedisallow irregular whitespace (recommended)
🚫no-negated-in-lhsNot applicabledisallow negation of the left operand of an in expression (recommended)
🚫no-obj-callsNot applicabledisallow the use of object properties of the global object (Math and JSON) as functions (recommended)
no-regex-spacesno-regex-spacesdisallow multiple spaces in a regular expression literal (recommended)
no-sparse-arrayster-no-sparse-arraysdisallow sparse arrays (recommended)
no-unexpected-multilineno-unexpected-multilineAvoid code that looks like two expressions but is actually one
🚫no-unreachableNot applicabledisallow unreachable statements after a return, throw, continue, or break statement (recommended)
☑️no-unsafe-finallyno-unsafe-finallydisallow control flow statements in finally blocks (recommended)
☑️use-isnanuse-isnandisallow comparisons with the value NaN (recommended)
valid-jsdocvalid-jsdocenforce valid JSDoc comments
valid-typeofvalid-typeofEnsure that the results of typeof are compared against a valid string (recommended)

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.

ESLintTSLintDescription
accessor-pairsaccessor-pairsEnforces getter/setter pairs in objects
array-callback-returnarray-callback-returnEnforce return statements in callbacks of array’s methods
block-scoped-varblock-scoped-vartreat var statements as if they were block scoped
☑️complexitycyclomatic-complexityspecify the maximum cyclomatic complexity allowed in a program
consistent-returnconsistent-returnrequire return statements to either always or never specify values
☑️curlycurlyspecify curly brace conventions for all control statements
☑️default-caseswitch-defaultrequire default case in switch statements
dot-locationdot-locationenforces consistent newlines before or after dots
dot-notationdot-notationencourages use of dot notation whenever possible
☑️eqeqeqtriple-equalsrequire the use of === and !==
☑️guard-for-inforinmake sure for-in loops have an if statement
☑️no-alertbandisallow the use of alert, confirm, and prompt
can be achieved using the "ban": [true, ["alert"]] tslint rule
☑️no-callerno-argdisallow use of arguments.caller or arguments.callee
no-case-declarationsno-case-declarationsdisallow lexical declarations in case clauses
no-div-regexno-div-regexdisallow division operators explicitly at beginning of regular expression
no-else-returnno-else-returndisallow else after a return in an if
☑️no-empty-functionno-emptydisallow use of empty functions
no-empty-patternno-empty-patterndisallow use of empty destructuring patterns
no-eq-nullno-eq-nulldisallow comparisons to null without a type-checking operator
☑️no-evalno-evaldisallow use of eval()
no-extend-nativeno-extend-nativedisallow adding to native types
no-extra-bindno-extra-binddisallow unnecessary function binding
no-extra-labelno-extra-labeldisallow unnecessary labels
☑️no-fallthroughno-switch-case-fall-throughdisallow fallthrough of case statements (recommended)
no-floating-decimalno-floating-decimaldisallow the use of leading or trailing decimal points in numeric literals
no-implicit-coercionno-implicit-coerciondisallow the type conversions with shorter notations
no-implicit-globalsno-implicit-globalsdisallow var and named functions in global scope
no-implied-evalno-implied-evaldisallow use of eval()-like methods
☑️no-invalid-thisno-invalid-thisdisallow this keywords outside of classes or class-like objects
no-iteratorno-iteratordisallow Usage of __iterator__ property
☑️no-labelslabel-positiondisallow use of labeled statements
no-lone-blocksno-lone-blocksdisallow unnecessary nested blocks
no-loop-funcno-loop-funcdisallow creation of functions within loops
☑️no-magic-numbersno-magic-numbersdisallow the use of magic numbers
no-multi-spacesno-multi-spacesdisallow use of multiple spaces
no-multi-strno-multi-strdisallow use of multiline strings
🚫no-native-reassignNot applicabledisallow reassignments of native objects
☑️no-newno-unused-expressiondisallow use of the new operator when not part of an assignment or comparison
no-new-funcno-new-funcdisallow use of new operator for Function object
☑️no-new-wrappersno-constructdisallows creating new instances of String,Number, and Boolean
🚫no-octalNot applicabledisallow use of octal literals (recommended)
no-octal-escapeno-octal-escapedisallow use of octal escape sequences in string literals, such as var foo = "Copyright \251";
no-param-reassignno-param-reassigndisallow reassignment of function parameters
no-prototer-no-protodisallow the use of __proto__ property
☑️no-redeclareno-duplicate-variabledisallow declaring the same variable more than once (http://eslint.org/docs/rules/recommended)
no-return-assignno-return-assigndisallow use of assignment in return statement
no-script-urlter-no-script-urldisallow use of javascript: urls.
no-self-assignno-self-assigndisallow assignments where both sides are exactly the same
no-self-compareter-no-self-comparedisallow comparisons where both sides are exactly the same
no-sequencesno-sequencesdisallow use of the comma operator
☑️no-throw-literalno-string-throwrestrict what can be thrown as an exception
no-unmodified-loop-conditionno-unmodified-loop-conditiondisallow unmodified conditions of loops
☑️no-unused-expressionsno-unused-expressiondisallow Usage of expressions in statement position
no-unused-labelsno-unused-labelsdisallow unused labels
no-useless-callno-useless-calldisallow unnecessary .call() and .apply()
no-useless-concatno-useless-concatdisallow unnecessary concatenation of literals or template literals
no-useless-escapeno-useless-escapedisallow unnecessary usage of escape character
no-voidno-voiddisallow use of the void operator
no-warning-commentsno-warning-commentsdisallow Usage of configurable warning terms in comments e.g. TODO or FIXME
no-withno-withdisallow use of the with statement
☑️radixradixrequire use of the second argument for parseInt()
vars-on-topvars-on-toprequire declaration of all vars at the top of their containing scope
wrap-iifewrap-iiferequire immediate function invocation to be wrapped in parentheses
☑️yodabinary-expression-operand-orderdisallow Yoda conditions

Strict Mode

These rules relate to using strict mode.

ESLintTSLintDescription
🚫strictNot applicablerequire effective use of strict mode directives

Variables

These rules have to do with variable declarations.

ESLintTSLintDescription
init-declarationsinit-declarationsenforce or disallow variable initializations at definition
no-catch-shadowno-catch-shadowdisallow the catch clause parameter name being the same as a variable in the outer scope
🚫no-delete-varNot applicabledisallow deletion of variables (recommended)
no-label-varno-label-vardisallow labels that share a name with a variable
☑️no-shadowno-shadowed-variabledisallow declaration of variables already declared in the outer scope
no-shadow-restricted-namesno-shadow-restricted-namesdisallow shadowing of names such as arguments
🚫no-undefNot applicabledisallow use of undeclared variables unless mentioned in a /*global */ block (recommended)
no-undef-initno-undef-initdisallow use of undefined when initializing variables
no-undefinedno-undefineddisallow use of undefined variable
☑️no-unused-varsno-unused-variabledisallow unused variables (recommended).
☑️no-use-before-defineno-use-before-declaredisallow use of variables before they are defined

Node.js and CommonJS

These rules are specific to JavaScript running on Node.js or using CommonJS in the browser.

ESLintTSLintDescription
callback-returncallback-returnenforce return after a callback
global-requireglobal-requireenforce require() on top-level module scope
handle-callback-errhandle-callback-errenforce error handling in callbacks
no-mixed-requiresno-mixed-requiresdisallow mixing regular variable and require declarations
no-new-requireno-new-requiredisallow use of new operator with the require function
no-path-concatno-path-concatdisallow string concatenation with __dirname and __filename
no-process-envno-process-envdisallow use of process.env
no-process-exitno-process-exitdisallow process.exit()
no-restricted-modulesno-restricted-modulesrestrict Usage of specified node modules
no-syncno-syncdisallow use of synchronous methods

Stylistic Issues

These rules are purely matters of style and are quite subjective.

ESLintTSLintDescription
array-bracket-spacingarray-bracket-spacingenforce consistent spacing inside array brackets
block-spacingblock-spacingdisallow or enforce spaces inside of single line blocks
brace-stylebrace-styleenforce one true brace style
☑️camelcasevariable-namerequire camel case names
comma-spacingcomma-spacingenforce spacing before and after comma
comma-stylecomma-styleenforce one true comma style
computed-property-spacingter-computed-property-spacingrequire or disallow padding inside computed properties
consistent-thisconsistent-thisenforce consistent naming when capturing the current execution context
☑️eol-lasteoflineenforce newline at the end of file, with no multiple empty lines
func-call-spacingter-func-call-spacingrequire or disallow spacing between function identifiers and their invocations
func-namesfunc-namesrequire function expressions to have a name
func-stylefunc-styleenforce use of function declarations or expressions
id-blacklistid-blacklistdisallow certain identifiers to prevent them being used
id-lengthid-lengththis option enforces minimum and maximum identifier lengths (variable names, property names etc.)
id-matchid-matchrequire identifiers to match the provided regular expression
indentter-indentenforce consistent indentation
jsx-quotesjsx-quotesspecify whether double or single quotes should be used in JSX attributes
key-spacingkey-spacingenforce spacing between keys and values in object literal properties
Tslint's whitespace can partially be used
keyword-spacingkeyword-spacingenforce spacing before and after keywords
Tslint's whitespace can partially be used
☑️linebreak-stylelinebreak-styledisallow mixed 'LF' and 'CRLF' as linebreaks
lines-around-commentlines-around-commentenforce empty lines around comments
max-depthmax-depthspecify the maximum depth that blocks can be nested
max-lenter-max-lenenforce a maximum line length
☑️max-linesmax-file-line-countenforce a maximum number of lines per file
max-nested-callbacksmax-nested-callbacksspecify the maximum depth callbacks can be nested
max-paramsmax-paramsspecify the number of parameters that can be used in the function declaration
max-statementsmax-statementsspecify the maximum number of statement allowed in a function
max-statements-per-linemax-statements-per-linespecify the maximum number of statements allowed per line
🚫new-capNot applicablerequire a capital letter for constructors
☑️new-parensnew-parensdisallow the omission of parentheses when invoking a constructor with no arguments
newline-after-varter-newline-after-varrequire or disallow an empty newline after variable declarations
newline-before-returnnewline-before-returnrequire newline before return statement
newline-per-chained-callnewline-per-chained-callenforce newline after each call when chaining the calls
no-array-constructorno-array-constructordisallow use of the Array constructor
☑️no-bitwiseno-bitwisedisallows bitwise operators
no-continueno-continuedisallow use of the continue statement
no-inline-commentsno-inline-commentsdisallow comments inline after code
no-lonely-ifno-lonely-ifdisallow if as the only statement in an else block
no-mixed-spaces-and-tabster-no-mixed-spaces-and-tabsdisallow mixed spaces and tabs for indentation (recommended)
☑️no-multiple-empty-linesno-consecutive-blank-linesdisallow multiple empty lines
no-negated-conditionno-negated-conditiondisallow negated conditions
no-nested-ternaryno-nested-ternarydisallow nested ternary expressions
no-new-objectno-new-objectdisallow the use of the Object constructor
no-restricted-syntaxno-restricted-syntaxdisallow use of certain syntax in code
no-spaced-funcno-spaced-funcdisallow space between function identifier and application
no-ternaryno-ternarydisallow the use of ternary operators
☑️no-trailing-spacesno-trailing-whitespacedisallow trailing whitespace at the end of lines
no-underscore-dangleno-underscore-dangledisallow dangling underscores in identifiers
no-unneeded-ternaryno-unneeded-ternarydisallow the use of ternary operators when a simpler alternative exists
no-whitespace-before-propertyno-whitespace-before-propertydisallow whitespace before properties
object-curly-spacingobject-curly-spacingrequire or disallow padding inside curly braces
☑️one-varone-variable-per-declarationrequire or disallow one variable declaration per function
one-var-declaration-per-lineone-var-declaration-per-linerequire or disallow a newline around variable declarations
operator-assignmentoperator-assignmentrequire assignment operator shorthand where possible or prohibit it entirely
operator-linebreakoperator-linebreakenforce operators to be placed before or after line breaks
padded-blockster-padded-blocksenforce padding within blocks
☑️quote-propsobject-literal-key-quotesrequire quotes around object literal property names
☑️quotesquotemarkspecify whether backticks, double or single quotes should be used
require-jsdocrequire-jsdocRequire JSDoc comment
☑️semisemicolonrequire or disallow use of semicolons instead of ASI
semi-spacingsemi-spacingenforce spacing before and after semicolons
sort-importssort-importsenforce sorting import declarations within module
sort-varssort-varssort variables within the same declaration block
space-before-blocksspace-before-blocksrequire or disallow a space before blocks
space-before-function-parenspace-before-function-parenrequire or disallow a space before function opening parenthesis
space-in-parensspace-in-parensrequire or disallow spaces inside parentheses
space-infix-opsspace-infix-opsrequire spaces around operators
Tslint's whitespace can partially be used
space-unary-opsspace-unary-opsrequire or disallow spaces before/after unary operators
☑️spaced-commentcomment-formatrequire or disallow a space immediately following the // or /* in a comment
wrap-regexwrap-regexrequire regex literals to be wrapped in parentheses
no-tabster-no-tabsdisallow all tabs

ECMAScript 6

These rules are only relevant to ES6 environments.

ESLintTSLintDescription
arrow-body-styleter-arrow-body-stylerequire braces in arrow function body
arrow-parenster-arrow-parensrequire parens in arrow function arguments
arrow-spacingter-arrow-spacingrequire space before/after arrow function's arrow
🚫constructor-superNot applicableverify calls of super() in constructors
generator-star-spacinggenerator-star-spacingenforce spacing around the * in generator functions
no-class-assignno-class-assigndisallow modifying variables of class declarations
no-confusing-arrowno-confusing-arrowdisallow arrow functions where they could be confused with comparisons
🚫no-const-assignNot applicabledisallow modifying variables that are declared using const
🚫no-dupe-class-membersNot applicabledisallow duplicate name in class members
no-duplicate-importsno-duplicate-importsdisallow duplicate module imports
no-new-symbolno-new-symboldisallow use of the new operator with the Symbol object
no-restricted-importsno-restricted-importsrestrict usage of specified modules when loaded by import declaration
🚫no-this-before-superNot applicabledisallow use of this/super before calling super() in constructors.
no-useless-constructorno-useless-constructordisallow unnecessary constructor
☑️no-varno-var-keywordrequire let or const instead of var
☑️object-shorthandobject-literal-shorthandrequire method and property shorthand syntax for object literals
prefer-arrow-callbackter-prefer-arrow-callbackrequire arrow functions as callbacks
☑️prefer-constprefer-constsuggest using const declaration for variables that are never modified after declared
prefer-destructuringprefer-destructuringrequire using destructuring when assigning to variables from arrays and objects
prefer-reflectprefer-reflectsuggest using Reflect methods where applicable
prefer-rest-paramsprefer-rest-paramssuggest using the rest parameters instead of arguments
prefer-spreadprefer-spreadsuggest using the spread operator instead of .apply().
prefer-templateprefer-templatesuggest using template literals instead of strings concatenation
require-yieldrequire-yielddisallow generator functions that do not have yield
template-curly-spacingtemplate-curly-spacingenforce spacing around embedded expressions of template strings
yield-star-spacingyield-star-spacingenforce spacing around the * in yield* expressions

Contributing

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.

LICENSE

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial