facebook pixelJavaScript Static Analysis Rules
BACK TO LIST

JavaScript rules

The Codiga Static Analysis engine checks JavaScript code and supports many popular libraries. If you are using React, NextJS, Vue or Angular: the engine will flag any issue in your codebase. Automate your code reviews with Codiga and merge with confidence.

      @typescript-eslint/ban-ts-comment

      Best practice
      High

      Detect any '@ts-<directive>' comment as it can reduce the effectiveness of TypeScript overall.

      Learn more

      @typescript-eslint/ban-types

      Best practice
      High

      Bans specific types and can suggest alternatives (such as String).

      @typescript-eslint/explicit-function-return-type

      Best practice
      High

      Ensure that the values returned from functions are of the expected type

      @typescript-eslint/explicit-member-accessibility

      Best practice
      Medium

      Make code more readable and explicit about who can use which properties

      @typescript-eslint/explicit-module-boundary-types

      Safety
      High

      Ensure that the values returned from a module are of the expected type

      @typescript-eslint/naming-convention

      Code style
      High

      Enforces naming conventions for everything across a codebase, in the settings verify if the naming-convention is camelCase, snake_case, etc.

      @typescript-eslint/no-empty-function

      Best practice
      High

      Detect any empty methods, as in methods that do not have any logic

      @typescript-eslint/no-explicit-any

      Safety
      Critical

      Detect any explicit "any" type, it should be replaced by another specific valid type (e.g string, number, boolean)

      @typescript-eslint/no-non-null-assertion

      Best practice
      Medium

      Detect all non-null assertions as they cancel the benefits of strict null-checking mode

      @typescript-eslint/no-shadow

      Error prone
      Medium

      Disallow variable declarations from shadowing variables declared in the outer scope

      @typescript-eslint/no-unsafe-assignment

      Safety
      High

      Disallows assigning any to variables and properties as it creates a potential safety hole, and source of bugs in your codebase.

      @typescript-eslint/no-unsafe-call

      Safety
      High

      Disallows calling an any type value as it creates a potential safety hole, and source of bugs in your codebase.

      @typescript-eslint/no-unsafe-member-access

      Safety
      High

      Disallows member access on any typed variables as it creates a potential safety hole, and source of bugs in your codebase.

      @typescript-eslint/no-unsafe-return

      Safety
      Critical

      Disallows returning any from a function

      @typescript-eslint/no-unused-expressions

      Best practice
      High

      Disallow unused expressions. An unused expression which has no effect on the state of the program indicates a logic error.

      @typescript-eslint/no-unused-vars

      Best practice
      High

      Disallow unused variables. Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring

      @typescript-eslint/no-use-before-define

      Safety
      Critical

      Disallow the use of variables before they are defined.

      @typescript-eslint/no-var-requires

      Best practice
      High

      Disallows the use of require statements except in import statements

      @typescript-eslint/restrict-template-expressions

      Best practice
      Medium

      Enforce template literal expressions to be of string type

      @typescript-eslint/triple-slash-reference

      Code style
      Minor

      Ban use of /// <reference path="" />, /// <reference types="" />, or /// <reference lib="" /> directives.

      @typescript-eslint/unbound-method

      Safety
      High

      Warns when a method is used outside of a method call.

      babel/new-cap

      Code style
      Minor

      Ignores capitalized decorators

      compat/compat

      Best practice
      High

      This rule enables linting your code for browser compatibility.

      constructor-super

      Best practice
      High

      Constructors of derived classes must call super()

      cypress/no-unnecessary-waiting

      Best practice
      Minor

      Unnecessary wait for cy.request()

      eslint-comments/no-unused-disable

      Best practice
      High

      Disallow unused eslint-disable comments. Make sure all your rules are defined and are used correctly.

      fecs-key-spacing

      Code style
      Medium

      This rule enforces spacing around the colon in object literal properties.

      flowtype/no-weak-types

      Safety
      High

      Warns against weak type annotations any, Object and Function.

      for-direction

      Error prone
      High

      Enforce "for" loop update clause moving the counter in the right direction.

      getter-return

      Error prone
      High

      Enforces that a return statement is present in property getters

      import/extensions

      Best practice
      Minor

      Ensure consistent use of file extension within the import path

      import/no-commonjs

      Best practice
      Minor

      Reports require([string]) function calls. Will not report if >1 argument, or single argument is not a literal string.

      import/no-dynamic-require

      Best practice
      Minor

      Checks every call to require() that uses expressions for the module name argument.

      import/no-unresolved

      Best practice
      Minor

      Ensures an imported module can be resolved to a module on the local filesystem, as defined by standard Node require.resolve behavior.

      import/no-unused-modules

      Best practice
      Minor

      Reports modules without any exports, individual exports not being statically imported or required from other modules in the same project or dynamic imports are supported if argument is a literal string

      import/no-webpack-loader-syntax

      Best practice
      Minor

      Forbid Webpack loader syntax in imports.

      import/order

      Best practice
      Minor

      Enforce a convention in the order of require() / import statements.

      import/unambiguous

      Security
      High

      Warn if a module could be mistakenly parsed as a script by a consumer leveraging Unambiguous JavaScript Grammar to determine correct parsing goal.

      jest/expect-expect

      Best practice
      Medium

      Jest: Ensure that there is at least one expect call made in a test.

      jest/no-conditional-expect

      Best practice
      Medium

      Jest: This rule prevents the use of expect in conditional blocks, such as ifs & catchs.

      jest/no-identical-title

      Unknown
      Medium

      Jest: Disallow identical testing titles

      jsx-a11y/anchor-is-valid

      Best practice
      Minor

      Make sure the HTML <a> has a valid href value and can be used to navigate in a browser, make sure all attributes are specified correctly.

      jsx-a11y/click-events-have-key-events

      Best practice
      High

      Enforce onClick is accompanied by at least one of the following: onKeyUp, onKeyDown, onKeyPress

      jsx-a11y/iframe-has-title

      Best practice
      Medium

      <iframe> elements must have a unique title property to indicate its content to the user.

      jsx-a11y/label-has-associated-control

      Best practice
      Medium

      Accessibility: Enforce that a label tag has a text label and an associated control.

      jsx-a11y/label-has-for

      Best practice
      Minor

      Accessibility: Enforce that a label tag has a text label and an associated control.

      jsx-a11y/media-has-caption

      Best practice
      Medium

      Accessibility: Provide a caption for your media. Providing captions for media is essential for deaf users to follow along.

      jsx-a11y/mouse-events-have-key-events

      Best practice
      Medium

      Accessibility: enforce onmouseover/onmouseout are accompanied by onfocus/onblur.

      jsx-a11y/no-noninteractive-element-interactions

      Best practice
      Medium

      Accessibility: disallow interactions in no interactive elements.

      jsx-a11y/no-noninteractive-tabindex

      Best practice
      Medium

      Tab key navigation should be limited to elements on the page that can be interacted with.

      jsx-a11y/no-static-element-interactions

      Best practice
      High

      Disallow interactions in static elements. Static HTML elements do not have semantic meaning.

      key-spacing

      Code style
      High

      Enforce consistent spacing between keys and values in object literal properties

      max-statements

      Best practice
      High

      Check max number of statements for a function

      mocha/no-hooks-for-single-case

      Best practice
      Minor

      Disallow hooks for a single test or test suite

      mocha/no-setup-in-describe

      Best practice
      Minor

      Disallow setup in describe blocks

      mocha/prefer-arrow-callback

      Unknown
      High

      Definition for rule 'mocha/prefer-arrow-callback' was not found.

      no-class-assign

      Code style
      High

      RegistrationForm' is a class.

      no-compare-neg-zero

      Error prone
      High

      Detect the use of operator (e.g <=, <, ===, etc) to compare against -0.

      no-const-assign

      Code style
      High

      Disallows assigning values to const as they're immutable.

      no-control-regex

      Error prone
      High

      Control characters are special, invisible characters in the ASCII range 0-31. These characters are rarely used in JavaScript strings so a regular expression containing these characters is most likely a mistake.

      no-dupe-class-members

      Code style
      High

      Disallow duplicate name in class members

      no-dupe-else-if

      Error prone
      High

      Disallow duplicate conditions in if-else-if chains

      no-dupe-keys

      Error prone
      High

      Disallow duplicate keys in object literals

      no-duplicate-case

      Error prone
      High

      If a switch statement has duplicate test expressions in case clauses, it is likely that a programmer copied a case clause but forgot to change the test expression.

      no-empty-pattern

      Best practice
      High

      Disallow empty destructuring patterns

      no-func-assign

      Error prone
      High

      Disallow reassigning function declarations

      no-global-assign

      Best practice
      High

      Disallow assignment to native objects or read-only global variables

      no-inner-declarations

      Error prone
      High

      Disallow variable or function declarations in nested blocks

      no-irregular-whitespace

      Error prone
      High

      Irregular whitespace not allowed.

      no-misleading-character-class

      Error prone
      High

      Disallow characters which are made with multiple code points in character class syntax

      no-prototype-builtins

      Error prone
      High

      Disallow use of Object.prototypes builtins directly

      no-redeclare

      Best practice
      High

      Disallow variable redeclaration

      no-regex-spaces

      Error prone
      High

      Disallow multiple spaces in regular expression literals

      no-self-assign

      Best practice
      High

      Detects self assignments as they have no effect, so probably those are an error due to incomplete refactoring.

      no-setter-return

      Error prone
      High

      Setter cannot return a value.

      no-shadow-restricted-names

      Code style
      High

      Disallow shadowing of restricted names

      no-unexpected-multiline

      Error prone
      High

      Disallow confusing multiline expressions

      no-unreachable

      Error prone
      High

      Disallow unreachable code after return, throw, continue, and break statements

      no-unsafe-finally

      Error prone
      High

      Disallow control flow statements in finally blocks

      no-unsafe-negation

      Error prone
      High

      Disallow negating the left operand of relational operators

      no-unused-labels

      Best practice
      High

      Disallow unused labels. Labels that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring.

      no-unused-vars

      Code style
      High

      Disallow unused variables. Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring

      no-useless-catch

      Best practice
      High

      Disallow unnecessary catch clauses

      no-useless-escape

      Best practice
      High

      Reports unnecessary escapes, as escaping non-special characters in strings, template literals, and regular expressions doesn't have any effect.

      node/no-deprecated-api

      Best practice
      High

      Disallow deprecated APIs

      node/no-missing-require

      Error prone
      High

      Disallow require() expressions which import non-existence modules

      promise/catch-or-return

      Safety
      High

      Ensure that each time a then() is applied to a promise, a catch() is applied as well. Exceptions are made if you are returning that promise.

      promise/prefer-await-to-then

      Performance
      High

      Use async/await style for managing concurrency instead of .then()

      react-hooks/rules-of-hooks

      Best practice
      High

      React: Detects when rules of hooks are not being followed

      react-internal/no-production-logging

      Unknown
      High

      React: Disallow internal logging when running in production

      react-native/no-color-literals

      Best practice
      High

      React: Disallow color literals in styles

      react-native/no-inline-styles

      Unknown
      High

      React: Styles should be defined in css blocks and not as inline of the web component or element

      react/destructuring-assignment

      Best practice
      High

      React: Enforce consistent usage of destructuring assignment of props, state, and context

      react/display-name

      Best practice
      High

      Prevent missing displayName in a React component definition

      react/forbid-prop-types

      Best practice
      High

      React: By default this rule prevents vague prop types with more specific alternatives available (any, array, object), but any prop type can be disabled if desired.

      react/jsx-key

      Error prone
      High

      React: Warn if an element that likely requires a key prop--namely, one present in an array literal or an arrow function expression.

      react/jsx-no-duplicate-props

      Error prone
      High

      React: No duplicate props allowed

      react/jsx-no-target-blank

      Best practice
      High

      React: This rules requires that you accompany target='\_blank' attributes with rel='noreferrer'.

      react/jsx-no-undef

      Error prone
      High

      React: Detects potential ReferenceErrors resulting from misspellings or missing components.

      react/no-array-index-key

      Unknown
      High

      React: Prevent usage of Array index in keys

      react/no-children-prop

      Best practice
      High

      React: Prevent passing of children as props. Children should always be actual children, not passed in as a prop.

      react/no-danger

      Unknown
      High

      React: Prevent usage of dangerous JSX properties

      react/no-deprecated

      Best practice
      High

      React: Prevent usage of deprecated methods

      react/no-direct-mutation-state

      Error prone
      High

      React: NEVER mutate this.state directly, as calling setState() afterwards may replace the mutation you made. Treat this.state as if it were immutable.

      react/no-find-dom-node

      Best practice
      High

      React: Prevent usage of findDOMNode. Facebook will eventually deprecate findDOMNode as it blocks certain improvements in React in the future.

      react/no-render-return-value

      Best practice
      High

      React: Prevent usage of the return value of ReactDOM.render

      react/no-string-refs

      Best practice
      High

      React: Prevent using string references

      react/no-unescaped-entities

      Error prone
      High

      React: Prevent invalid characters from appearing in markup

      react/no-unknown-property

      Error prone
      High

      React: Prevent usage of unknown DOM property

      react/prop-types

      Best practice
      High

      React: Prevent missing props validation in a React component definition

      react/require-default-props

      Best practice
      High

      React: Enforce a defaultProps definition for every prop that is not a required prop

      react/require-render-return

      Best practice
      High

      React: Enforce ES5 or ES6 class for returning value in render function

      react/sort-comp

      Best practice
      High

      React: Enforce component methods order

      react/style-prop-object

      Best practice
      High

      React: Enforce style prop value being an object

      require-yield

      Code style
      High

      Disallow generator functions that do not have yield

      security/detect-non-literal-regexp

      Security
      High

      Detects RegExp(variable), which might allow an attacker to DOS your server with a long-running regular expression.

      sonarjs/no-duplicate-string

      Best practice
      Medium

      Find duplicate string

      sonarjs/no-identical-functions

      Best practice
      High

      When two functions have the same implementation, either it was a mistake - something else was intended - or the duplication was intentional, but may be confusing to maintainers.

      standard/no-callback-literal

      Best practice
      High

      When invoking a callback function which uses the Node.js error-first callback pattern, all of your errors should either use the Error class or a subclass of it. It is also acceptable to use undefined or null if there is no error.

      unicorn/consistent-destructuring

      Best practice
      High

      Use destructured variables over properties

      unicorn/prefer-exponentiation-operator

      Best practice
      High

      Disallow the use of Math.pow in favor of the ** operator

      unicorn/prevent-abbreviations

      Best practice
      Minor

      Using complete words results in more readable code. Not everyone knows all your abbreviations.

      valid-typeof

      Error prone
      High

      Enforce comparing typeof expressions against valid strings

      vue/no-reserved-keys

      Best practice
      High

      Vue: Disallow overwriting reserved keys in Vue

      vue/no-side-effects-in-computed-properties

      Best practice
      High

      Vue: Disallow side effects in computed properties

      xo/throw-new-error

      Best practice
      High

      Use the new keyword when throwing an error