facebook pixelCodiga Analysis JavaScript Rules, category best practice
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
Error

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

Learn more

@typescript-eslint/ban-types

Best practice
Error

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

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

Best practice
Error

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

@typescript-eslint/explicit-member-accessibility

Best practice
Warning

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

@typescript-eslint/no-empty-function

Best practice
Error

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

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

Best practice
Warning

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

@typescript-eslint/no-unused-expressions

Best practice
Error

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
Error

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-var-requires

Best practice
Error

Disallows the use of require statements except in import statements

@typescript-eslint/restrict-template-expressions

Best practice
Warning

Enforce template literal expressions to be of string type

compat/compat

Best practice
Error

This rule enables linting your code for browser compatibility.

constructor-super

Best practice
Error

Constructors of derived classes must call super()

cypress/no-unnecessary-waiting

Best practice
Informational

Unnecessary wait for cy.request()

eslint-comments/no-unused-disable

Best practice
Error

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

import/extensions

Best practice
Informational

Ensure consistent use of file extension within the import path

import/no-commonjs

Best practice
Informational

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
Informational

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

import/no-unresolved

Best practice
Informational

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
Informational

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
Informational

Forbid Webpack loader syntax in imports.

import/order

Best practice
Informational

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

jest/expect-expect

Best practice
Warning

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

jest/no-conditional-expect

Best practice
Warning

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

jsx-a11y/anchor-is-valid

Best practice
Informational

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
Error

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

jsx-a11y/iframe-has-title

Best practice
Warning

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

jsx-a11y/label-has-associated-control

Best practice
Warning

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

jsx-a11y/label-has-for

Best practice
Informational

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

jsx-a11y/media-has-caption

Best practice
Warning

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
Warning

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

jsx-a11y/no-noninteractive-element-interactions

Best practice
Warning

Accessibility: disallow interactions in no interactive elements.

jsx-a11y/no-noninteractive-tabindex

Best practice
Warning

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

jsx-a11y/no-static-element-interactions

Best practice
Error

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

max-statements

Best practice
Error

Check max number of statements for a function

mocha/no-hooks-for-single-case

Best practice
Informational

Disallow hooks for a single test or test suite

mocha/no-setup-in-describe

Best practice
Informational

Disallow setup in describe blocks

no-empty-pattern

Best practice
Error

Disallow empty destructuring patterns

no-global-assign

Best practice
Error

Disallow assignment to native objects or read-only global variables

no-redeclare

Best practice
Error

Disallow variable redeclaration

no-self-assign

Best practice
Error

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

no-unused-labels

Best practice
Error

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

no-useless-catch

Best practice
Error

Disallow unnecessary catch clauses

no-useless-escape

Best practice
Error

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
Error

Disallow deprecated APIs

react-hooks/rules-of-hooks

Best practice
Error

React: Detects when rules of hooks are not being followed

react-native/no-color-literals

Best practice
Error

React: Disallow color literals in styles

react/destructuring-assignment

Best practice
Error

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

react/display-name

Best practice
Error

Prevent missing displayName in a React component definition

react/forbid-prop-types

Best practice
Error

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-no-target-blank

Best practice
Error

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

react/no-children-prop

Best practice
Error

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

react/no-deprecated

Best practice
Error

React: Prevent usage of deprecated methods

react/no-find-dom-node

Best practice
Error

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
Error

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

react/no-string-refs

Best practice
Error

React: Prevent using string references

react/prop-types

Best practice
Error

React: Prevent missing props validation in a React component definition

react/require-default-props

Best practice
Error

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

react/require-render-return

Best practice
Error

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

react/sort-comp

Best practice
Error

React: Enforce component methods order

react/style-prop-object

Best practice
Error

React: Enforce style prop value being an object

sonarjs/no-duplicate-string

Best practice
Warning

Find duplicate string

sonarjs/no-identical-functions

Best practice
Error

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
Error

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
Error

Use destructured variables over properties

unicorn/prefer-exponentiation-operator

Best practice
Error

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

unicorn/prevent-abbreviations

Best practice
Informational

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

vue/no-reserved-keys

Best practice
Error

Vue: Disallow overwriting reserved keys in Vue

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

Best practice
Error

Vue: Disallow side effects in computed properties

xo/throw-new-error

Best practice
Error

Use the new keyword when throwing an error