This past year weโve seen an incredible growth coming from ESLint, a linter on steroids for ECMAScript, JSX and JavaScript code. It quickly became the go-to JavaScript linter for the programming language’s community. The work of Nicholas and the numerous contributors is really impressive.
The original philosophy behind the tool is something that speaks to us greatly as it is completely pluggable. ESLint makes it very easy to write your own plugins and share them with the community. You can find several examples on NPM.
Today Iโm happy to announce that ESLint rules are now supported on Codacy. Here are the rules taken from the rules list that you can now enforce on Codacy. Enable them on your projects and share your feedback with us!
ESLint Rules
Possible Errors
The following rules point out areas where you might have made mistakes.
- comma-dangleโโโdisallow or enforce trailing commas (recommended)
- no-cond-assignโโโdisallow assignment in conditional expressions (recommended)
- no-consoleโโโdisallow use of console in the node environment (recommended)
- no-constant-conditionโโโdisallow use of constant expressions in conditions (recommended)
- no-control-regexโโโdisallow control characters in regular expressions (recommended)
- no-debuggerโโโdisallow use of debugger (recommended)
- no-dupe-argsโโโdisallow duplicate arguments in functions (recommended)
- no-dupe-keysโโโdisallow duplicate keys when creating object literals (recommended)
- no-duplicate-caseโโโdisallow a duplicate case label. (recommended)
- no-empty-character-classโโโdisallow the use of empty character classes in regular expressions (recommended)
- no-emptyโโโdisallow empty statements (recommended)
- no-ex-assignโโโdisallow assigning to the exception in a catch block (recommended)
- no-extra-boolean-castโโโdisallow double-negation boolean casts in a boolean context (recommended)
- no-extra-parensโโโdisallow unnecessary parentheses
- no-extra-semiโโโdisallow unnecessary semicolons (recommended) (fixable)
- no-func-assignโโโdisallow overwriting functions written as function declarations (recommended)
- no-inner-declarationsโโโdisallow function or variable declarations in nested blocks (recommended)
- no-invalid-regexpโโโdisallow invalid regular expression strings in the RegExp constructor (recommended)
- no-irregular-whitespaceโโโdisallow irregular whitespace outside of strings and comments (recommended)
- no-negated-in-lhsโโโdisallow negation of the left operand of an in expression (recommended)
- no-obj-callsโโโdisallow the use of object properties of the global object (Math and JSON) as functions (recommended)
- no-regex-spacesโโโdisallow multiple spaces in a regular expression literal (recommended)
- no-sparse-arraysโโโdisallow sparse arrays (recommended)
- no-unexpected-multilineโโโAvoid code that looks like two expressions but is actually one
- no-unreachableโโโdisallow unreachable statements after a return, throw, continue, or break statement (recommended)
- use-isnanโโโdisallow comparisons with the value NaN (recommended)
- valid-jsdocโโโEnsure JSDoc comments are valid
- valid-typeofโโโEnsure 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.
- accessor-pairsโโโEnforces getter/setter pairs in objects
- block-scoped-varโโโtreat var statements as if they were block scoped
- complexityโโโspecify the maximum cyclomatic complexity allowed in a program
- consistent-returnโโโrequire return statements to either always or never specify values
- curlyโโโspecify curly brace conventions for all control statements
- default-caseโโโrequire default case in switch statements
- dot-locationโโโenforces consistent newlines before or after dots
- dot-notationโโโencourages use of dot notation whenever possible
- eqeqeqโโโrequire the use of === andย !== (fixable)
- guard-for-inโโโmake sure for-in loops have an if statement
- no-alertโโโdisallow the use of alert, confirm, and prompt
- no-callerโโโdisallow use of arguments.caller or arguments.callee
- no-case-declarationsโโโdisallow lexical declarations in case clauses
- no-div-regexโโโdisallow division operators explicitly at beginning of regular expression
- no-else-returnโโโdisallow else after a return in an if
- no-empty-labelโโโdisallow use of labels for anything other than loops and switches
- no-empty-patternโโโdisallow use of empty destructuring patterns
- no-eq-nullโโโdisallow comparisons to null without a type-checking operator
- no-evalโโโdisallow use of eval()
- no-extend-nativeโโโdisallow adding to native types
- no-extra-bindโโโdisallow unnecessary function binding
- no-fallthroughโโโdisallow fallthrough of case statements (recommended)
- no-floating-decimalโโโdisallow the use of leading or trailing decimal points in numeric literals
- no-implicit-coercionโโโdisallow the type conversions with shorter notations
- no-implied-evalโโโdisallow use of eval()-like methods
- no-invalid-thisโโโdisallow this keywords outside of classes or class-like objects
- no-iteratorโโโdisallow usage of __iterator__ property
- no-labelsโโโdisallow use of labeled statements
- no-lone-blocksโโโdisallow unnecessary nested blocks
- no-loop-funcโโโdisallow creation of functions within loops
- no-magic-numbersโโโdisallow the use of magic numbers
- no-multi-spacesโโโdisallow use of multiple spaces (fixable)
- no-multi-strโโโdisallow use of multiline strings
- no-native-reassignโโโdisallow reassignments of native objects
- no-new-funcโโโdisallow use of new operator for Function object
- no-new-wrappersโโโdisallows creating new instances of String,Number, and Boolean
- no-newโโโdisallow use of the new operator when not part of an assignment or comparison
- no-octal-escapeโโโdisallow use of octal escape sequences in string literals, such as var foo = โCopyright 251โ;
- no-octalโโโdisallow use of octal literals (recommended)
- no-param-reassignโโโdisallow reassignment of function parameters
- no-process-envโโโdisallow use of process.env
- no-protoโโโdisallow usage of __proto__ property
- no-redeclareโโโdisallow declaring the same variable more than once (recommended)
- no-return-assignโโโdisallow use of assignment in return statement
- no-script-urlโโโdisallow use of javascript: urls.
- no-self-compareโโโdisallow comparisons where both sides are exactly the same
- no-sequencesโโโdisallow use of the comma operator
- no-throw-literalโโโrestrict what can be thrown as an exception
- no-unused-expressionsโโโdisallow usage of expressions in statement position
- no-useless-callโโโdisallow unnecessaryย .call() andย .apply()
- no-useless-concatโโโdisallow unnecessary concatenation of literals or template literals
- no-voidโโโdisallow use of the void operator
- no-warning-commentsโโโdisallow usage of configurable warning terms in commentsโโโe.g. TODO or FIXME
- no-withโโโdisallow use of the with statement
- radixโโโrequire use of the second argument for parseInt()
- vars-on-topโโโrequire declaration of all vars at the top of their containing scope
- wrap-iifeโโโrequire immediate function invocation to be wrapped in parentheses
- yodaโโโrequire or disallow Yoda conditions
Strict Mode
These rules relate to using strict mode.
- strictโโโcontrols location of Use Strict Directives
Variables
These rules have to do with variable declarations.
- init-declarationsโโโenforce or disallow variable initializations at definition
- no-catch-shadowโโโdisallow the catch clause parameter name being the same as a variable in the outer scope
- no-delete-varโโโdisallow deletion of variables (recommended)
- no-label-varโโโdisallow labels that share a name with a variable
- no-shadow-restricted-namesโโโdisallow shadowing of names such as arguments
- no-shadowโโโdisallow declaration of variables already declared in the outer scope
- no-undef-initโโโdisallow use of undefined when initializing variables
- no-undefโโโdisallow use of undeclared variables unless mentioned in a /*global */ block (recommended)
- no-undefinedโโโdisallow use of undefined variable
- no-unused-varsโโโdisallow declaration of variables that are not used in the code (recommended)
- no-use-before-defineโโโdisallow 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.
- callback-returnโโโenforce return after a callback
- global-requireโโโenforce require() on top-level module scope
- handle-callback-errโโโenforce error handling in callbacks
- no-mixed-requiresโโโdisallow mixing regular variable and require declarations
- no-new-requireโโโdisallow use of new operator with the require function
- no-path-concatโโโdisallow string concatenation with __dirname and __filename
- no-process-exitโโโdisallow process.exit()
- no-restricted-modulesโโโrestrict usage of specified node modules
- no-syncโโโdisallow use of synchronous methods
Stylistic Issues
These rules are purely matters of style and are quite subjective.
- array-bracket-spacingโโโenforce spacing inside array brackets (fixable)
- block-spacingโโโdisallow or enforce spaces inside of single line blocks (fixable)
- brace-styleโโโenforce one true brace style
- camelcaseโโโrequire camel case names
- comma-spacingโโโenforce spacing before and after comma (fixable)
- comma-styleโโโenforce one true comma style
- computed-property-spacingโโโrequire or disallow padding inside computed properties (fixable)
- consistent-thisโโโenforce consistent naming when capturing the current execution context
- eol-lastโโโenforce newline at the end of file, with no multiple empty lines (fixable)
- func-namesโโโrequire function expressions to have a name
- func-styleโโโenforce use of function declarations or expressions
- id-lengthโโโthis option enforces minimum and maximum identifier lengths (variable names, property names etc.)
- id-matchโโโrequire identifiers to match the provided regular expression
- indentโโโspecify tab or space width for your code (fixable)
- jsx-quotesโโโspecify whether double or single quotes should be used in JSX attributes
- key-spacingโโโenforce spacing between keys and values in object literal properties
- linebreak-styleโโโdisallow mixed โLFโ and โCRLFโ as linebreaks
- lines-around-commentโโโenforce empty lines around comments
- max-depthโโโspecify the maximum depth that blocks can be nested
- max-lenโโโspecify the maximum length of a line in your program
- max-nested-callbacksโโโspecify the maximum depth callbacks can be nested
- max-paramsโโโlimits the number of parameters that can be used in the function declaration.
- max-statementsโโโspecify the maximum number of statement allowed in a function
- new-capโโโrequire a capital letter for constructors
- new-parensโโโdisallow the omission of parentheses when invoking a constructor with no arguments
- newline-after-varโโโrequire or disallow an empty newline after variable declarations
- no-array-constructorโโโdisallow use of the Array constructor
- no-bitwiseโโโdisallow use of bitwise operators
- no-continueโโโdisallow use of the continue statement
- no-inline-commentsโโโdisallow comments inline after code
- no-lonely-ifโโโdisallow if as the only statement in an else block
- no-mixed-spaces-and-tabsโโโdisallow mixed spaces and tabs for indentation (recommended)
- no-multiple-empty-linesโโโdisallow multiple empty lines
- no-negated-conditionโโโdisallow negated conditions
- no-nested-ternaryโโโdisallow nested ternary expressions
- no-new-objectโโโdisallow the use of the Object constructor
- no-plusplusโโโdisallow use of unary operators, ++ and โ
- no-restricted-syntaxโโโdisallow use of certain syntax in code
- no-spaced-funcโโโdisallow space between function identifier and application (fixable)
- no-ternaryโโโdisallow the use of ternary operators
- no-trailing-spacesโโโdisallow trailing whitespace at the end of lines (fixable)
- no-underscore-dangleโโโdisallow dangling underscores in identifiers
- no-unneeded-ternaryโโโdisallow the use of ternary operators when a simpler alternative exists
- object-curly-spacingโโโrequire or disallow padding inside curly braces (fixable)
- one-varโโโrequire or disallow one variable declaration per function
- operator-assignmentโโโrequire assignment operator shorthand where possible or prohibit it entirely
- operator-linebreakโโโenforce operators to be placed before or after line breaks
- padded-blocksโโโenforce padding within blocks
- quote-propsโโโrequire quotes around object literal property names
- quotesโโโspecify whether backticks, double or single quotes should be used (fixable)
- require-jsdocโโโRequire JSDoc comment
- semi-spacingโโโenforce spacing before and after semicolons
- semiโโโrequire or disallow use of semicolons instead of ASI (fixable)
- sort-varsโโโsort variables within the same declaration block
- space-after-keywordsโโโrequire a space after certain keywords (fixable)
- space-before-blocksโโโrequire or disallow a space before blocks (fixable)
- space-before-function-parenโโโrequire or disallow a space before function opening parentheses (fixable)
- space-before-keywordsโโโrequire a space before certain keywords (fixable)
- space-in-parensโโโrequire or disallow spaces inside parentheses
- space-infix-opsโโโrequire spaces around operators (fixable)
- space-return-throw-caseโโโrequire a space after return, throw, and case (fixable)
- space-unary-opsโโโrequire or disallow spaces before/after unary operators (fixable)
- spaced-commentโโโrequire or disallow a space immediately following the // or /* in a comment
- wrap-regexโโโrequire regex literals to be wrapped in parentheses
ECMAScript 6
These rules are only relevant to ES6 environments.
- arrow-body-styleโโโrequire braces in arrow function body
- arrow-parensโโโrequire parentheses in arrow function arguments
- arrow-spacingโโโrequire space before/after arrow functionโs arrow (fixable)
- constructor-superโโโverify calls of super() in constructors
- generator-star-spacingโโโenforce spacing around the * in generator functions (fixable)
- no-arrow-conditionโโโdisallow arrow functions where a condition is expected
- no-class-assignโโโdisallow modifying variables of class declarations
- no-const-assignโโโdisallow modifying variables that are declared using const
- no-dupe-class-membersโโโdisallow duplicate name in class members
- no-this-before-superโโโdisallow use of this/super before calling super() in constructors.
- no-varโโโrequire let or const instead of var
- object-shorthandโโโrequire method and property shorthand syntax for object literals
- prefer-arrow-callbackโโโsuggest using arrow functions as callbacks
- prefer-constโโโsuggest using const declaration for variables that are never modified after declared
- prefer-reflectโโโsuggest using Reflect methods where applicable
- prefer-spreadโโโsuggest using the spread operator instead ofย .apply().
- prefer-templateโโโsuggest using template literals instead of strings concatenation
- require-yieldโโโdisallow generator functions that do not have yield
Edit: We just published an ebook: โThe Ultimate Guide to Code Reviewโ based on a survey of 680+ developers. Enjoy!
For more on ESLint from us check out our ESLint archive
About Codacy
Codacy is used by thousands of developers to analyze billions of lines of code every day!
Getting started is easy โ and free! Just use yourย ย GitHub, Bitbucket or Google account toย sign up.