Home Products Integration with ESLint JavaScript Linter

Integration with ESLint JavaScript Linter

Author

Date

Category

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.

GET STARTED

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Subscribe to our newsletter

To be updated with all the latest news, offers and special announcements.

Recent posts

How does code quality fit into your CI/CD pipeline?

Continuous Integration and Continuous Deployment (CI/CD) are key for organizations wanting to deliver software at scale. CI/CD allows developers to automate...

How Stim uses Codacy to achieve high-quality code

We spoke with Tobias Sjรถsten, Head of Software Engineering at Stim, about how Codacy helps them guarantee code quality and standardization...

6 things developers should do to ship more secure code

Writing better, more secure source code is fundamental to prevent potential exploits and attacks that could undermine your software applications. However,...

Best practices for security code reviews

In today's interconnected world, where data breaches and cyber threats are increasingly common, one of your top priorities should be to...

April Product Update ๐Ÿš€

Hi there ๐Ÿ‘‹ It's been a whirlwind month, and we have big news to share: