GoLand 2024.1 Help

Code Inspections in JavaScript and TypeScript

This topic lists all GoLand code inspections available in JavaScript and TypeScript.

You can toggle specific inspections or change their severity level on the Editor | Inspections page of settings  Ctrl+Alt+S.

Code quality tools

Inspection

Description

Default Severity

ESLint

Reports a discrepancy detected by the ESLint linter.



The highlighting is based on the rule severity specified in the ESLint configuration file for each individual rule.



Clear the 'Use rule severity from the configuration file' checkbox to use the severity configured in this inspection for all ESLint rules.

Disabled

JSHint

Reports a problem detected by the JSHint linter.

Disabled

Standard code style

Reports a discrepancy detected by the JavaScript Standard Style linter.



The highlighting severity in the editor is based on the severity level the linter reports.

Disabled

TSLint

Reports a discrepancy detected by the TSLint linter.



The highlighting is based on the rule severity specified in the TSLint configuration file for each individual rule.



Clear the 'Use rule severity from the configuration file' checkbox to use the severity configured in this inspection for all TSLint rules.

Disabled

Assignment issues

Inspection

Description

Default Severity

Assignment could be replaced with operator assignment

Reports an assignment operation that can be replaced by an operator assignment to make your code shorter and probably clearer.

Example:

x = x + 3;

x = x / 3;

After the quick fix is applied the result looks like:

x += 3;

x /= 3;

Disabled

Assignment to 'for' loop parameter

Reports an assignment to a variable declared as a for loop parameter. Although occasionally intended, this construct can be extremely confusing, and is often a result of an error.

Disabled

Assignment to function parameter

Reports an assignment to a function parameter, including increment and decrement operations. Although occasionally intended, this construct can be extremely confusing, and is often a result of an error.

Disabled

Assignment used as condition

Reports an assignment that is used as the condition of an if, while, for, or do statement. Although occasionally intended, this usage is confusing, and often indicates a typo (for example, = instead of ==).

Warning Warning

Nested assignment

Reports an assignment expression nested inside another expression, for example, a = b = 1. Such expressions may be confusing and violate the general design principle that a given construct should do precisely one thing.

Disabled

Result of assignment used

Reports an assignment expression where the result of the assignment is used in the containing expression. Such assignments often indicate coding errors, for example, = instead of ==. Moreover, they can result in confusion due to the order of operations, as evaluation of the assignment may affect the outer expression in unexpected ways.

Expressions in parentheses are ignored.

Disabled

Variable is assigned to itself

Reports an assignment in the form x = x.

Warning Warning

Potentially confusing code constructs

Inspection

Description

Default Severity

Confusing floating point literal

Reports any floating point number that does not have a decimal point, or any numbers before the decimal point, or and numbers after the decimal point. Such literals may be confusing, and violate several coding standards.

Disabled

Confusing sequence of '+' or '-'

Reports a suspicious combination of + or - characters in JavaScript code (for example, a+++b. Such sequences are confusing, and their semantics may change through changes in the whitespace.

Disabled

Execution of dynamically generated code

Reports a call of the eval(), setTimeout(), or setInterval() function or an allocation of a Function object. These functions are used to execute arbitrary strings of JavaScript text, which often dynamically generated. This can be very confusing, and may be a security risk.



Ignores the cases when a callback function is provided to these methods statically, without code generation.

Disabled

Magic number

Reports a "magic number" that is a numeric literal used without being named by a constant declaration. Magic numbers can result in code whose intention is unclear, and may result in errors if a magic number is changed in one code location but remains unchanged in another. The numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 1000, 0.0 and 1.0 are ignored.

Disabled

Negated 'if' statement

Reports if statements which have an else branch and a negated condition. Flipping the order of the if and else branches will usually increase the clarity of such statements.

Disabled

Negated conditional expression

Reports a conditional expression whose condition is negated. Suggests flipping the order of branches in the conditional expression to increase the clarity of the statement. Example: !condition ? 2 : 1

Disabled

Nested conditional expression

Reports a ternary conditional expression within another ternary condition. Such nested conditionals may be extremely confusing, and best replaced by more explicit conditional logic.

Disabled

Nested function

Reports a function nested inside another function. Although JavaScript allows functions to be nested, such constructs may be confusing.

Use the checkbox below to ignore anonymous nested functions.

Disabled

Overly complex arithmetic expression

Reports an arithmetic expression with too many terms. Such expressions may be confusing and bug-prone.

Use the field below to specify the maximum number of terms allowed in an arithmetic expression.

Disabled

Overly complex boolean expression

Reports a boolean expression with too many terms. Such expressions may be confusing and bug-prone.

Use the field below to specify the maximum number of terms allowed in an arithmetic expression.

Disabled

Pointless arithmetic expression

Reports an arithmetic expression that include adding or subtracting zero, multiplying by zero or one, division by one, and shift by zero. Such expressions may result from not fully completed automated refactoring.

Warning Warning

Result of increment or decrement used

Reports an increment (++) or decrement (--) expression where the result of the assignment is used in a containing expression. Such assignments can result in confusion due to the order of operations, as evaluation of the assignment may affect the outer expression in unexpected ways. Example: var a = b++

Disabled

Statement with empty body

Reports an if, while, for, or with statement with an empty body. Such statements often result from typos, and may cause confusion.

Use the checkbox below to specify whether the statements with empty block statements as bodies should be reported.

Warning Warning

Unnecessary block statement

Reports a block statement that is not used as the body of if, for, while, do, with, or try statements, or as the body of a function declaration. Starting from ECMAScript 6, JavaScript blocks introduce new scopes for let and const variables, but still free-standing block statements may be confusing and result in subtle bugs when used with var variables.

Disabled

Use of 'caller' property

Reports a usage of the caller property in a JavaScript function. Using this property to access the stack frame of the calling method can be extremely confusing and result in subtle bugs.

Warning Warning

Validity issues

Inspection

Description

Default Severity

'this' expression which references the global object

Reports a this expression outside an object literal or a constructor body. Such this expressions reference the top-level "global" JavaScript object, but are mostly useless.

Warning Warning

Attempt to assign to const or readonly variable

Reports reassigning a value to a constant or a readonly variable.

Error Error

Expression statement which is not assignment or call

Reports an expression statement that is neither an assignment nor a call. Such statements usually indicate an error.

Weak Warning Weak warning

Function with inconsistent returns

Reports a function that returns a value in some cases while in other cases no value is returned. This usually indicates an error.

Example:

function foo() { if (true) return 3; return; }

Disabled

Octal integer

Reports a deprecated octal integer literal prefixed with 0 instead of 0o.


Such literals are not allowed in modern ECMAScript code, and using them in the strict mode is an error.


To force this inspection for ES5 and ES3 language levels, select the 'Warn about obsolete octal literals in ES5- code' checkbox below.

Error Error

Reserved word used as name

Reports a JavaScript reserved word used as a name. The JavaScript specification reserves a number of words which are currently not used as keywords. Using those words as identifiers may result in broken code if later versions of JavaScript start using them as keywords.

Warning Warning

String literal which breaks HTML parsing

Reports a string literal that contains a </ sequence. Such strings may result in incorrect parsing of any HTML in which the JavaScript code is embedded.

Disabled

Data flow

Inspection

Description

Default Severity

Redundant local variable

Reports an unnecessary local variable that does not make a function more comprehensible:

  • a local variable that is immediately returned

  • a local variable that is immediately assigned to another variable and is not used anymore

  • a local variable that always has the same value as another local variable or parameter.

Use the checkbox below to have this inspection ignore variables that are immediately returned or thrown. Some coding styles suggest using such variables for clarity and ease of debugging.

Warning Warning

Reuse of local variable

Reports reusing a local variable and overwriting its value with a new value that is not related to the original variable usage. Reusing a local variable in this way may be confusing because the intended semantics of the local variable may vary with each usage. It may also cause bugs, if code changes result in values that were expected to be overwritten while they are actually live. It is good practices to keep variable lifetimes as short as possible, and not reuse local variables for the sake of brevity.

Disabled

TypeScript

Inspection

Description

Default Severity

Abstract class constructor can be made protected

Reports a public constructor of an abstract class and suggests making it protected (because it is useless to have it public).

Weak Warning Weak warning

Assigned constructor field parameter

Reports a common mistake in TypeScript code, when a class field is declared as a constructor parameter, and then this parameter is assigned.


In this case, the corresponding field won't be assigned, only the local parameter value is modified.

class Foo { constructor(private p: number) { p = 1; //must be this.p = 1; } }

Warning Warning

Duplicate union or intersection type component

Reports a duplicate type inside a union or intersection.

Warning Warning

Explicit types

Reports a type annotation that doesn't match the current code style for explicit types.

Type declarations are not necessary when the type that is inferred from the context exactly matches the type annotation, for example:

var pi: number = 3.14

In some cases it is preferable to always have explicit types - this prevents accidental type changes and makes code more explicit.

Info No highlighting, only fix

Field can be readonly

Reports a private field that can be made readonly (for example, if the field is assigned only in the constructor).

Weak Warning Weak warning

Inconsistent tsconfig.json properties

Reports inconsistency of a paths, checkJs, or extends property in a tsconfig.json file.


The checkJs property requires allowJs.


The extends property should be a valid file reference.

Warning Warning

Incorrect generic type argument

Reports an invalid type argument in a function, interface, or class declaration.

Error Error

Missing augmentation import

Reports a usage from augmentation module without an explicit import.

Info No highlighting, only fix

Missing global library

Reports a TypeScript library file that is required for a symbol but is not listed under the lib compiler option in tsconfig.json.

Error Error

Missing tsconfig.json option

Reports a usage that requires an explicit option in tsconfig.json. For example, to use JSX in .tsx files, tsconfig.json must contain "jsx" property.

Warning Warning

Narrowed type

Reports a usage of a variable where the variable type is narrowed by a type guard. Note that severity level doesn't affect this inspection.

Warning Warning

Redundant type arguments

Reports a type argument that is equal to the default one and can be removed.

Example:

type Foo<T=number> = T; let z: Foo<number>;

Weak Warning Weak warning

Referenced UMD global variable

Reports a usage of a Universal Module Definition (UMD) global variable if the current file is a module (ECMAScript or CommonJS). Referencing UMD variables without explicit imports can lead to a runtime error if the library isn't included implicitly.

Weak Warning Weak warning

Type mismatch

Reports a parameter, return value, or assigned expression of incorrect type.

Error Error

Type mismatch in 'any' type

Reports a function call with a parameter, return value, or assigned expression or incorrect type, if the context symbol can be implicitly resolved to the any type.

declare var test: any; test.hasOwnProperty(true); //reports 'true'

Weak Warning Weak warning

Unresolved TypeScript reference

Reports an unresolved reference in TypeScript code.

Weak Warning Weak warning

Unresolved imported name

Reports an unresolved name or binding in an import declaration in TypeScript code.

Error Error

Probable bugs

Inspection

Description

Default Severity

'for' loop where update or condition does not use loop variable

Reports a for loop where the condition or update does not use the for loop variable.

Disabled

'typeof' comparison with non-standard value

Reports a comparison of a typeof expression with a literal string which is not one of the standard types: undefined, object, boolean, number, string, function, or symbol. Such comparisons always return false.

Warning Warning

Comparison of expressions having incompatible types

Reports a comparison with operands of incompatible types or an operand with a type without possible common values.

Weak Warning Weak warning

Comparison with NaN

Reports a comparison with NaN. Comparisons like expr == NaN or expr === NaN are always evaluated to false.

Warning Warning

Consecutive commas in array literal

Reports a consecutive comma in an array literal. The skipped element accepts the undefined value, but it could be done unintentionally, for example, when commas are at the end of one line and at the beginning of the next one.

Warning Warning

Constructor returns primitive value

Reports a constructor function that returns a primitive value. When called with new, this value will be lost and an object will be returned instead. To avoid warnings, use the @return tag to specify the return of the function.

Disabled

Division by zero

Reports division by zero or a remainder by zero.

Disabled

Equality operator may cause type coercion

Reports a usage of an equality operator that may cause unexpected type coercions. Suggests replacing == and != with type-safe equality operators === and !==.

Depending on the option selected, one of the following cases will be reported:

  • All usages of == and != operators.

  • All usages except comparison with null. Some code styles allow using x == null as a replacement for x === null || x === undefined.

  • Only suspicious expressions, such as: == or != comparisons with 0, '', null, true, false, or undefined.

Warning Warning

Infinite loop statement

Reports a for, while, or do statement which can only exit by throwing an exception. Such statements often indicate coding errors.

Warning Warning

Infinite recursion

Reports a function which must either recurse infinitely or throw an exception. Such functions may not return normally.

Warning Warning

Possibly incorrect target of indexed property access

Reports a potentially invalid indexed property access, for example, Array[1].

Warning Warning

Potentially invalid constructor usage

Reports a usage of a potentially invalid constructor function, for example: a function that is not a constructor after new, using a constructor's prototype or calling a constructor without new. A constructor function is assumed to have an upper case name (optional) or have an explicit JSDoc @constructor tag.

Warning Warning

Potentially invalid reference to 'this' from closure

Reports a this in closure that is used for referencing properties of outer context.

Example:

function Outer() { this.outerProp = 1; function inner() { // bad, because 'outerProp' of Outer // won't be updated here // on calling 'new Outer()' as may be expected this.outerProp = 2; } inner(); }

Warning Warning

Potentially invalid reference to 'this' of a class from closure

Reports an attempt to reference a member of an ECMAScript class via the this. qualifier in a nested function that is not a lambda.


this in a nested function that is not a lambda is the function's own this and doesn't relate to the outer class.

Warning Warning

Result of object allocation ignored

Reports object allocation where the result of the allocated object is ignored, for example, new Error(); as a statement, without any assignment. Such allocation expressions may indicate an odd object initialization strategy.

Disabled

Suspicious '=+' assignment

Reports an assignment in the form a =+ b. Suggests replacing with a += b.

Warning Warning

Suspicious usage of 'bind' with arrow function

Reports bind used together with an arrow function.


Because arrow functions use lexical this, a bind call will have no effect on them.


See here for details.

Warning Warning

Suspicious variable/parameter name combination

Reports an assignment or a function call where the name of the target variable or the function parameter does not match the name of the value assigned to it.

Example:

var x = 0; var y = x;

or

var x = 0, y = 0; var rc = new Rectangle(y, x, 20, 20);

Here the inspection guesses that x and y are mixed up.

Specify the names that should not be used together. An error is reported if a parameter name or an assignment target name contains words from one group while the name of the assigned or passed variable contains words from another group.

Warning Warning

Void function return value used

Reports a return value of a function that doesn't return anything. Calling of such functions always produces an undefined value and such assignment may indicate an error.

Example:

let a = console.log('foo');

The following usages are ignored:

  • Inside a return statement

  • In some binary operations

  • For overridden non-void functions

Warning Warning

Try statement issues

Inspection

Description

Default Severity

'continue' or 'break' inside 'finally' block

Reports a break or continue statement inside a finally block. Such statements are very confusing, may hide exceptions, and complicate debugging.

Warning Warning

'return' inside 'finally' block

Reports a return statement inside a finally block. Such return statements may mask exceptions thrown, and complicate debugging.

Warning Warning

'throw' inside 'finally' block

Reports s throw statement inside a finally block. Such throw statements may mask exceptions thrown, and complicate debugging.

Warning Warning

Empty 'catch' block

Reports an empty catch block. This indicates that errors are simply ignored instead of handling them.



Any comment in a catch block mutes the inspection.

Disabled

Empty 'finally' block

Reports an empty finally block, which usually indicates an error.

Disabled

Empty 'try' block

Reports an empty try block, which usually indicates an error.

Disabled

Exception used for local control-flow

Reports a throw statement whose exceptions are always caught by the containing try statement. Using throw statements as a goto to change the local flow of control is confusing.

Warning Warning

Unused 'catch' parameter

Reports a catch parameter that is not used in the corresponding block. The catch parameters named ignore or ignored are ignored.

Use the checkbox below to disable this inspection for catch blocks with comments.

Disabled

Naming conventions

Inspection

Description

Default Severity

Class naming convention

Reports a class or a function that is annotated with a JSDoc @constructor or @class tag whose names are too short, too long, or do not follow the specified regular expression pattern.

Use the fields provided below to specify minimum length, maximum length, and a regular expression expected for classes names. Use the standard java.util.regex format for regular expressions.

Disabled

Function naming convention

Reports a function whose name is too short, too long, or does not follow the specified regular expression pattern.

Use the fields provided below to specify minimum length, maximum length, and a regular expression for function names. Use the standard java.util.regex format for regular expressions.

Disabled

Function parameter naming convention

Reports a function parameter whose name is too short, too long, or doesn't follow the specified regular expression pattern.

Use the fields provided below to specify minimum length, maximum length and regular expression expected for local variables names. Use the standard java.util.regex format regular expressions.

Disabled

Identifiers with non-ASCII symbols

Reports a non-ASCII symbol in a name.



If the 'Allow only ASCII names' option is selected, reports all names that contain non-ASCII symbols.


Otherwise reports all names that contain both ASCII and non-ASCII symbols.

Warning Warning

Local variable naming convention

Reports a local variable whose name is too short, too long, or doesn't follow the specified regular expression pattern.

Use the fields provided below to specify minimum length, maximum length, and a regular expression expected for local variables names. Use the standard java.util.regex format regular expressions.

Disabled

Flow type checker

Inspection

Description

Default Severity

Code is not covered by Flow

Reports JavaScript code fragments that are not covered by the Flow type checker. To use this inspection, configure the Flow executable in Settings | Languages & Frameworks | JavaScript.

Disabled

Flow type checker

Reports errors from Flow.

Disabled

Misplaced @flow flag

Reports a @flow flag comment that is not located at the top of a file.

Warning Warning

Missing .flowconfig

Reports a JavaScript file with a @flow flag that doesn't have an associated .flowconfig file in the project.

Warning Warning

Function metrics

Inspection

Description

Default Severity

Function with more than three negations

Reports a function with three or more negation operations (! or !=). Such functions may be unnecessarily confusing.

Disabled

Function with multiple loops

Reports a function with multiple loop statements.

Disabled

Function with multiple return points

Reports a function with multiple return points. Such functions are hard to understand and maintain.

Disabled

Function with too many parameters

Reports a function with too many parameters. Such functions often indicate problems with design.

Use the field below to specify the maximum acceptable number of parameters for a function.

Disabled

Overly complex function

Reports a function with too many branching points in a function (too high cyclomatic complexity). Such functions may be confusing and hard to test.

Use the field provided below to specify the maximum acceptable cyclomatic complexity for a function.

Disabled

Overly long function

Reports an overly long function. Function length is calculated by counting up the number of non-empty statements in the function. Functions that are too long are error-prone and difficult to test.

Use the field below to specify the maximum acceptable number of statements in a function.

Disabled

Overly nested function

Reports a function whose body contains statements that are too deeply nested within other statements. Such functions may be confusing and indicate that refactoring may be necessary.

Use the field provided below to specify the maximum acceptable nesting depth allowed in a function.

Disabled

Code style issues

Inspection

Description

Default Severity

'var' declared not at the beginning of a function

Checks that declarations of local variables declared with var are at the top of a function scope.



By default, variable declarations are always moved ("hoisted") invisibly to the top of their containing scope when the code is executed. Therefore, declaring them at the top of the scope helps represent this behavior in the code.

Disabled

Chained equality

Reports a chained equality comparison (i.e. a==b==c). Such comparisons are confusing.

Disabled

Chained function call

Reports a function call whose target is another function call, for example, foo().bar()

Disabled

Constant on left side of comparison

Reports a comparison operation with a constant value in the left-hand side. According to coding conventions, constants should be in the right-hand side of comparisons.

Disabled

Constant on right side of comparison

Reports a comparison operation with a constant in the right-hand side. According to coding conventions, constants should only be in the left-hand side of comparisons.

Disabled

Nested function call

Reports a function call that is used as an argument in another function call, for example, foo(bar())

Disabled

Redundant braces around arrow function body

Reports an arrow function whose body only consists of braces and exactly one statement. Suggests converting to concise syntax without braces.

let incrementer = (x) => {return x + 1};

After the quick-fix is applied, the code fragment looks as follows:

let incrementer = (x) => x + 1;

Info No highlighting, only fix

Statement body without braces

Reports a if, while, for, or with statements whose body is not a block statement. Using code block in statement bodies is usually safer for downstream maintenance.

Disabled

Undefined property assignment

Reports an assignment to a property that is not defined in the type of a variable.

Example:

/** * @type {{ property1: string, property2: number }} */ let myVariable = create(); myVariable.newProperty = 3; // bad

Weak Warning Weak warning

Unnecessary parentheses

Reports redundant parentheses.

In expressions:

var x = ((1) + 2) + 3

In arrow function argument lists:

var incrementer = (x) => x + 1

In TypeScript and Flow type declarations:

type Card = (Suit & Rank) | (Suit & Number)

Info No highlighting, only fix

Unterminated statement

Reports a statement without a semicolon or a newline at the end.

Select the 'Terminate statements with semicolons' option in Editor | Code Style | JavaScript or TypeScript - Punctuation to report any statement that doesn't end with a semicolon, even if a newline is used. According to some coding styles, semicolons are preferred to line-breaks for consistency with the other languages.

Disabled

Potentially undesirable code constructs

Inspection

Description

Default Severity

'break' statement

Reports a break statements. Ignores break statements that end case blocks.

Disabled

'break' statement with label

Reports a labeled break statement.

Disabled

'continue' statement

Reports a continue statement.

Disabled

'continue' statement with label

Reports a labeled continue statement.

Disabled

'debugger' statement

Reports a debugger statement used for interaction with the Javascript debuggers. Such statements should not appear in production code.

Disabled

'void' expression

Reports a void expression.

Disabled

'with' statement

Reports a with statements. Such statements result in potentially confusing implicit bindings, and may behave strangely in setting new variables.

Warning Warning

Anonymous function

Reports an anonymous function. An explicit name of a function expression may be helpful for debugging. Ignores function expressions without names if they have a name property specified in the ECMAScript 6 standard. For example, var bar = function() {}; is not reported.

Disabled

Comma expression

Reports a comma expression. Such expressions are often a sign of overly clever code, and may lead to subtle bugs. Comma expressions in the initializer or in the update section of for loops are ignored.

Warning Warning

Conditional expression

Reports a ternary conditional expression. Some coding standards prohibit such expressions in favor of explicit if statements.

Disabled

Labeled statement

Reports a labeled statement.

Disabled

DOM issues

Inspection

Description

Default Severity

Call to 'document.write()'

Reports a method call to document.write() or document.writeln(). Most usages of such calls are performed better with explicit DOM calls, such as getElementByID() and createElement(). Additionally, the write() and writeln() calls will not work with XML DOMs, including DOMs for XHTML if viewed as XML. This can result in difficulty to point out bugs.

Disabled

Inaccurate platform detection

Reports a common JavaScript pattern for detecting the browser or operating system in which the script is run. In addition to pointing out non-portable constructs, these platform detection patterns are often incomplete and easily fooled. For most cases, detection of individual environment features is preferable to attempting to detect the entire platform.

Patterns detected include:

  • document.all

  • document.layers

  • navigator.userAgent

  • navigator.oscpu

  • navigator.appName

  • navigator.appCodeName

  • navigator.platform

Disabled

Incompatible XHTML usages

Reports common JavaScript DOM patterns which may present problems with XHTML documents. In particular, the patterns detected will behave completely differently depending on whether the document is loaded as XML or HTML. This can result in subtle bugs where script behaviour is dependent on the MIME-type of the document, rather than its content. Patterns detected include document.body, document.images, document.applets, document.links, document.forms, and document.anchors.

Disabled

Use of 'innerHTML' property

Reports a JavaScript access to DOM nodes as text using the innerHTML property. Most usages of innerHTML are performed better with explicit DOM calls, such as getElementByID() and createElement(). Additionally, innerHTML will not work with XML DOMs, including DOMs for XHTML if viewed as XML. This can lead to difficulties in diagnosing bugs.

Disabled

Imports and dependencies

Inspection

Description

Default Severity

Mismatched dependencies in package.json

Reports a dependency from package.json that is not installed or doesn't match the specified version range.

Warning Warning

Missing JSX namespace

Reports a usage of a JSX construction without importing namespace. Having the namespace in the file scope ensures proper code compilation.

Info No highlighting, only fix

Missing module dependency

Reports a module from a require() call or an import statement that is not installed or is not listed in package.json dependencies.

Suggests installing the module and including it into package.json.

For require() calls, works only in the files from the scope of Node.js Core JavaScript library.

Weak Warning Weak warning

URL import is used

Checks used URL imports in the JavaScript language. Suggests downloading the module for the specified remote URL. Such association enables the IDE to provide proper code completion and navigation.



URLs in import specifiers are supported only for ECMAScript modules in the JavaScript language.

Info No highlighting, only fix

Unused import

Reports a redundant import statement. This is usually the case if the imported symbols are not used in the source file. To avoid side-effects, consider using bare import import 'packageName' instead of the regular one.

Warning Warning

Update package.json dependencies to latest versions

Suggests to upgrade your package.json dependencies to the latest versions, ignoring specified versions.

Info No highlighting, only fix

Node.js

Inspection

Description

Default Severity

Unresolved Node.js APIs

Suggests configuring coding assistance for Node.js, for example, require and core modules ('path', 'http', 'fs', etc.).

See https://nodejs.org/api/ for the complete list.

Warning Warning

Unit testing

Inspection

Description

Default Severity

Highlight failure line in test code

Reports a failed method call or an assertion in a test.

Warning Warning

Invalid Karma configuration file

Reports a potential error in a file path ('basePath', 'files') for a Karma configuration file, for example, karma.conf.js.

Warning Warning

React

Inspection

Description

Default Severity

Invalid DOM element nesting

Detects HTML elements in JSX files which are not nested properly according to the DOM specification. React reports runtime warnings on incorrectly nested elements.

Warning Warning

Async code and promises

Inspection

Description

Default Severity

'await' in non-async function

Reports a usage of await in a function that was possibly intended to be async but is actually missing the async modifier.

Although await can be used as an identifier, it is likely that it was intended to be used as an operator, so the containing function should be made async.

Weak Warning Weak warning

Missing await for an async function call

Reports an async function call without an expected await prefix inside an async function. Such call returns a Promise and control flow is continued immediately.

Example:

async function bar() { /* ... */ } async function foo() { bar(); // bad }

After the quick-fix is applied, the await prefix is added:

async function bar() { /* ... */ } async function foo() { await bar(); // good }

When the 'Report for promises in return statements' checkbox is selected, also suggests adding await in return statements.


While this is generally not necessary, it gives two main benefits.


  • You won't forget to add await when surrounding your code with try-catch.

  • An explicit await helps V8 runtime to provide async stack traces.

Weak Warning Weak warning

Redundant 'await' expression

Reports a redundant usage of await, such as await await, or awaiting a non-promise result.

When the 'Report for promises' option is selected, suggests removing await before promises when applicable (in return statements, and with Promise.resolve/reject).

Removing await in such contexts causes two problems.

  • Surrounding your code with try-catch and forgetting to add await will change code semantics while you may fail to notice that.

  • Having an explicit await may prevent the V8 runtime from providing async stack traces.

Weak Warning Weak warning

Result of method call returning a promise is ignored

Reports a function call that returns a Promise that is not used later. Such calls are usually unintended and indicate an error.

Weak Warning Weak warning

Top-level 'await' expression

Reports a usage of a top-level await expression.

While the new 'top-level async' proposal is on its way, using await outside async functions is not allowed.

Disabled

Control flow issues

Inspection

Description

Default Severity

'for' loop may be replaced by 'while' loop

Reports a for loop that contains neither initialization nor an update component. Suggests replacing the loop with a simpler while statement.

Example:

for(; exitCondition(); ) { process(); }

After the quick-fix is applied the result looks like:

while(exitCondition()) { process(); }

Use the checkbox below if you wish this inspection to ignore for loops with trivial or non-existent conditions.

Disabled

'if' statement with identical branches

Reports an if statement with identical then and else branches. Such statements are almost certainly an error.

Disabled

'if' statement with too many branches

Reports an if statement with too many branches. Such statements may be confusing, and often indicate inadequate levels of design abstraction.

Use the field below to specify the maximum number of branches expected.

Disabled

Conditional expression with identical branches

Reports a ternary conditional expression with identical then and else branches.

Disabled

Constant conditional expression

Reports a conditional expression in the format true? result1: result2 or false? result1: result2. Suggests simplifying the expression.

Warning Warning

Duplicate condition in 'if' statement

Reports duplicate conditions in different branches of an if statement. Duplicate conditions usually represent programmer oversight.

Example:

if (a) { ... } else if (a) { ... }

Disabled

Loop statement that doesn't loop

Reports a for, while, or do statement whose bodies are guaranteed to execute at most once. Normally, this indicates an error.

Warning Warning

Object is 'null' or 'undefined'

Reports an error caused by invoking a method, accessing a property, or calling a function on an object that is undefined or null.

Warning Warning

Pointless statement or boolean expression

Reports a pointless or pointlessly complicated boolean expression or statement.

Example:

let a = !(false && x); let b = false || x;

After the quick fix is applied the result looks like:

let a = true; let b = x;

Warning Warning

Redundant 'if' statement

Reports an if statement that can be simplified to a single assignment or a return statement.

Example:

if(foo()) { return true; } else { return false; }

After applying the quick-fix the code looks as follows:

return foo();

Warning Warning

Redundant conditional expression

Reports a conditional expression of the form

condition ? true : false condition ? false : true

These expressions may be safely converted to

condition !condition

Warning Warning

Tail recursion

Reports a tail recursion, that is, when a function calls itself as its last action before returning. A tail recursion can always be replaced by looping, which will be considerably faster. Some JavaScript engines perform this optimization, while others do not. Thus, tail recursive solutions may have considerably different performance characteristics in different environments.

Disabled

Unnecessary 'continue' statement

Reports an unnecessary continue statement at the end of a loop. Suggests removing such statements.

Warning Warning

Unnecessary 'return' statement

Reports an unnecessary return statement, that is, a return statement that returns no value and occurs just before the function would have "fallen through" the bottom. These statements may be safely removed.

Warning Warning

Unnecessary label

Reports an unused label.

Warning Warning

Unnecessary label on 'break' statement

Reports a labeled break statement whose labels may be removed without changing the flow of control.

Warning Warning

Unnecessary label on 'continue' statement

Reports a labeled continue statement whose labels may be removed without changing the flow of control.

Warning Warning

Unreachable code

Reports code that can never be executed, which almost certainly indicates an error

Warning Warning

Unsound type guard check

Reports a typeof or instanceof unsound type guard check. The typeof x type guard can be unsound in one of the following two cases:

  • typeof x never corresponds to the specified value (for example, typeof x === 'number' when x is of the type 'string | boolean')

  • typeof x always corresponds to the specified value (for example, typeof x === 'string' when x is of the type 'string')


The x instanceof A type guard can be unsound in one of the following two cases:

  • The type of x is not related to A

  • The type of x is A or a subtype of A

Warning Warning

ES2015 migration aids

Inspection

Description

Default Severity

'for..in' is used instead of 'for..of'

Reports a usage of a for..in loop on an array. Suggests replacing it with a for..of loop.


for..of loops, which are introduced in ECMAScript 6, iterate over iterable objects. For arrays, this structure is preferable to for..in, because it works only with array values but not with array object's properties.

Info No highlighting, only fix

'let' is used instead of 'const'

Reports a let declaration that can be made const.


Info No highlighting, only fix

'module.exports' is used instead of 'export'

Reports a module.export statement. Suggests replacing it with an export or export default statement.



Please note that the quick-fix for converting module.export into export is not available for module.export inside functions or statements because export statements can only be at the top level of a module.

Info No highlighting, only fix

'require()' is used instead of 'import'

Reports a require() statement. Suggests converting it to a require() call with an import statement.



Enable 'Convert require() inside inner scopes with Fix all action' to convert all require() calls inside the nested functions and statements when using the 'Fix all' action.



Please note that converting require() statements inside inner scopes to import statements may cause changes in the semantics of the code. Import statements are static module dependencies and are hoisted, which means that they are moved to the top of the current module. require() calls load modules dynamically. They can be executed conditionally, and their scope is defined by the expression in which they are used.


Clear the 'Convert require() inside inner scopes with Fix all action' checkbox to prevent any changes in these complex cases when using the 'Fix all' action.

Info No highlighting, only fix

'var' is used instead of 'let' or 'const'

Reports a var declaration that is used instead of let or const.


Both let and const are block-scoped and behave more strictly.



Suggests replacing all var declarations with let or const declarations, depending on the semantics of a particular value. The declarations may be moved to the top of the function or placed before the first usage of the variable to avoid Reference errors.


Select the 'Conservatively convert var with Fix all action' option to prevent any changes in these complex cases when using the 'Fix all' action.

Weak Warning Weak warning

Function expression is used instead of arrow function

Reports a function expression. Suggests converting it to an arrow function.

Example:

arr.map(function(el) {return el + 1})

After applying the quick-fix the code looks as follows:

arr.map(el => el + 1)

Info No highlighting, only fix

Indexed 'for' is used instead of 'for..of'

Reports an indexed for loop used on an array. Suggests replacing it with a for..of loop.


for..of loops are introduced in ECMAScript 6 and iterate over iterable objects.

Info No highlighting, only fix

String concatenation is used instead of template literal

Reports a string concatenation. Suggests replacing it with a template literal

Example

"result: " + a + "."

After applying the quick-fix the code looks as follows:

`result: ${a}.`

Info No highlighting, only fix

General

Inspection

Description

Default Severity

Deprecated symbol used

Reports a usage of a deprecated function variable.

Weak Warning Weak warning

Destructuring properties with the same key

Reports multiple destructuring properties with identical keys. Suggests merging the properties.

Weak Warning Weak warning

Duplicate declaration

Reports multiple declarations in a scope.

Warning Warning

ECMAScript specification is not followed

Reports basic syntax issues and inconsistencies with language specification, such as invalid usages of keywords, usages of incompatible numeric format, or multiple parameters to getters/setters.


Generally, such errors must always be reported and shouldn't be disabled. But in some cases, such as issues due to the dynamic nature of JavaScript, the use of not yet supported language features, or bugs in IDE's checker, it may be handy to disable reporting these very basic errors.

Error Error

Implicitly declared global JavaScript variable

Reports an implicit declaration of a global variable.

Example:

var aaa = 1; // good bbb = 2; // bad, if bbb is not declared with 'var' somewhere

Weak Warning Weak warning

Import can be shortened

Reports an ES6 import whose from part can be shortened. Suggests importing the parent directory.

Warning Warning

Inaccessible @private and @protected members referenced

Reports a reference to a JavaScript member that is marked with a @private or @protected tag but does not comply with visibility rules that these tags imply.

Warning Warning

Incorrect usage of JSDoc tags

Reports warnings implied by Google Closure Compiler annotations including correct use of @abstract, @interface, and @implements tags.

Warning Warning

JQuery selector can be optimized

Reports a duplicated jQuery selector that can be cached or a usage of an attribute or a pseudo-selector (optional).

Warning Warning

JSX syntax used

Reports a usage of a JSX tag in JavaScript code.

Disabled

Method can be made 'static'

Reports a class method that can be safely made static. A method can be static if it does not reference any of its class' non-static methods and non-static fields and is not overridden in a subclass.

Use the first checkbox below to inspect only private methods.

Info No highlighting, only fix

Mismatched JSDoc and function signature

Reports mismatch between the names and the number of parameters within a JSDoc comment and the actual parameters of a function. Suggests updating parameters in JSDoc comment.

Example:

/** * @param height Height in pixels */ function sq(height, width) {} // width is not documented

After the quick-fix is applied:

/** * @param height Height in pixels * @param width */ function sq(height, width) {}

Warning Warning

Mismatched query and update of collection

Reports a collection of fields or variables whose contents are either queried and not updated or updated and not queried. Such mismatched queries and updates are pointless and may indicate either dead code or a typographical error.

Query methods are automatically detected, based on whether they return something, or a callback is passed to them. Use the table below to specify which methods are update methods.

Warning Warning

Missed locally stored library for HTTP link

Reports a URL of an external JavaScript library that is not associated with any locally stored file. Suggests downloading the library. Such association enables the IDE to provide proper code completion and navigation.

Warning Warning

Non-strict mode used

Reports a JavaScript file that is not in the strict mode.

Disabled

Primitive type object wrapper used

Reports an improper usage of a wrapper for primitive types or a property of a primitive type being modified, as in the latter case the assigned value will be lost.

Warning Warning

Property can be replaced with shorthand

Reports an object property that can be converted to ES6 shorthand style and provides a quick-fix to do it.

Example:

var obj = {foo:foo}

After applying the quick-fix the code looks as follows:

var obj = {foo}

Info No highlighting, only fix

Redundant nesting in template literal

Reports nested instances of a string or a template literal. Suggests inlining the nested instances into the containing template string.

Example:

let a = `Hello, ${`Brave ${"New"}`} ${"World"}!`

After applying the quick-fix the code looks as follows:

let a = `Hello, Brave New World!`

Weak Warning Weak warning

Referencing mutable variable from closure

Reports access to outer mutable variables from functions.

Example:

for (var i = 1; i <= 3; i++) { setTimeout(function() { console.log(i); // bad }, 0); }

Warning Warning

Signature mismatch

Reports a JavaScript call expression where the arguments do not match the signature of the referenced function, including the types of arguments and their number. Also, reports if the overloading function doesn't match the overloaded one in terms of parameters and return types.

TypeScript code is ignored.

Weak Warning Weak warning

Syntax errors and unresolved references in JSDoc

Reports a syntax discrepancy in a documentation comment.

Warning Warning

Unfiltered for..in loop

Reports unfiltered for-in loops.



The use of this construct results in processing not only own properties of an object but properties from its prototype as well. It may be unexpected in some specific cases, for example, in utility methods that copy or modify all properties or when Object 's prototype may be incorrectly modified. For example, the following code will print 42 and myMethod:



Object.prototype.myMethod = function myMethod() {}; let a = { foo: 42 }; for (let i in a) { console.log(a[i]); }

Suggests replacing the whole loop with a Object.keys() method or adding a hasOwnProperty() check. After applying the quick-fix the code looks as follows:

for (let i in a) { if (a.hasOwnProperty(i)) { console.log(a[i]); } }

Disabled

Unnecessary semicolon

Reports an unneeded semicolon.

Warning Warning

Unneeded last comma in array literal

Reports a usage of a trailing comma in an array literal.

The warning is reported only when the JavaScript language version is set to ECMAScript 5.1.

Although trailing commas in arrays are allowed by the specification, some browsers may throw an error when a trailing comma is used.

You can configure formatting options for trailing commas in Code Style | JavaScript or TypeScript | Punctuation.

Warning Warning

Unneeded last comma in object literal

Reports usages of a trailing comma in object literals.

The warning is reported only when the JavaScript language version is set to ECMAScript 5.1.

Trailing commas in object literals are allowed by the specification, however, some browsers might throw an error when a trailing comma is used.

You can configure formatting options for trailing commas in Code Style | JavaScript or TypeScript | Punctuation.

Warning Warning

Unresolved Ext JS xtype

Reports an Ext JS xtype reference that doesn't have a corresponding class.

Warning Warning

Unresolved JSX component

Reports an unresolved reference to a JSX component. Suggests adding a missing import statement if the referenced component is defined in the project or its dependencies or creating a new component with this name.

The template for a new component can be modified in Editor | File and Code Templates.

Weak Warning Weak warning

Unresolved JavaScript reference

Reports an unresolved reference in JavaScript code.

TypeScript code is ignored.

Weak Warning Weak warning

Unresolved file reference

Reports an unresolved file reference in a JavaScript file, including CommonJS and AMD modules references.

Warning Warning

Use of possibly unassigned property in a static initializer

Reports a class member initializer which references another non-hoisted class member while the latter may be not initialized yet.



Initialization of class members happens consequently for fields, so a field cannot reference another field that is declared later.

Warning Warning

Variable declaration can be merged with the first assignment to the variable

Reports a variable that is declared without an initializer and is used much further in the code or in a single nested scope. Suggests moving the variable closer to its usages and joining it with the initializer expression.

Info No highlighting, only fix

Webpack config compliance with JSON Schema

Validates options in webpack config files (which name should start with `webpack`, e.g. `webpack.config.js`) against webpack options schema.



Disable this inspection to turn off validation and code completion inside the configuration object.

Warning Warning

Switch statement issues

Inspection

Description

Default Severity

'default' not last case in 'switch'

Reports a switch statement where the default case comes before another case instead of being the very last case, which may cause confusion.

Disabled

'switch' statement has missing branches

Reports a switch statement on a variable of the type enum or union when the statement doesn't cover some value options from the type.

Info No highlighting, only fix

'switch' statement has no 'default' branch

Reports a switch statement without a default clause when some possible values are not enumerated.

Info No highlighting, only fix

'switch' statement is redundant and can be replaced

Reports a switch statement with an empty body, or with only one case branch, or with a default branch only.

Info No highlighting, only fix

Duplicate 'case' label

Reports a duplicated case label on a switch statement, which normally indicates an error.

Warning Warning

Fallthrough in 'switch' statement

Reports a switch statement where control can proceed from a branch to the next one. Such "fall-through" often indicates an error, for example, a missing break or return.

Warning Warning

Nested 'switch' statement

Reports a switch statement that is nested in another switch statement. Nested switch statements may be very confusing, particularly if indenting is inconsistent.

Disabled

Text label in 'switch' statement

Reports a labeled statement inside a switch statement, which often results from a typo.

Example:

switch(x) { case 1: case2: //typo! case 3: break; }

Disabled

Unreachable 'case' branch of a 'switch' statement

Reports an unreachable case branch of a switch statement.

Example:

/** * @param {('foo' | 'bar')} p */ function foo(p) { switch (p) { case 'foo': break; case 'bar': break; case 'baz': break; // unreachable } }

Warning Warning

Variable is declared and being used in different 'case' clauses

Reports a variable that is declared in one case clause of a switch statement but is used in another case clause of the same statement. For block-scoped variables, this results in throwing a ReferenceError. For var variables, it indicates a potential error.

Disable the inspection for var variables if this pattern is used intentionally.

Warning Warning

Bitwise operation issues

Inspection

Description

Default Severity

Bitwise expression can be simplified

Reports an expression that includes and with zero, or by zero, or shifting by zero. Such expressions may result from not fully completed automated refactorings.

Disabled

Bitwise operator usage

Reports a suspicious usage of a bitwise AND (" & ") or OR (" | ") operator. Usually it is a typo and the result of applying boolean operations AND (" && ") and OR (" || ") is expected.

Warning Warning

Incompatible bitwise mask operation

Reports a bitwise mask expression which for sure evaluates to true or false. Expressions are of the form (var & constant1) == constant2 or (var | constant1) == constant2, where constant1 and constant2 are incompatible bitmask constants.

Example:

// Incompatible mask: as the last byte in mask is zero, // something like 0x1200 would be possible, but not 0x1234 if ((mask & 0xFF00) == 0x1234) {...}

Warning Warning

Shift operation by possibly wrong constant

Reports a shift operation where the second operand is a constant outside the reasonable range, for example, an integer shift operation outside the range 0..31, shifting by negative or overly large values.

Warning Warning

Unused symbols

Inspection

Description

Default Severity

Unused assignment

Reports a variable whose value is never used after assignment.


Suggests removing the unused variable to shorten the code and to avoid redundant allocations.

The following cases are reported:

  • A variable is never read after assignment.

  • The value of a variable is always overwritten with another assignment before the variable is read next time.

  • The initializer of a variable is redundant (for one of the above-mentioned reasons).

Warning Warning

Unused global symbol

Reports an unused globally accessible public function, variable, class, or property.

Warning Warning

Unused local symbol

Reports an unused locally accessible parameter, local variable, function, class, or private member declaration.

Warning Warning

Last modified: 11 February 2024