Rules

DeepScan provides precise rules for JavaScript code quality.

Rules have been developed by finding best practices from various sources like CWE, FindBugs, PMD, open sources and papers. And DeepScan provides the rules by the following category:

  • Error: Code which might throw an exception at runtime or cause unintended execution
  • Code Quality: Code which should be more readable, reusable and refactorable

All rules are enabled by default.

Error

The following rules relate to code which might throw an exception at runtime or cause unintended execution:

ACCESS_INNER_FUNC_FROM_DEFAULT_PARAM

Inner functions should not be accessed at default parameter declaration

ACCESS_THIS_BEFORE_SUPER_CALL

this should be accessed after calling super in constructor of inherited class

ARRAY_INDEX_NEGATIVE

Negative index should not be used on arrays

ARROW_FUNC_RETURN_OBJECT_MISSING

Arrow function should use parentheses to return an object literal

ASSIGN_TO_PROPERTY_OF_PRIMITIVE

Assignment should not be made to property of primitive value

BAD_ARRAY_METHOD_ON_ARGUMENTS

Array methods should not be called on the arguments object itself

BAD_ASSIGN_IN_CONDITION

An equality operator should be used instead of an assignment operator in a conditional statement

BAD_ASSIGN_TO_CONST

Reassignment should not be made to a variable that is declared using const keyword

BAD_ASSIGN_TO_PROTO

The __proto__ property of an object should be assigned with a proper value.

BAD_BACK_REFERENCE_IN_REGEXP

Back reference in a regular expression should be used after the referred group

BAD_BITWISE_OPERATOR

Bitwise operators should not be used where logical operators are expected

BAD_CHAR_AT_COMPARISON

The result of String.prototype.charAt() should not be compared with a string of length 2 or more

BAD_COMPARISON_SEQUENCE

The comparison operator should not be applied 2 or more times in a row

BAD_COMPARISON_WITH_FLOAT

The result of integer-returning built-in API should not be compared with a float number

BAD_CONDITIONAL_OPERATOR

The conditional operator should be used in correct order

BAD_ESCAPE_AT_REGEXP_CONSTRUCTOR

Character escapes should be used properly when constructing a regular expression from string literal

BAD_EVENT_LISTENER_CALL

The handler function itself should be used at addEventListener() and removeEventListener()

BAD_FINALLY_CONTROL_FLOW

finally block should not execute return or throw after try-catch block already executes return or throw

BAD_FOR_STATEMENT

The index variable of for statement should be initialized and updated properly

BAD_MATCH_ALL_ARG

String.prototype.matchAll() should be called with a global regular expression

BAD_MONTH_ARG

The month argument of Date methods should not be specified as 12

BAD_MIN_MAX_FUNC

Math.min and Math.max functions should be combined in correct order

BAD_NEGATION_OPERATOR

The logical negation operator should be used in correct order

BAD_NUMBER_FUNC

String functions should not be used on number values

BAD_NUMBER_PROPERTY

Non-existent properties of number value should not be accessed

BAD_OBJECT_LITERAL_COMPARISON

Object literal should not be used for comparison

BAD_OPERAND_TYPE

in and instanceof should have a right operand of proper type

BAD_PROPERTY_DESCRIPTOR

Property descriptors should be defined properly

BAD_RANGE_IN_CHARACTER_CLASS

A character range from an uppercase to a lowercase should not be used in a regular expression

BAD_REGEXP

Empty character classes should not be used in regular expressions

BAD_REGEXP_LITERAL_IN_STRING

Regular expression should not be wrapped as a string at String.prototype.replace()

BAD_REMOVE_EVENT_LISTENER

removeEventListener() should be called with a correct listener

BAD_REPLACE_ALL_ARG

String.prototype.replaceAll() should not be called with a non-global regular expression

BAD_RETURN_IN_FOREACH

The callback function of forEach() should not return a value uselessly

BAD_STRING_CASE_COMPARISON

Result of String.prototype.toLowerCase() and String.prototype.toUpperCase() should be compared with a lower and upper case string

BAD_TEST_WITH_GLOBAL_REGEXP

The test() method of a global regular expression should be used with caution

BAD_TYPE_COERCION

Suspicious type coercion should be avoided

BAD_TYPEOF_COMPARISON

Result of typeof should be compared with correct value

BAD_USE_STRICT

Strict mode should be declared properly

CALL_NON_CONSTRUCTOR

Non-constructor function should not be called with the new operator as a constructor

CALL_NON_FUNC

Non-function object should not be called as a function

CALL_REQUIRE_AS_CONSTRUCTOR

require() should not be called as a constructor

COMPARE_INCOMPATIBLE_TYPE_STRICTLY

Strict equality should not be used for two values with different types

COMPARE_NAN

Comparing NaN directly should be avoided

DUPLICATE_CASE

switch statement should not have duplicate case clauses

DUPLICATE_PARAM

Function should not have duplicate parameter names

DUPLICATE_PROPERTY

Property should not be redeclared in object literals or classes

FUTILE_REGEXP_TEST

RegExp.prototype.test() should not be used on always matching regular expressions

FUTILE_STRING_REPLACE

The search and the replace strings of String.prototype.replace() should not be the same

GETTER_SETTER_RECURSION

Getter or setter functions should avoid an infinite call by accessing themselves

INCOMPLETE_STRING_ESCAPE

All occurrences should be replaced when escaping a special character

INHERIT_NON_CONSTRUCTOR

Class should inherit from a constructor

INSUFFICIENT_NULL_CHECK

null or undefined check should be consistent for all accesses of a variable

INVALID_PRIVATE_FIELD_ACCESS

Read or write-only private fields should be accessed properly

ITERATE_NON_ITERABLE

Non-iterable values should not be iterated

JSX_BAD_COMMENT

The content of a JSX text node should not be in the form of JavaScript comment

LENGTH_PROPERTY_TYPO

The length property should not be misspelled as lenght

MISMATCHED_COUNT_OF_ARGS

Built-in API should be called with the correct number of arguments

MISMATCHED_TYPE_OF_ARG

Built-in API should be called with arguments of correct types

MISMATCHED_TYPE_OF_DEFAULT_VALUE

Default values should be of expected types

MISPLACED_ALTERNATIVE_IN_REGEXP

Regular expression alternatives that are prefixes should be placed in proper order

MISPLACED_ANCHOR_IN_REGEXP

^ and $ anchors should be placed properly in a regular expression

MISPLACED_COMPARISON_AT_INDEX_OF

Comparison expressions should not be placed as indexOf() argument itself

MISSING_AWAIT

await operator should be used at async function call when the resolved value is needed

MISSING_ELSE_KEYWORD

else keyword should be used properly in if...else sequence

MISSING_LENGTH_IN_LOOP_CONDITION

length property should not be omitted for the array in a loop condition

MISSING_RETURN_VALUE

Return value of function without any return statement should not be used

MISSING_SUPER_CALL

Constructor of inherited class should call super

MISSING_THROW

throw statement should be used to actually throw an exception

MISUSED_EXPORTS_VAR

Assignments to exports variable and its properties should be properly exported

MISUSED_ITERATOR

Iterator objects should not be misused as arrays

MULTIPLE_RESOLVE_IN_PROMISE_EXECUTOR

The resolve and reject function should not be called multiple times in a Promise executor

MULTIPLE_SUPER_CALL

super() should be called only once in the constructor

NO_EFFECT_CALL

Result of built-in API call should not be ignored when it has no side effect

NON_REFERENCE_LHS

Value should not be assigned to LHS which is not a reference

NULL_POINTER

Properties of variables with null or undefined values should not be accessed

NUMBER_ARG_OUT_OF_RANGE

Radix or precision arguments of Number-related functions should not exceed the limit

REACT_API_TYPO

React's APIs should not have typo

REACT_BAD_API_OVERRIDDEN

React component method only supported in createReactClass() API should not be overridden in ES6 class component

REACT_BAD_API_RETURN_VALUE

Return values of React lifecycle methods and API callback functions should have valid types

REACT_BAD_CHILD_GENERATOR

Generator object should not be used as a child of React element

REACT_BAD_CONTEXT_CONSUMER_CHILD

The child node of a React context consumer should be specified properly

REACT_BAD_CONTEXT_TYPE

contextType property of a React component should be specified properly

REACT_BAD_DANGER_FORMAT

dangerouslySetInnerHTML prop for a React DOM element should be in the form of {__html: ...}

REACT_BAD_DANGER_WITH_CHILDREN

When using dangerouslySetInnerHTML prop for a React DOM element, children should not be specified

REACT_BAD_DOM_ATTRIBUTE_VALUE

React DOM element's attribute should not have a value of the wrong type

REACT_BAD_EVENT_HANDLER

Event handler of a React element should not be a string

REACT_BAD_EVENT_HANDLER_RETURN_FALSE

return false should not be used in a React event handler

REACT_BAD_INITIAL_STATE_TYPE

The initial state of React component should be set to an object or null

REACT_BAD_LENGTH_CHECK

length property itself should not be checked in the code for React child element

REACT_BAD_SPECIAL_PROPS

React special props should not be accessed

REACT_BAD_STYLE_OBJ_PROPERTY

React DOM element's style property name or value should not be wrong

REACT_BAD_STYLE_PROP

style property of a React DOM element should be an object

REACT_BAD_UNKNOWN_PROP

React property name in React DOM element should be pre-defined one

REACT_BAD_UPDATE_STATE

Updating the state inside the specific lifecycle methods of a React component should be avoided

REACT_DIRECT_ASSIGN_TO_STATE

Assignment should not be made to this.state in the React component's specific methods

REACT_EVENT_HANDLER_INVALID_THIS

React event handler should have proper this object binding

REACT_FUNC_COMPONENT_INVALID_REF_PROP

ref prop should not be used on React function components

REACT_FUNC_COMPONENT_INVALID_THIS

this object should not be used in React function components

REACT_MISMATCHED_COUNT_OF_ARGS

React API should be called with the correct number of arguments

REACT_MISMATCHED_TYPE_OF_ARG

React API should be called with arguments of correct types

REACT_MISMATCHED_TYPE_OF_PROP

React component should receive prop values of correct propTypes

REACT_MISSING_CLEANUP_IN_EFFECT_HOOK

Global event handlers added at React Effect Hooks should be properly removed at the cleanup function

REACT_MISSING_CLEANUP_IN_LIFECYCLE

Global event handlers should be properly removed during React component lifecycle

REACT_MISSING_EVENT_PERSIST

event.persist() should be called when using React synthetic events inside an asynchronous callback function

REACT_MISUSED_API_IN_RENDER

Using specific APIs inside React.render() should be avoided

REACT_MISUSED_CONTROLLED_COMPONENT

Form elements should be either controlled or uncontrolled

REACT_MISUSED_CREATOR_IN_PROP_TYPES

React type checker creator itself should not be used as a prop type

REACT_MISUSED_INNER_HTML

innerHTML prop for a React DOM element should not be used

REACT_STATIC_LIFECYCLE_INVALID_THIS

this should not be accessed in React static lifecycle methods

REACT_STATIC_PROPERTY_IN_INSTANCE

React static property should not be defined as an instance property

REACT_UNINITIALIZED_PROPS

Properties of the uninitialized this.props should not be accessed

REACT_UNINVOKED_UNSAFE_LIFECYCLE

Unsafe legacy lifecycle methods should not be defined together with newly added replacements

REACT_VOID_ELEMENT_WITH_CHILDREN

Void elements should neither have children nor dangerouslySetInnerHTML prop

REDUCE_EMPTY_ARRAY_WITHOUT_INIT

An initial value should be provided at Array.prototype.reduce() if the array can be empty

REDUNDANT_COMPOUND_ASSIGN

A reference is used on both sides of compound assignment operator

REFERENCE_BEFORE_LEXICAL_DECL

Lexical variables (let, const and class) must be declared before they are used

STRAY_SEMICOLON

An extraneous semicolon should be avoided to prevent an unintentional logic change

STRICT_MODE_ARGS_CALLER_CALLEE

caller and callee properties should not be accessed on arguments object for strict mode function

STRICT_MODE_ASSIGN_TO_READONLY_VAR

In strict mode, read-only variables cannot be assigned

STRICT_MODE_FUNC_PROPERTY

caller and arguments properties should not be accessed on strict mode function

STRICT_MODE_INVALID_THIS

Strict mode function should not be called with invalid this access

SWITCH_CASE_INCOMPATIBLE_TYPE

switch and its cases should be compared with equal types

SYNTAX_ERROR

JavaScript syntax error

UNDEFINED_IMPORT

Imported bindings should be defined and exported from the requested module

UNINITIALIZED_LOCAL_VAR

Uninitialized local variables should not be accessed

UNINVOKED_ARRAY_CALLBACK

Array callback function should not be used for an array with empty slots.

UNREACHABLE_CODE

Unreachable code should not be used

VUE_ASSIGN_TO_READONLY_PROPERTY

Read-only property of Vue should not be assigned

VUE_BAD_API_RETURN_VALUE

Return value of function-typed Vue options should be a valid type

VUE_BAD_ARROW_FUNC

Arrow function with this accesses should not be used as a Vue instance option

VUE_BAD_COMPONENT_NAME

Vue component name should be defined with valid string

VUE_BAD_DIRECTIVE_FORMAT

Vue directive should be defined with a right format

VUE_BAD_DIRECTIVE_VALUE

Vue directive should be defined with values of correct types

VUE_BAD_DYNAMIC_COMPONENT

Vue dynamic component should have a dynamically bound is attribute

VUE_BAD_EVENT_HANDLER_RETURN_FALSE

return false should not be used in a Vue event handler

VUE_BAD_HTML_SYNTAX

HTML syntax error in Vue template

VUE_BAD_MOUNT_ELEMENT

Vue instance should be mounted on a proper element

VUE_BAD_PROP_DECL

Vue prop should be declared properly

VUE_BAD_PROPERTY_SET_DELETE

Vue's global API Vue.set and Vue.delete should be called with proper argument

VUE_BAD_TRANSITION_GROUP

<transition-group> component of Vue should be used properly

VUE_DEPRECATED_FEATURE

Deprecated features of Vue should not be used

VUE_DUPLICATE_ATTRIBUTE

Each attribute of a Vue element should be unique

VUE_DUPLICATE_PROPERTY_IN_OPTION

Property should be unique between Vue options

VUE_DUPLICATE_SLOT

Each slot passed to a component should have unique name

VUE_FIXED_TRANSITION_CHILD

The child of a <transition> component should have changes to trigger the transition

VUE_INVALID_COMPUTED_PROPERTY_ACCESS

Computed properties should be accessed properly according to the existence of getter or setter

VUE_INVALID_REF_ACCESS

Properties of $refs should not be accessed when the component is not mounted

VUE_INVALID_V_ELSE

v-else directive should be used in proper place

VUE_MISMATCHED_COUNT_OF_ARGS

Vue API should be called with the correct number of arguments

VUE_MISMATCHED_TYPE_OF_ARG

Vue API should be called with arguments of correct types

VUE_MISMATCHED_TYPE_OF_OPTION

Vue option should be defined with a valid type

VUE_MISMATCHED_TYPE_OF_PROP

Vue component should receive prop values of correct prop types

VUE_MISPLACED_OPTION

Vue options should be used in proper place

VUE_MISSING_CLEANUP_IN_LIFECYCLE

Global event handlers should be properly removed during Vue component lifecycle

VUE_MISSING_REF_UNWRAP

Ref objects should be used after unwrapping

VUE_MISSING_RETURN_VALUE_IN_VALIDATOR

Validator functions for Vue prop and event should have return values

VUE_MISUSED_API_AFTER_AWAIT

Lifecycle hooks and watchers should not be registered after await in an async function

VUE_MISUSED_PROPERTY_IN_DATA

Computed and data properties should not be used inside the data() of a Vue component

VUE_MISUSED_V_FOR_VAR

The first variable of v-for should not be used as an index of the iterated array

VUE_MISUSED_V_SLOT

v-slot directive should be used properly

VUE_MULTIPLE_TEMPLATE_ROOT

Vue template should have a single root element

VUE_OPTION_TYPO

Vue option should not have typo

VUE_PASSIVE_WITH_PREVENT

v-on directive should not have passive and prevent modifiers at the same time

VUE_REDUNDANT_REF_ATTRIBUTE

ref attribute should not be redundantly defined

VUE_REDUNDANT_TEMPLATE

Template should not be defined redundantly for a Vue component

VUE_RESERVED_PROPERTY_IN_OPTION

Vue option's property name should not be a reserved name of Vue

VUE_SETUP_INVALID_THIS

this object should not be used in the Vue setup function

VUE_SHARED_DATA

The data function of a Vue component should return a newly created object

VUE_STATIC_KEY_ATTRIBUTE

Element iterated with v-for should not have a static key attribute

VUE_TEMPLATE_WITH_V_SHOW

Vue <template> element should not have v-show directive

VUE_UNINITIALIZED_INSTANCE_PROPERTY

Uninitialized properties of a Vue instance should not be accessed

VUE_USELESS_V_ONCE

v-once directive should be used properly

VUE_V_BIND_ON_DIRECTIVE

v-bind should not be used on Vue directives

Code Quality

The following rules relate to code which should be more readable, reusable and refactorable:

AMBIGUOUS_BRANCH_BODY

if branch bodies should be formatted unambiguously

AMBIGUOUS_ELSE_BRANCH

The indentation of else branch should be unambiguous

ARRAY_CALLBACK_RETURN_MISSING

Callback function argument of Array functions should have return statement

ASSIGN_BEFORE_DECL

Variables should be declared before they are assigned

ASSIGN_SAME_VALUE

The same value is assigned to the variable again

AWAIT_NON_PROMISE

await operator should not be used on a non-Promise value

BAD_WITH_STATEMENT

with statement should not be used

CONSTANT_CONDITION

Constant expression should not be used in the conditional statements

DUPLICATE_DECL

Functions or variables should not be redeclared

DUPLICATE_PARENS

Parentheses should not be used for an already parenthesized expression

DUPLICATES_IN_CHARACTER_CLASS

Character classes in a regular expression should not have duplicate characters

EMPTY_BLOCK

Empty block statements should not be used in conditional statements

FORIN_ARRAY

for-in loop should not be used on arrays

IDENTICAL_BRANCHES

Branches in the conditional statements should not have the same implementation

MISSING_COMMA

Comma should not be missing between function arguments or array elements

PREFER_INEQUALITY_OPERATOR

The inequality operator should be preferred over negating the equality comparison result

PROMISE_REJECT_FALL_THROUGH

Execution should not fall through after reject call in a Promise executor

REACT_ASYNC_RENDER_RETURN_VALUE

Using the return value of ReactDOM.render() should be avoided

REACT_DEPRECATED_DOM_ELEMENT_PROP

Deprecated prop for a React DOM element should not be used

REACT_INEFFICIENT_PURE_COMPONENT_PROP

React.PureComponent prop should not be specified with a newly created object

REACT_INVALID_DOM_NESTING

React DOM elements should be nested properly

REACT_MISSING_KEY_PROP

key prop should be defined at each element inside the children of a React element

REACT_MISUSED_UPDATE_IN_SET_STATE

this.state value may not be directly used when updating the state in React component

REACT_REDUNDANT_SHOULD_COMPONENT_UPDATE

A component extending React.PureComponent should not override shouldComponentUpdate() lifecycle method

REACT_REDUX_UNUSED_OWN_PROPS_PARAM

Unused ownProps parameter of the React Redux mapStateToProps function should be removed

REACT_UNUSED_SNAPSHOT

Return value of getSnapshotBeforeUpdate() should be used

REACT_USELESS_DEPENDENCY_OF_HOOK

The dependency of a React Hook should not be specified with a newly created object

REACT_USELESS_FORWARD_REF

The argument function of React.forwardRef() should use its second ref parameter

REACT_USELESS_MEMOIZE_HOOK

React Memoize Hooks should not be used fruitlessly

REACT_USELESS_PROP_TYPES

Useless PropTypes declaration should be removed

REACT_USELESS_SHOULD_COMPONENT_UPDATE

Overridden shouldComponentUpdate() should not always return a truthy value

SAME_OPERAND_VALUE

Operands always having the same value should be avoided

SETTER_RETURN_VALUE

Setter functions should not return values

SKIPPED_ITERATION_AFTER_SPLICE

Loop iteration should not be skipped after removing an element with Array.prototype.splice()

SWITCH_CASE_FALL_THROUGH

Cases in switch statement should not fall through to the next one

TOO_MANY_ARGS

Functions should not be called with extra arguments

TRIPLE_NEGATION_OPERATOR

The logical negation operator should not be applied 3 or more times in a row

UNEXPECTED_GLOBAL_DECL

Unexpected global variable declaration should be avoided

UNUSED_DECL

Unused local variables and functions should be removed

UNUSED_EXPR

Result of expressions should be used

UNUSED_IMPORT

Unused imported bindings should be removed

UNUSED_LABEL

Unused label should be removed

UNUSED_PARAM

Unused parameters of local function should be removed

UNUSED_PRIVATE_FIELD

Unused private fields in a class should be removed

UNUSED_REQUIRE

Unused require() should be removed

UNUSED_VAR_ASSIGN

Dead variables should not be used

USELESS_ARRAY

Elements added to an array should be used

USELESS_ARROW_FUNC_BIND

Arrow functions cannot be bound

USELESS_CALL

Function.prototype.call() should not be used when this context remains the same

USELESS_CATCH

A catch clause should not just rethrow the exception

USELESS_LOCAL_VAR_DELETE

delete operator should not be used on local variables

USELESS_LOOP

Loop should not be used when only a single iteration is needed

VUE_IDENTICAL_BRANCHES_IN_TEMPLATE

Branches of v-if directive should not have the same implementation

VUE_MISSING_KEY_ATTRIBUTE

The Vue component iterated with v-for should have a v-bind:key attribute

VUE_MISSING_RETURN_VALUE_IN_COMPUTED

Getter function of computed property should have return values

VUE_MUTATED_PROP

Props of a Vue component should not be mutated

VUE_REDUNDANT_INLINE_EVENT_HANDLER

Vue inline event handlers should not be redundantly used

VUE_TEXTAREA_WITH_USELESS_CHILDREN

<textarea> with v-model directive should not have children

VUE_UNUSED_DECL_IN_TEMPLATE

Variables declared in a Vue template should be used

VUE_UNUSED_LOCAL_COMPONENT

Local components declared in a Vue component should be used

VUE_V_IF_WITH_V_FOR

v-if directive should use variables defined at v-for appearing on the same element

ES6+ Rules

The following rules also relate to the latest ECMAScript specifications:

ACCESS_INNER_FUNC_FROM_DEFAULT_PARAM

Inner functions should not be accessed at default parameter declaration

ACCESS_THIS_BEFORE_SUPER_CALL

this should be accessed after calling super in constructor of inherited class

ARROW_FUNC_RETURN_OBJECT_MISSING

Arrow function should use parentheses to return an object literal

AWAIT_NON_PROMISE

await operator should not be used on a non-Promise value

BAD_ASSIGN_TO_CONST

Reassignment should not be made to a variable that is declared using const keyword

BAD_MATCH_ALL_ARG

String.prototype.matchAll() should be called with a global regular expression

BAD_REPLACE_ALL_ARG

String.prototype.replaceAll() should not be called with a non-global regular expression

CALL_NON_CONSTRUCTOR

Non-constructor function should not be called with the new operator as a constructor

INHERIT_NON_CONSTRUCTOR

Class should inherit from a constructor

INVALID_PRIVATE_FIELD_ACCESS

Read or write-only private fields should be accessed properly

ITERATE_NON_ITERABLE

Non-iterable values should not be iterated

MISSING_AWAIT

await operator should be used at async function call when the resolved value is needed

MISSING_SUPER_CALL

Constructor of inherited class should call super

MULTIPLE_RESOLVE_IN_PROMISE_EXECUTOR

The resolve and reject function should not be called multiple times in a Promise executor

MULTIPLE_SUPER_CALL

super() should be called only once in the constructor

PROMISE_REJECT_FALL_THROUGH

Execution should not fall through after reject call in a Promise executor

REACT_BAD_CHILD_GENERATOR

Generator object should not be used as a child of React element

REFERENCE_BEFORE_LEXICAL_DECL

Lexical variables (let, const and class) must be declared before they are used

STRICT_MODE_INVALID_THIS

Strict mode function should not be called with invalid this access

UNDEFINED_IMPORT

Imported bindings should be defined and exported from the requested module

UNUSED_IMPORT

Unused imported bindings should be removed

UNUSED_PRIVATE_FIELD

Unused private fields in a class should be removed

USELESS_ARROW_FUNC_BIND

Arrow functions cannot be bound

React Rules

We try to support fast-changing web frameworks. One of the results is the following React specific rules.

JSX_BAD_COMMENT

The content of a JSX text node should not be in the form of JavaScript comment

REACT_API_TYPO

React's APIs should not have typo

REACT_ASYNC_RENDER_RETURN_VALUE

Using the return value of ReactDOM.render() should be avoided

REACT_BAD_API_OVERRIDDEN

React component method only supported in createReactClass() API should not be overridden in ES6 class component

REACT_BAD_API_RETURN_VALUE

Return values of React lifecycle methods and API callback functions should have valid types

REACT_BAD_CHILD_GENERATOR

Generator object should not be used as a child of React element

REACT_BAD_CONTEXT_CONSUMER_CHILD

The child node of a React context consumer should be specified properly

REACT_BAD_CONTEXT_TYPE

contextType property of a React component should be specified properly

REACT_BAD_DANGER_FORMAT

dangerouslySetInnerHTML prop for a React DOM element should be in the form of {__html: ...}

REACT_BAD_DANGER_WITH_CHILDREN

When using dangerouslySetInnerHTML prop for a React DOM element, children should not be specified

REACT_BAD_DOM_ATTRIBUTE_VALUE

React DOM element's attribute should not have a value of the wrong type

REACT_BAD_EVENT_HANDLER

Event handler of a React element should not be a string

REACT_BAD_EVENT_HANDLER_RETURN_FALSE

return false should not be used in a React event handler

REACT_BAD_INITIAL_STATE_TYPE

The initial state of React component should be set to an object or null

REACT_BAD_LENGTH_CHECK

length property itself should not be checked in the code for React child element

REACT_BAD_SPECIAL_PROPS

React special props should not be accessed

REACT_BAD_STYLE_OBJ_PROPERTY

React DOM element's style property name or value should not be wrong

REACT_BAD_STYLE_PROP

style property of a React DOM element should be an object

REACT_BAD_UNKNOWN_PROP

React property name in React DOM element should be pre-defined one

REACT_BAD_UPDATE_STATE

Updating the state inside the specific lifecycle methods of a React component should be avoided

REACT_DEPRECATED_DOM_ELEMENT_PROP

Deprecated prop for a React DOM element should not be used

REACT_DIRECT_ASSIGN_TO_STATE

Assignment should not be made to this.state in the React component's specific methods

REACT_EVENT_HANDLER_INVALID_THIS

React event handler should have proper this object binding

REACT_FUNC_COMPONENT_INVALID_REF_PROP

ref prop should not be used on React function components

REACT_FUNC_COMPONENT_INVALID_THIS

this object should not be used in React function components

REACT_INEFFICIENT_PURE_COMPONENT_PROP

React.PureComponent prop should not be specified with a newly created object

REACT_INVALID_DOM_NESTING

React DOM elements should be nested properly

REACT_MISMATCHED_COUNT_OF_ARGS

React API should be called with the correct number of arguments

REACT_MISMATCHED_TYPE_OF_ARG

React API should be called with arguments of correct types

REACT_MISMATCHED_TYPE_OF_PROP

React component should receive prop values of correct propTypes

REACT_MISSING_CLEANUP_IN_EFFECT_HOOK

Global event handlers added at React Effect Hooks should be properly removed at the cleanup function

REACT_MISSING_CLEANUP_IN_LIFECYCLE

Global event handlers should be properly removed during React component lifecycle

REACT_MISSING_EVENT_PERSIST

event.persist() should be called when using React synthetic events inside an asynchronous callback function

REACT_MISSING_KEY_PROP

key prop should be defined at each element inside the children of a React element

REACT_MISUSED_API_IN_RENDER

Using specific APIs inside React.render() should be avoided

REACT_MISUSED_CONTROLLED_COMPONENT

Form elements should be either controlled or uncontrolled

REACT_MISUSED_CREATOR_IN_PROP_TYPES

React type checker creator itself should not be used as a prop type

REACT_MISUSED_INNER_HTML

innerHTML prop for a React DOM element should not be used

REACT_MISUSED_UPDATE_IN_SET_STATE

this.state value may not be directly used when updating the state in React component

REACT_REDUNDANT_SHOULD_COMPONENT_UPDATE

A component extending React.PureComponent should not override shouldComponentUpdate() lifecycle method

REACT_REDUX_UNUSED_OWN_PROPS_PARAM

Unused ownProps parameter of the React Redux mapStateToProps function should be removed

REACT_STATIC_LIFECYCLE_INVALID_THIS

this should not be accessed in React static lifecycle methods

REACT_STATIC_PROPERTY_IN_INSTANCE

React static property should not be defined as an instance property

REACT_UNINITIALIZED_PROPS

Properties of the uninitialized this.props should not be accessed

REACT_UNINVOKED_UNSAFE_LIFECYCLE

Unsafe legacy lifecycle methods should not be defined together with newly added replacements

REACT_UNUSED_SNAPSHOT

Return value of getSnapshotBeforeUpdate() should be used

REACT_USELESS_DEPENDENCY_OF_HOOK

The dependency of a React Hook should not be specified with a newly created object

REACT_USELESS_FORWARD_REF

The argument function of React.forwardRef() should use its second ref parameter

REACT_USELESS_MEMOIZE_HOOK

React Memoize Hooks should not be used fruitlessly

REACT_USELESS_PROP_TYPES

Useless PropTypes declaration should be removed

REACT_USELESS_SHOULD_COMPONENT_UPDATE

Overridden shouldComponentUpdate() should not always return a truthy value

REACT_VOID_ELEMENT_WITH_CHILDREN

Void elements should neither have children nor dangerouslySetInnerHTML prop

What's the difference with ESLint React plugin?

DeepScan supports unique rules that require the understanding of the execution flow.

REACT_EVENT_HANDLER_INVALID_THIS

In the below, DeepScan detects this.handleClick as invalid because this.handleClick is not bound with this object.

class Hello extends React.Component {
    constructor(props) {
        super(props);
        this.state = { name: "John" };
    }
    handleClick() {
        this.setState({ name: "Mary" }); // 'this' has undefined value.
    }
    render() {
        return (<div onClick={this.handleClick}>{this.state.name}</div>);
    }
}

At line 10, DeepScan reports like:

Function 'this.handleClick' is used as a React event handler without 'this' binding. But 'this' object is accessed in the function body at line 10.

REACT_MISSING_KEY_PROP

In the below, DeepScan supports the object spread syntax by tracing the involved object.

class Hello extends React.Component {
    render() {
        let childs = members.map((member) => {
            let props = { className: "style1" };
            return (<li {...props}></li>);
        });
        return (<ul>{childs}</ul>);
    }
}

At line 5, DeepScan reports like:

Each child React element in a collection should have a 'key' prop.

REACT_BAD_API_RETURN_VALUE

In the below, DeepScan detects missing return statement in if block while ESLint just finds whether return statement is in function body.

class Hello extends React.Component {
    render() {
        let someErrorFlag = true;
        if (someErrorFlag) {
            <div>Error</div>;
        } else {
            return <div>Success!</div>;
        }
    }
}

At line 5, DeepScan reports like:

The 'render()' function of React component 'Hello' returns an undefined value at this point. Consider adding 'return' keyword before JSX expression.

Vue Rules

DeepScan now supports Vue.js! The followings are our Vue specific rules:

VUE_ASSIGN_TO_READONLY_PROPERTY

Read-only property of Vue should not be assigned

VUE_BAD_API_RETURN_VALUE

Return value of function-typed Vue options should be a valid type

VUE_BAD_ARROW_FUNC

Arrow function with this accesses should not be used as a Vue instance option

VUE_BAD_COMPONENT_NAME

Vue component name should be defined with valid string

VUE_BAD_DIRECTIVE_FORMAT

Vue directive should be defined with a right format

VUE_BAD_DIRECTIVE_VALUE

Vue directive should be defined with values of correct types

VUE_BAD_DYNAMIC_COMPONENT

Vue dynamic component should have a dynamically bound is attribute

VUE_BAD_EVENT_HANDLER_RETURN_FALSE

return false should not be used in a Vue event handler

VUE_BAD_HTML_SYNTAX

HTML syntax error in Vue template

VUE_BAD_MOUNT_ELEMENT

Vue instance should be mounted on a proper element

VUE_BAD_PROPERTY_SET_DELETE

Vue's global API Vue.set and Vue.delete should be called with proper argument

VUE_BAD_PROP_DECL

Vue prop should be declared properly

VUE_BAD_TRANSITION_GROUP

<transition-group> component of Vue should be used properly

VUE_DEPRECATED_FEATURE

Deprecated features of Vue should not be used

VUE_DUPLICATE_ATTRIBUTE

Each attribute of a Vue element should be unique

VUE_DUPLICATE_PROPERTY_IN_OPTION

Property should be unique between Vue options

VUE_DUPLICATE_SLOT

Each slot passed to a component should have unique name

VUE_FIXED_TRANSITION_CHILD

The child of a <transition> component should have changes to trigger the transition

VUE_IDENTICAL_BRANCHES_IN_TEMPLATE

Branches of v-if directive should not have the same implementation

VUE_INVALID_COMPUTED_PROPERTY_ACCESS

Computed properties should be accessed properly according to the existence of getter or setter

VUE_INVALID_REF_ACCESS

Properties of $refs should not be accessed when the component is not mounted

VUE_INVALID_V_ELSE

v-else directive should be used in proper place

VUE_MISMATCHED_COUNT_OF_ARGS

Vue API should be called with the correct number of arguments

VUE_MISMATCHED_TYPE_OF_ARG

Vue API should be called with arguments of correct types

VUE_MISMATCHED_TYPE_OF_OPTION

Vue option should be defined with a valid type

VUE_MISMATCHED_TYPE_OF_PROP

Vue component should receive prop values of correct prop types

VUE_MISPLACED_OPTION

Vue options should be used in proper place

VUE_MISSING_CLEANUP_IN_LIFECYCLE

Global event handlers should be properly removed during Vue component lifecycle

VUE_MISSING_KEY_ATTRIBUTE

The Vue component iterated with v-for should have a v-bind:key attribute

VUE_MISSING_REF_UNWRAP

Ref objects should be used after unwrapping

VUE_MISSING_RETURN_VALUE_IN_COMPUTED

Getter function of computed property should have return values

VUE_MISSING_RETURN_VALUE_IN_VALIDATOR

Validator functions for Vue prop and event should have return values

VUE_MISUSED_API_AFTER_AWAIT

Lifecycle hooks and watchers should not be registered after await in an async function

VUE_MISUSED_PROPERTY_IN_DATA

Computed and data properties should not be used inside the data() of a Vue component

VUE_MISUSED_V_FOR_VAR

The first variable of v-for should not be used as an index of the iterated array

VUE_MISUSED_V_SLOT

v-slot directive should be used properly

VUE_MULTIPLE_TEMPLATE_ROOT

Vue template should have a single root element

VUE_MUTATED_PROP

Props of a Vue component should not be mutated

VUE_OPTION_TYPO

Vue option should not have typo

VUE_PASSIVE_WITH_PREVENT

v-on directive should not have passive and prevent modifiers at the same time

VUE_REDUNDANT_INLINE_EVENT_HANDLER

Vue inline event handlers should not be redundantly used

VUE_REDUNDANT_REF_ATTRIBUTE

ref attribute should not be redundantly defined

VUE_REDUNDANT_TEMPLATE

Template should not be defined redundantly for a Vue component

VUE_RESERVED_PROPERTY_IN_OPTION

Vue option's property name should not be a reserved name of Vue

VUE_SETUP_INVALID_THIS

this object should not be used in the Vue setup function

VUE_SHARED_DATA

The data function of a Vue component should return a newly created object

VUE_STATIC_KEY_ATTRIBUTE

Element iterated with v-for should not have a static key attribute

VUE_TEMPLATE_WITH_V_SHOW

Vue <template> element should not have v-show directive

VUE_TEXTAREA_WITH_USELESS_CHILDREN

<textarea> with v-model directive should not have children

VUE_UNINITIALIZED_INSTANCE_PROPERTY

Uninitialized properties of a Vue instance should not be accessed

VUE_UNUSED_DECL_IN_TEMPLATE

Variables declared in a Vue template should be used

VUE_UNUSED_LOCAL_COMPONENT

Local components declared in a Vue component should be used

VUE_USELESS_V_ONCE

v-once directive should be used properly

VUE_V_BIND_ON_DIRECTIVE

v-bind should not be used on Vue directives

VUE_V_IF_WITH_V_FOR

v-if directive should use variables defined at v-for appearing on the same element

Node.js Rules

Check out our Node.js specific rules:

CALL_REQUIRE_AS_CONSTRUCTOR

require() should not be called as a constructor

MISUSED_EXPORTS_VAR

Assignments to exports variable and its properties should be properly exported

UNUSED_REQUIRE

Unused require() should be removed

CWE Rules

DeepScan covers the following Common Weakness Enumeration (CWE) rules.
CWECWE NameRule
CWE-129Improper Validation of Array IndexARRAY_INDEX_NEGATIVE
CWE-398Indicator of Poor Code QualityNO_EFFECT_CALL
CWE-398Indicator of Poor Code QualityIDENTICAL_BRANCHES
CWE-398Indicator of Poor Code QualityUNUSED_EXPR
CWE-398Indicator of Poor Code QualityVUE_IDENTICAL_BRANCHES_IN_TEMPLATE
CWE-476NULL Pointer DereferenceNULL_POINTER
CWE-480Use of Incorrect OperatorBAD_ASSIGN_IN_CONDITION
CWE-480Use of Incorrect OperatorBAD_BITWISE_OPERATOR
CWE-481Assigning instead of ComparingBAD_ASSIGN_IN_CONDITION
CWE-482Comparing instead of AssigningUNUSED_EXPR
CWE-483Incorrect Block DelimitationAMBIGUOUS_BRANCH_BODY
CWE-484Omitted Break Statement in SwitchSWITCH_CASE_FALL_THROUGH
CWE-489Leftover Debug CodeCONSTANT_CONDITION
CWE-561Dead CodeUNREACHABLE_CODE
CWE-563Assignment to Variable without Use ('Unused Variable')UNUSED_VAR_ASSIGN
CWE-569Expression IssuesBAD_NEGATION_OPERATOR
CWE-569Expression IssuesCONSTANT_CONDITION
CWE-570Expression is Always FalseBAD_NEGATION_OPERATOR
CWE-570Expression is Always FalseCONSTANT_CONDITION
CWE-571Expression is Always TrueCONSTANT_CONDITION
CWE-628Function Call with Incorrectly Specified ArgumentsMISMATCHED_COUNT_OF_ARGS
CWE-628Function Call with Incorrectly Specified ArgumentsMISMATCHED_TYPE_OF_ARG
CWE-628Function Call with Incorrectly Specified ArgumentsNUMBER_ARG_OUT_OF_RANGE
CWE-628Function Call with Incorrectly Specified ArgumentsREACT_MISMATCHED_COUNT_OF_ARGS
CWE-628Function Call with Incorrectly Specified ArgumentsREACT_MISMATCHED_TYPE_OF_ARG
CWE-628Function Call with Incorrectly Specified ArgumentsVUE_MISMATCHED_COUNT_OF_ARGS
CWE-628Function Call with Incorrectly Specified ArgumentsVUE_MISMATCHED_TYPE_OF_ARG
CWE-628Function Call with Incorrectly Specified ArgumentsTOO_MANY_ARGS
CWE-665Improper InitializationUNUSED_EXPR
CWE-670Always-Incorrect Control Flow ImplementationSTRAY_SEMICOLON
CWE-670Always-Incorrect Control Flow ImplementationAMBIGUOUS_ELSE_BRANCH
CWE-685Function Call With Incorrect Number of ArgumentsMISMATCHED_COUNT_OF_ARGS
CWE-685Function Call With Incorrect Number of ArgumentsREACT_MISMATCHED_COUNT_OF_ARGS
CWE-685Function Call With Incorrect Number of ArgumentsVUE_MISMATCHED_COUNT_OF_ARGS
CWE-685Function Call With Incorrect Number of ArgumentsTOO_MANY_ARGS
CWE-843Access of Resource Using Incompatible Type ('Type Confusion')BAD_TYPE_COERCION