Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tslint-eslint-rules

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tslint-eslint-rules

Improve your TSLint with the missing ESLint Rules

  • 5.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
397K
increased by95.54%
Maintainers
2
Weekly downloads
 
Created
Source

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

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, extend this package, e.g:

{
  "extends": [
    "tslint-eslint-rules"
  ],
  "rules": {
    "no-constant-condition": true
  }
}

You can also extend other tslint config packages to combine this plugin with other community custom 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
:no_entry_sign:The rule is not applicable to Typescript.
:ballot_box_with_check:The rule is provided natively by TSLint.
:white_check_mark:The rule is available via tslint-eslint-rules.
:x:The rule is currently unavailable.

Possible Errors

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

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

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

Strict Mode

These rules relate to using strict mode.

:grey_question:ESLintTSLintDescription
:no_entry_sign:strictNot applicablerequire effective use of strict mode directives

Variables

These rules have to do with variable declarations.

:grey_question:ESLintTSLintDescription
:x:init-declarationsinit-declarationsenforce or disallow variable initializations at definition
:x:no-catch-shadowno-catch-shadowdisallow the catch clause parameter name being the same as a variable in the outer scope
:no_entry_sign:no-delete-varNot applicabledisallow deletion of variables (recommended)
:x:no-label-varno-label-vardisallow labels that share a name with a variable
:ballot_box_with_check:no-shadowno-shadowed-variabledisallow declaration of variables already declared in the outer scope
:x:no-shadow-restricted-namesno-shadow-restricted-namesdisallow shadowing of names such as arguments
:no_entry_sign:no-undefNot applicabledisallow use of undeclared variables unless mentioned in a /*global */ block (recommended)
:x:no-undef-initno-undef-initdisallow use of undefined when initializing variables
:x:no-undefinedno-undefineddisallow use of undefined variable
:ballot_box_with_check:no-unused-varsno-unused-variabledisallow unused variables (recommended).
:ballot_box_with_check: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.

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

Stylistic Issues

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

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

ECMAScript 6

These rules are only relevant to ES6 environments.

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

Keywords

FAQs

Package last updated on 15 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc