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 the Settings/Preferences Ctrl+Alt+S.
DOM issues
Inspection | Description | Default Severity |
---|---|---|
Call to 'document.write()' | Reports method calls to document.write() or document.writeln(). Most uses of these calls are better performed using 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 |
Platform detection | Reports common JavaScript patterns for detecting the browser or operating system in which the script is being 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, and navigator.platform | Disabled |
Use of 'innerHTML' property | Reports JavaScript accesses to DOM nodes as text using the innerHTML property. Most uses of innerHTML are better performed using 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 difficult to diagnose bugs. | Disabled |
XHTML incompatibilities | 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 |
Imports and dependencies
Inspection | Description | Default Severity |
---|---|---|
Imports validation | Validates names and paths in ECMAScript import declarations. | Weak warning |
Mismatched dependencies in package.json | Reports dependencies in package.json that are not installed or don't match the specified version range. | Warning |
Missing React import with JSX | When using JSX, it's usually required to have import from React in the file scope. Otherwise, the code may not compile properly. The inspection is disabled in projects with React 17 because the version no longer requires the React import. | Weak warning |
Missing module dependency | Checks whether the module in the require() call or import statement exists, whether it is listed in package.json dependencies, and whether it is locally installed. | Weak warning |
Unused ES6 / TypeScript imports | Reports unused JavaScript or TypeScript import bindings or specifiers. The validation works in ES6 and TypeScript files. | Warning |
Code quality tools
Inspection | Description | Default Severity |
---|---|---|
ESLint | Runs the ESLint linter. | Disabled |
JSHint | Runs JSHint validator for specified JavaScript file. | Disabled |
Standard code style | Reports errors according to JavaScript Standard Style. | Disabled |
TSLint | Runs TSLint- a linter for TypeScript. | Disabled |
Assignment issues
Inspection | Description | Default Severity |
---|---|---|
Assignment replaceable with operator assignment | Reports assignment operations which can be replaced by operator assignment. Using operator assignment may be clearer, and theoretically more performant. | Disabled |
Assignment to 'for' loop parameter | Reports assignments to variables declared as a for loop parameter. While occasionally intended, this construct can be extremely confusing, and is often the result of a programmer error. | Disabled |
Assignment to function parameter | Reports assignments to function parameters. It also reports attempts to increment or decrement the variable. While occasionally intended, this construct can be extremely confusing, and is often the result of a programmer error. | Disabled |
Assignment used as condition | Reports an assignment being used as the condition of an if, while, for or do statement. While occasionally intended, this usage is confusing, and often indicates a typo (= instead of == ). | Warning |
Nested assignment | Reports assignment expressions nested inside other expressions. While admirably terse, 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 assignment expressions where the result of the assignment is used in a containing expression. Such assignments are often indications of coding errors such as using = instead of ==. Moreover, they can result in confusion due to order of operations, as evaluation of the assignment may effect the outer expression in unexpected ways. | Disabled |
Variable is assigned to itself | Reports assignments of the form x = x. These are pointless, and usually indicate programmer error. | Warning |
Potentially confusing code constructs
Inspection | Description | Default Severity |
---|---|---|
Confusing floating point literal | Reports floating point numbers which do not have a decimal point, numbers before the decimal point, and numbers after the decimal point. Such literals may be confusing, and violate several coding standards. | Disabled |
Confusing sequence of '+' or '-' | Reports suspicions combinations of + or - characters in JavaScript code (e.g. a+++b. While legal, such sequences are confusing, and may have their semantics changed through changes in whitespace. | Disabled |
Execution of dynamically generated JavaScript | Reports calls to the eval(), setTimeout(), and setInterval() functions, or allocation of a Function object. These functions are used to execute arbitrary strings of JavaScript text, often dynamically generated. This can be very confusing, and may be a security risk. | Disabled |
Magic number | Reports "magic numbers", i.e. literal numeric constants used without declaration. "Magic numbers" can result in code whose intention is extremely unclear, and may result in errors if a "magic number" is changed in one code location but not another. The numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 1000, 0.0 and 1.0 are not reported by this inspection. | 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 conditional expressions whose conditions are negated. Flipping the order of the conditional expression branches will usually increase the clarity of such statements. | Disabled |
Nested conditional expression | Reports ternary conditional expressions contained within other ternary conditions. Such nested conditionals may be extremely confusing, and best replaced by more explicit conditional logic. | Disabled |
Nested function | Reports functions nested inside other functions. While JavaScript allows functions to be nested, such constructs may be confusing. Additionally, nested functions are prone to cause difficult-to-diagnose memory leaks in certain browsers, including Microsoft Internet Explorer. | Disabled |
Overly complex arithmetic expression | Reports arithmetic expressions with too many terms. Such expressions may be confusing and bug-prone. | Disabled |
Overly complex boolean expression | Reports boolean expressions with too many terms. Such expressions may be confusing and bug-prone. | Disabled |
Pointless arithmetic expression | Reports pointless arithmetic expressions. Such expressions include adding or subtracting zero, multiplying by zero or one, division by one, and shift by zero. Such expressions may be the result of automated refactorings not completely followed through to completion, and in any case are unlikely to be what the developer intended to do. | Warning |
Result of increment or decrement used | Reports increment (++) or decrement (--) expressions where the result of the assignment is used in a containing expression. Such assignments can result in confusion due to order of operations, as evaluation of the assignment may effect the outer expression in unexpected ways. | Disabled |
Statement with empty body | Reports if, while, for, and with statements whose bodies are empty. While occasionally useful, such statements are often the result of typos, and may cause confusion. | Warning |
Unnecessary 'block' statement | Reports unnecessary block statements. Block statements that are not used as the body of if, for, while, do, with, or try statements, or as the body of a function declaration are reported. Since JavaScript blocks do not introduce new scopes as is common in Java and other languages, free-standing block statements may be the result of code confusion, and may result in subtle bugs. | Disabled |
Use of 'caller' property | Reports uses of the caller property in a JavaScript function. Use of this property to access the stack frame of the calling method can be extremely confusing, and result in subtle bugs. | Warning |
Node.js
Inspection | Description | Default Severity |
---|---|---|
Unresolved Node.js APIs | Suggests configuring coding assistance for Node.js, e.g. 'require' and/or core modules ('path', 'http', 'fs', etc.). | Warning |
Unit testing
Inspection | Description | Default Severity |
---|---|---|
Highlight failure line in test code | This inspection highlights failed method calls or assertions in tests. | Warning |
Validity issues
Inspection | Description | Default Severity |
---|---|---|
'this' expression which references the global object | Reports this expressions occurring outside of object literals or constructor bodies. Such this expressions are legal JavaScript, and reference the top-level "global" JavaScript object, but are largely useless. | Warning |
Attempt to assign to const or readonly variable | Checks that constant or readonly variable is being reassigned. | Error |
Expression statement which is not assignment or call | Reports expression statements which are not assignments or calls. Such statements have no obvious semantics, and are normally the result of programmer error. | Weak warning |
Function with inconsistent returns | Reports functions which return a value in some circumstances and return without a value in others. While legal, such code almost certainly represents a programming error. | Disabled |
Octal integer | Reports deprecated octal integer literals prefixed with '0' and not '0o'. | Error |
Referencing 'arguments' outside of function | a | Error |
Reserved word used as name | Reports JavaScript reserved words being 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 |
String literal which breaks HTML parsing | Reports string literals which contain the sequence </. Such strings are legal JavaScript, but may result in incorrect parsing of any HTML the JavaScript is embedded in. | Disabled |
Async code and promises
Inspection | Description | Default Severity |
---|---|---|
Missing await for an async function call | Missing await for an async function call results in having a Promise where a value was expected. | Weak warning |
Possibly async function | Highlights usages of await in functions that were possibly intended to be async but are missing the async modifier. While it is possible to use await as an identifier, it is likely that it was intended to be used as an operator and the containing function should be made async. | Weak warning |
Redundant 'await' expression | Reports redundant await usages, such as await await, or awaiting a non-promise result. | Weak warning |
Result of method call returning a promise is ignored | Reports function calls that return a Promise that is not later used. These are usually unintended and indicate an error. | Weak warning |
Top-level 'await' expression | Highlights usages of top-level await -expressions. While the new 'top-level async' proposal is on its way, currently it is still illegal to use await outside async functions. | Disabled |
Data flow
Inspection | Description | Default Severity |
---|---|---|
Redundant local variable | Reports unnecessary local variables, which add nothing to the comprehensibility of a function. Variables caught include local variables which are immediately returned, local variables that are immediately assigned to another variable and then not used, and local variables which always have the same value as another local variable or parameter. | Warning |
Reuse of local variable | Reports where local variables are "reused", overwriting their values with new values unrelated to their original use. Such local variable reuse may be confusing, as the intended semantics of the local variable may vary with each use. It may also be prone to bugs, if code changes result in values that were thought to be overwritten actually being 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 | Suggests to make the constructor of an abstract class protected (because it is useless to have it public). | Weak warning |
Duplicate union or intersection type component | Checks union and intersection types for duplicates | Warning |
Equality operator may cause type coercion | Reports usages of equality operators which may cause unexpected type coercions. It is considered a good practice to use the type-safe equality operators === and !== instead of their regular counterparts == and !=.
| Disabled |
Explicit member types | Highlights type annotations that do not match the current code style for explicit types. | No highlighting, only fix |
Field is assigned only in the constructor and can be made readonly | If a private field is assigned only in the constructor, it can be made readonly. | Weak warning |
Generic type mismatch | Checks that a corresponding type argument is passed when a generic type is used in a function, interface or class declaration | Error |
Missing augmentation import | Checks that current file imports the augmentation module. | No highlighting, only fix |
Missing option in tsconfig.json | Checks that required options are enabled in tsconfig.json, e.g. when using React JSX in .tsx files, the TypeScript configuration file contains 'jsx: "react"'. | Warning |
Redundant type argument for a generic type | Checks type arguments for redundancy when a reference provides the type with default values | Weak warning |
Reference to a UMD global | Report the use of references to a UMD global if the current file is a module. | Weak warning |
Required TypeScript library is not included in tsconfig.json | Checks that the TypeScript library files required for the symbol are listed under the 'lib' compiler option in tsconfig.json. | Error |
Suspicious parameter assignment in constructor | Warns against a common mistake in TypeScript code, when a class field is declared as a constructor parameter, and then this parameter is assigned. | Warning |
Type mismatch in 'any' type context | Checks TypeScript called function parameters, return values, assigned expressions to be of correct type in any type context. | Weak warning |
Unresolved TypeScript function | Checks that TypeScript called functions are valid. | Weak warning |
Unresolved TypeScript variable | Checks that TypeScript referenced variables and fields are valid. | Weak warning |
Variable type is narrowed by a type guard | Highlights variable usages where variable type is narrowed by a type guard. Note that severity level doesn't affect this inspection. | Warning |
tsconfig.json validation | Validates consistency of 'paths', 'checkJs' and 'extends' in tsconfig.json files. | Warning |
Probable bugs
Inspection | Description | Default Severity |
---|---|---|
'for' loop where update or condition does not use loop variable | Reports for loops where the condition or update does not use the for loop variable. | Disabled |
Comparison of expressions having incompatible types | Checks that operands in comparisons have compatible types in JavaScript files. Operands of types without possible common values are reported. | Weak warning |
Comparison with NaN | Checks code for comparisons with NaN. Comparisons like expr == NaN or expr === NaN are always evaluated to false. | Warning |
Consecutive commas in array literal | Checks that array literal doesn't contain consecutive commas. Skipped element takes undefined value, but it could be done unintentionally, e.g. when commas are at the end of one line and at the beginning of the following. | Warning |
Constructor returns primitive value | Checks that function recognized as constructor does not return primitive values. When called with new, this value will be lost and object will be returned instead. To avoid warnings, you can explicitly specify function's return type with @return tag. | Disabled |
Division by zero | Reports division by zero or remainder by zero. | Disabled |
Infinite loop statement | Reports for, while, or do statements which can only exit by throwing an exception. While such statements may be correct, they are often a symptom of coding errors. | Warning |
Infinite recursion | Reports functions which must either recurse infinitely or throw an exception. Functions reported by this inspection can not return normally. | Warning |
Possibly incorrect target of indexed property access | Reports potentially invalid indexed property access such as Array[1]. The validation works in JavaScript, html, or jsp files. | Warning |
Potentially invalid constructor usage | Reports potentially invalid constructor function usages such as: using non constructor in new, using constructor's prototype and constructor call without new. Constructor function assumed to have upper case name (optional) or have explicit JSDoc @constructor tag. The validation works in JavaScript, html or jsp files. | Warning |
Potentially invalid reference to 'this' from closure | Checks for this to be the same in closure and in outer context. The validation works in JavaScript, html, or jsp files. | Warning |
Potentially invalid reference to 'this' of a class from closure | Warns against a common mistake of trying to reference a member of an ECMAScript class via this. qualifier in a nested function that is not a lambda. | Warning |
Result of object allocation ignored | Reports object allocation where the result of the object allocated is ignored. Such allocation expressions are legal JavaScript, but are usually either inadvertent, or evidence of a very odd object initialization strategy. | Disabled |
Suspicious '=+' assignment | Reports assignments in form 'a =+ b'. In most cases, assignments of form 'a =+ b' are typos, and the correct option is 'a += b'. | Warning |
Suspicious name combination | Reports assignments and function calls where the name of the variable to which a value is assigned or the function parameter does not seem to match the name of the value assigned to it. For example:
var
x = 0;
var
y = x;
or
var
x = 0, y = 0;
var
rc =
new
Rectangle(y, x, 20, 20);
The configuration pane allows to specify the names which should not be used together: the error is reported if the parameter name or assignment target name contains words from one group and the name of the assigned or passed variable contains words from a different group. | Warning |
Suspicious usage of 'bind' with arrow function | Warns if | Warning |
Typeof comparing with non-standard value | Reports when literal string in a comparing with typeof is not one of the standard types: undefined, object, boolean, number, string, function or symbol. | Warning |
Control flow issues
Inspection | Description | Default Severity |
---|---|---|
'for' loop may be replaced by 'while' loop | Reports for loops which contain neither initialization or update components, and can thus be replaced by simpler while statements. | Disabled |
'if' statement with identical branches | Reports if statements with identical then and else branches. Such statements are almost certainly programmer error. | Disabled |
'if' statement with too many branches | Reports if statements with too many branches. Such statements may be confusing, and are often the sign of inadequate levels of design abstraction. | Disabled |
Conditional expression with identical branches | Reports ternary conditional expressions with identical then and else branches. Such statements are almost certainly programmer error. | Disabled |
Constant conditional expression | Reports conditional expressions of the form true? result1: result2 or false? result1: result2. These expressions sometimes occur as the result of automatic refactorings, and may obviously be simplified. | Warning |
Duplicate condition in 'if' statement | Reports duplicate conditions in different branches of an if statement. While it may rarely be the desired semantics, duplicate conditions usually represent programmer oversight. | Disabled |
Loop statement that doesn't loop | Reports for, while and do statements whose bodies are guaranteed to execute at most once. Normally, this is an indication of a bug. | Warning |
Object is 'null' or 'undefined' | Reports errors caused by invoking a method, accessing a property or calling a function on an object that is undefined or null. | Warning |
Pointless statement or boolean expression | Reports pointless or pointlessly complicated boolean expressions or statements. | Warning |
Redundant 'if' statement | Reports if statements which can be simplified to single assignment or return statements. For example:
if
(foo())
{
return
true;
}
else
{
return
false;
}
(foo())
{
if
(foo())
{
return
true;
}
else
{
return
false;
}
true;
}
if
(foo())
{
return
true;
}
else
{
return
false;
}
{
if
(foo())
{
return
true;
}
else
{
return
false;
}
false;
}
can be simplified to
return
foo();
foo();
| Warning |
Redundant conditional expression | Reports conditional expressions of the form condition ?true:false or condition ?false:true. These expressions may be safely simplified to condition or ! condition, respectively. | Warning |
Tail recursion | Reports tail recursion, that is when a function calls itself as its last action before returning. 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 on different environments. | Disabled |
Unnecessary 'continue' statement | Reports unnecessary continue statements at the end of loops. These statements may be safely removed. | Warning |
Unnecessary 'return' statement | Reports unnecessary return statements. Unnecessary return statements are those which return no value and occur just before the function would have "fallen through" the bottom. These statements may be safely removed. | Warning |
Unnecessary label | Reports unused labels. | Warning |
Unnecessary label on 'break' statement | Reports labelled break statements whose labels may be removed without changing the flow of control. | Warning |
Unnecessary label on 'continue' statement | Reports labelled continue statements whose labels may be removed without changing the flow of control. | Warning |
Unreachable code | Reports code which can never be executed. Such code almost certainly represents a programming error | Warning |
Unsound type guard check | typeof x type guard can be unsound in one of the following two cases:
x instanceof A type guard can be unsound in one of the following two cases:
| Warning |
Try statement issues
Inspection | Description | Default Severity |
---|---|---|
'continue' or 'break' inside 'finally' block | Reports break or continue statements inside of finally blocks. While occasionally intended, such statements are very confusing, may mask exceptions thrown, and tremendously complicate debugging. | Warning |
'return' inside 'finally' block | Reports return statements inside of finally blocks. While occasionally intended, such return statements may mask exceptions thrown, and tremendously complicate debugging. | Warning |
'throw' inside 'finally' block | Reports throw statements inside of finally blocks. While occasionally intended, such throw statements may mask exceptions thrown, and tremendously complicate debugging. | Warning |
Empty 'catch' block | Reports empty catch blocks. Empty catch blocks are a sign that errors are simply being ignored, rather than properly handled. | Disabled |
Empty 'finally' block | Reports empty finally blocks. Empty finally blocks are usually the result of a coding error. | Disabled |
Empty 'try' block | Reports empty try blocks. Empty try blocks are usually the result of a coding error. | Disabled |
Exception used for local control-flow | Reports throw statements whose exceptions are always caught by containing try statements. Using throw statements as a "goto" to change the local flow of control is likely to be confusing. | Warning |
Unused 'catch' parameter | Reports catch parameters that are unused in their corresponding blocks. This inspection will not report catch parameters named "ignore" or "ignored". | Disabled |
Naming conventions
Inspection | Description | Default Severity |
---|---|---|
Class naming convention | Reports classes and functions annotated with JSDoc @constructor or @class tags whose names are either too short, too long, or do not follow the specified regular expression pattern. | Disabled |
Function naming convention | Reports functions whose names are either too short, too long, or do not follow the specified regular expression pattern. | Disabled |
Function parameter naming convention | Reports function parameters whose names are either too short, too long, or do not follow the specified regular expression pattern. | Disabled |
Identifiers with non-ASCII symbols | Reports names containing non-ASCII symbols. | Warning |
Local variable naming convention | Reports local variables whose names are either too short, too long, or do not follow the specified regular expression pattern. | Disabled |
Flow type checker
Inspection | Description | Default Severity |
---|---|---|
Code is not covered by Flow | Checks that JavaScript code is covered by the Flow type checker. To use this inspection, the Flow executable must be configured in Settings | Languages & Frameworks | JavaScript | Disabled |
Flow errors | Reports errors from Flow in Inspect code. | Disabled |
Flow flag is misplaced | Checks that the | Warning |
Missing .flowconfig | Checks that there’s a .flowconfig file in the project that covers a JavaScript file with the | Warning |
Function metrics
Inspection | Description | Default Severity |
---|---|---|
Function with more than three negations | Reports functions with three or more negation operations (! or != ). Such functions may be unnecessarily confusing. | Disabled |
Function with multiple loops | Reports functions containing multiple loop statements. | Disabled |
Function with multiple return points | Reports functions with multiple return points. Some coding standards warn against functions with multiple returns, as they may make functions more difficult to understand and maintain. | Disabled |
Function with too many parameters | Reports functions with too many parameters. Functions with too many parameters are often an indication of design weakness. | Disabled |
Overly complex function | Reports functions that have too high cyclomatic complexity. Cyclomatic complexity is basically a measurement of the number of branching points in a function. Functions with too high a cyclomatic complexity may be confusing and difficult to test. | Disabled |
Overly long function | Reports overly long functions. 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. | Disabled |
Overly nested function | Reports functions whose bodies are contain statements too deeply nested within other statements. Functions with too much statement nesting may be confusing, and are a good sign that refactoring may be necessary. | Disabled |
Code style issues
Inspection | Description | Default Severity |
---|---|---|
Braces around arrow function body can be removed | Reports arrow functions where the body contains exactly one statement and can be converted to concise syntax without braces. | No highlighting, only fix |
Chained equality | Reports chained equality comparisons (i.e. a==b==c ). Such comparisons are confusing. | Disabled |
Chained function call | Reports function calls whose target is another function call. | Disabled |
Constant on left side of comparison | Reports on comparison operations with constant values on their left-hand side. Some coding conventions specify that constants should be on the right-hand side of comparisons. | Disabled |
Constant on right side of comparison | Reports on comparison operations with constant values on their right-hand side. Some coding conventions specify that constants should be on the left-hand side of comparisons. | Disabled |
Nested function call | Reports function calls used as arguments to another function call. | Disabled |
Non-block statement body | Reports if, while, for, and with statements whose bodies are not block statements. While such statements are legal JavaScript, it is usually safer for downstream maintenance to use the code blocks for statement bodies. | Disabled |
Undefined property assignment | Reports assignments to undefined properties of explicitly type-annotated variables. | Weak warning |
Unnecessary parentheses | Reports parentheses when they are redundant. | No highlighting, only fix |
Unterminated statement | Reports statements that may be erroneously not terminated by a semicolon or a newline. | Disabled |
Variable declarations are not at the scope start | Checks that local variables declared with var are at the top of a function scope. | Disabled |
General
Inspection | Description | Default Severity |
---|---|---|
#-private fields access without explicit 'this.' | Checks for #x -like access to private fields. Such syntax was allowed in the early versions of the specification draft, but is no longer a valid syntax. In the most recent versions of the draft, only the syntax with explicit 'this.' qualifier is valid. | Error |
@private and @protected members accessibility | Checks that JavaScript members marked with @private and @protected tags are visible in current context. | Warning |
Closure compiler syntax | Checks code for warnings implied by Google Closure Compiler annotations. This includes correct usage of @abstract, @interface and @implements tags. | Warning |
Deprecated JavaScript symbol | Checks for using deprecated functions and variables. The validation works in JavaScript, html, or jsp files. | Weak warning |
Destructuring properties with the same key can be merged | Reports multiple destructuring properties with identical keys that can be merged | Weak warning |
Duplicate JavaScript declaration | Checks that declarations are declared once in current scope. The validation works in JavaScript, TypeScript, html or jsp files. | Warning |
File references validation | Reports unresolved file references in JavaScript files, including CommonJS and AMD modules references. | Warning |
Implicitly declared global JavaScript variable | Checks that variables are declared explicitly with a var statement. The validation works in JavaScript, html or jsp files. | Weak warning |
Import can be shortened | Reports ES6 imports whose from part can be shortened by importing the parent directory. | Warning |
JQuery usage efficiency | Checks that jQuery selectors are used in an efficient way. It warns about duplicated selectors which could be cached and optionally about attribute and pseudo-selectors usage. | Warning |
JSDoc comment matches function signature | Checks that parameters defined within JSDoc comments match the function's actual parameters, i.e. have the same names and quantity. | Warning |
JavaScript general errors | This inspection reports basic syntax issues and inconsistencies with language specification. Examples are invalid usages of keywords, incompatible numeric format usage or multiple parameters to getters/setters. | Error |
Method can be static | Checks for ActionScript, JavaScript and TypeScript methods which may safely be made static. A method may be static if it does not reference any of its class' non static methods and non static fields and is not overridden in a sub class. | Warning |
Mismatched query and update of collection | Reports collection 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. | Warning |
Non-strict mode used | Checks that JavaScript files are in strict mode. | Disabled |
Primitive type object wrapper used | Checks for improper usage of wrappers for primitive types. Also, warning will be produced when property of primitive type is modified, as assigned value will be lost. | Warning |
Property can be replaced with shorthand | Highlights and provides fixes to convert object properties to ES6 shorthand style. | No highlighting, only fix |
React JSX syntax | Highlights usages of React JSX tags in JavaScript code. | Disabled |
Redundant nesting in template literal | Reports nested instances of strings and template literals. Such instances can be inlined into the containing template string. | Weak warning |
Referencing mutable variable from closure | Checks for accessing mutable variables in nested functions. The validation works in JavaScript, html, or jsp files. | Warning |
Signature mismatch | Checks JavaScript called function arguments, return values, assigned expressions to be of correct type. The validation works in JavaScript, html or jsp files. | Weak warning |
Syntax errors and unresolved references in JSDoc | Validates syntax and references in JavaScript/ActionScript documentation comments (JSDoc/ASDoc). | Warning |
There is no locally stored library for the HTTP link. | Checks that URL of an external JavaScript library is associated with a locally stored file used for code completion and navigation. | Warning |
Type mismatch | Checks that called function parameters, return values and assigned expressions are of the correct type. The validation works in JavaScript, html or jsp files. | Weak warning |
Unfiltered for..in loop | Checks for unfiltered for-in loops. The use of this construct results in processing inherited or unexpected properties. You need to filter own properties with hasOwnProperty() method. The validation works in JavaScript, html or jsp files. | Warning |
Unnecessary semicolon | Reports unneeded semicolons. The validation works in JavaScript, html or jsp files. | Warning |
Unneeded last comma in array literal | Reports when a trailing comma is used in array literals. | Warning |
Unneeded last comma in object literal | Reports when a trailing comma is used in object literals. | Warning |
Unresolved Ext JS xtype | Checks that Ext JS xtype references have corresponding class. | Warning |
Unresolved JavaScript function | Checks that called functions are valid. The validation works in JavaScript, html or jsp files. | Weak warning |
Unresolved JavaScript variable | Checks that referenced variables and fields are valid. The validation works in JavaScript, html or jsp files. | Weak warning |
Unresolved React component | Reports the use of unresolved React components. As a fix, 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. | Weak warning |
Use of possibly unassigned property in a static initializer | Reports when a class member initializer references another non-hoisted class member that could be not initialized yet. | Warning |
Variable declaration can be merged with the first assignment to the variable | This inspection suggests to move variables closer to their usages joining with the initializer expression If a variable is declared without an initializer, and it is used in the code much further or in a single nested scope, such variable may be joined with the first assignment as an initializer. | No highlighting, only fix |
Webpack configuration validation | Validates options in the webpack configuration file (which name should start with `webpack`, e.g. `webpack.config.js`) against webpack Options Schema. | Warning |
Switch statement issues
Inspection | Description | Default Severity |
---|---|---|
'default' not last case in 'switch' | Reports switch statements where the default case comes before some other case. | Disabled |
'switch' statement has missing branches | Reports switch statements on a variable of enum or union type when the statement covers not all the value options from the type. | No highlighting, only fix |
'switch' statement has no 'default' branch | Reports switch statements without default clause in case when not all possible values are enumerated. | No highlighting, only fix |
'switch' statement is redundant and can be replaced | Reports unnecessary switch statements. Warns on switch statement with an empty body, only one case branch, or only single default branch. | No highlighting, only fix |
Duplicate case label | Reports duplicated case labels on switch statements. Such switch statements are normally an indication of programmer error. | Warning |
Fallthrough in 'switch' statement | Reports cases where control can proceed from one branch of a switch statement to the next. Such "fall-through" is often a result of programmer error, for example, a missing break or return. | Warning |
Nested 'switch' statement | Reports switch statements which are nested in other switch statements. Such nested switch statements can be very confusing, particularly if proper indenting is not followed. | Disabled |
Text label in 'switch' statement | Reports labelled statements inside of switch statements. While occasionally intended, this construction is often the result of a typo.
switch
(x)
{
case
1:
case2: //typo!
case
3:
break
;
}
(x)
{
switch
(x)
{
case
1:
case2: //typo!
case
3:
break
;
}
1:
case2: //typo!
switch
(x)
{
case
1:
case2: //typo!
case
3:
break
;
}
3:
switch
(x)
{
case
1:
case2: //typo!
case
3:
break
;
}
;
}
| Disabled |
Unreachable 'case' branch of a 'switch' statement | Reports case branches of a switch statement that are unreachable in current context | Warning |
Variable is declared and being used in different 'case' clauses | Reports variables that are declared in one case clause of a switch statement, and are used in a different case clause of the same statement. For block-scope variables, this results in a ReferenceError being thrown. For var -variables, it signifies a potential error. This inspection can be disabled for var -variables if you use this pattern intentionally. | Warning |
ECMAScript 6 migration aids
Inspection | Description | Default Severity |
---|---|---|
'for..in' is used instead of 'for..of' | Converts | No highlighting, only fix |
'let' used where it could be a 'const' | Reports | No highlighting, only fix |
'module.exports' is used instead of 'export' | Reports when | No highlighting, only fix |
'require()' is used instead of 'import' | Reports when | No highlighting, only fix |
'var' used instead of 'let' or 'const' | Reports | Weak warning |
Function expression is used instead of arrow function | Helps to replace function expressions with arrow functions. | No highlighting, only fix |
Indexed 'for' loop could be replaced with 'for..of' | Converts indexed | No highlighting, only fix |
String concatenation is used instead of string template | This inspection highlights string concatenations that can be replaced with a template string. | No highlighting, only fix |
Bitwise operation issues
Inspection | Description | Default Severity |
---|---|---|
Bitwise operator usage | Reports suspicious usages of bitwise AND (" & ") and OR (" | ") operators. Usually it is a common typo and user expect a result according to the boolean operations AND (" && ") and OR (" || "). | Warning |
Incompatible bitwise mask operation | Reports bitwise mask expressions which are guaranteed to evaluate to true or false. Expressions checked are of the form (var & constant1) == constant2 or (var | constant1) == constant2, where constant1 and constant2 are incompatible bitmask constants. | Warning |
Pointless bitwise expression | Reports pointless bitwise expressions. Such expressions include and ing with zero, or ing by zero, and shift by zero. Such expressions may be the result of automated refactorings not completely followed through to completion, and in any case are unlikely to be what the developer intended to do. | Disabled |
Shift operation by inappropriate constant | Reports shift operations where the value shifted by is constant and outside of the reasonable range. Integer shift operations outside of the range 0..31 are reported. Shifting by negative or overly large values is almost certainly a coding error. | Warning |
Unused symbols
Inspection | Description | Default Severity |
---|---|---|
Unused assignment | Checks JavaScript for unused assignments. The validation works in JavaScript, ActionScript, HTML and JSP files. | Warning |
Unused global symbol | Reports unused globally accessible public functions, variables, classes, and properties. The validation works in JavaScript, ActionScript, HTML and JSP files. | Warning |
Unused local symbol | Reports unused locally accessible parameters, local variables, functions, classes and private member declarations. The validation works in JavaScript, ActionScript, HTML and JSP files. | Warning |
Potentially undesirable code constructs
Inspection | Description | Default Severity |
---|---|---|
'break' statement | Reports break statements. break statements that end case blocks are not reported. | Disabled |
'break' statement with label | Reports labelled break statements. | Disabled |
'continue' statement | Reports continue statements. | Disabled |
'continue' statement with label | Reports labelled continue statements. | Disabled |
'debugger' statement | Reports debugger statements, used for interaction with Javascript debuggers. Such statements should probably not be found in production code. | Disabled |
'void' expression | Reports void expressions. Since void behaves completely differently in JavaScript and Java, these expressions maybe confusing. | Disabled |
'with' statement | Reports with statements. with statements result in potentially confusing implicit bindings, and may behave strangely in setting new variables. | Warning |
Anonymous function | Reports anonymous functions. An explicit name of a function expression may be helpful for debugging. Function expressions without names are not reported if they have a name property specified in the ECMAScript 6 standard. For example, | Disabled |
Comma expression | Reports comma expressions. Comma expressions are often a sign of overly clever code, and may lead to subtle bugs. Comma expressions in the initializer or update section of a for loop are ignored by this inspection. | Warning |
Conditional expression | Reports ternary conditional expressions. Some coding standards prohibit such expressions, in favor of explicit if statements. | Disabled |
Labeled statement | Reports labeled statements. | Disabled |