Code Inspections in JavaScript and TypeScript
This topic lists all PhpStorm code inspections available in JavaScript and TypeScript.
You can toggle specific inspections or change their severity level on the Editor | Inspections page of the IDE settings Ctrl+Alt+S.
DOM issues
Inspection | Description | Default Severity |
---|---|---|
Reports a method call to | ||
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:
| ||
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. | ||
Reports a JavaScript access to DOM nodes as text using the |
Imports and dependencies
Inspection | Description | Default Severity |
---|---|---|
Reports a dependency from package.json that is not installed or doesn't match the specified version range. | Warning | |
Reports a usage of a JSX construction without importing React namespace. Having React namespace in the file scope ensures proper code compilation. The inspection is disabled in projects with React 17+ because these versions no longer require React namespace. | Weak warning | |
Reports a module from a require() calls, works only in the files from the scope of Node.js Core JavaScript library. | Weak warning | |
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. | No highlighting, only fix | |
Reports an unresolved name or binding in an | Weak warning | |
Reports a redundant | Warning | |
Suggests to upgrade your package.json dependencies to the latest versions, ignoring specified versions. | No highlighting, only fix |
Code quality tools
Inspection | Description | Default Severity |
---|---|---|
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. | ||
Reports a problem detected by the JSHint linter. | ||
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. | ||
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. |
Assignment issues
Inspection | Description | Default Severity |
---|---|---|
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; | ||
Reports an assignment to a variable declared as a | ||
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. | ||
Reports an assignment that is used as the condition of an | Warning | |
Reports an assignment expression nested inside another expression, for example, | ||
Reports an assignment expression where the result of the assignment is used in the containing expression. Such assignments often indicate coding errors, for example, | ||
Reports an assignment in the form | Warning |
Potentially confusing code constructs
Inspection | Description | Default Severity |
---|---|---|
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. | ||
Reports a suspicious combination of | ||
Reports a call of the | ||
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. | ||
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. | ||
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: | ||
Reports a ternary conditional expression within another ternary condition. Such nested conditionals may be extremely confusing, and best replaced by more explicit conditional logic. | ||
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. | ||
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. | ||
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. | ||
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 | |
Reports an increment ( | ||
Reports an | Warning | |
Reports a block statement that is not used as the body of | ||
Reports a usage of the | Warning |
Node.js
Inspection | Description | Default Severity |
---|---|---|
Suggests configuring coding assistance for Node.js, for example, | Warning |
Unit testing
Inspection | Description | Default Severity |
---|---|---|
Reports a failed method call or an assertion in a test. | Warning |
Async code and promises
Inspection | Description | Default Severity |
---|---|---|
Reports a usage of | Weak warning | |
Reports an
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.
| Weak warning | |
Reports a redundant usage of await before promises when applicable (in return statements, and with Promise.resolve/reject ). Removing await in such contexts causes two problems.
| Weak warning | |
Reports a function call that returns a | Weak warning | |
Reports a usage of a top-level |
Validity issues
Inspection | Description | Default Severity |
---|---|---|
Reports a | Warning | |
Reports reassigning a value to a constant or a readonly variable. | Error | |
Reports an expression statement that is neither an assignment nor a call. Such statements usually indicate an error. | Weak warning | |
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;
}
| ||
Reports a deprecated octal integer literal prefixed with | Error | |
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 | |
Reports a string literal that contains a |
Data flow
Inspection | Description | Default Severity |
---|---|---|
Reports am unnecessary local variable that does not make a function more comprehensible:
| Warning | |
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. |
TypeScript
Inspection | Description | Default Severity |
---|---|---|
Reports a public constructor of an abstract class and suggests making it protected (because it is useless to have it public). | Weak warning | |
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 | |
Reports a duplicate type inside a union or intersection. | Warning | |
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. | No highlighting, only fix | |
Reports a private field that can be made readonly (for example, if the field is assigned only in the constructor). | Weak warning | |
Reports inconsistency of a checkJs property requires allowJs . The extends property should be a valid file reference. | Warning | |
Reports an invalid type argument in a function, interface, or class declaration. | Error | |
Reports a usage from augmentation module without an explicit import. | No highlighting, only fix | |
Reports a TypeScript library file that is required for a symbol but is not listed under the | Error | |
Reports a usage that requires an explicit option in | Warning | |
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 | |
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 | |
Reports a usages of a 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 | |
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
declare var test: any;
test.hasOwnProperty(true); //reports 'true'
| Weak warning | |
Reports an unresolved reference to a JSX (React) component. Suggests adding an import statement if the referenced component is defined in the project or its dependencies or creating a new component with the specified name. The template for a new component can be modified in Editor | File and Code Templates. | Weak warning | |
Reports a call of a function that is not resolved. | Weak warning | |
Reports an unresolved reference to a variable or field. | Weak warning |
Probable bugs
Inspection | Description | Default Severity |
---|---|---|
'for' loop where update or condition does not use loop variable | Reports a | |
Reports a comparison of a | Warning | |
Reports a comparison with operands of incompatible types or an operand with a type without possible common values. | Weak warning | |
Reports a comparison with NaN. Comparisons like | Warning | |
Reports a consecutive comma in an array literal. The skipped element accepts the | Warning | |
Reports a constructor function that returns a primitive value. When called with | ||
Reports division by zero or a remainder by zero. | ||
Reports a usage of an equality operator that may cause unexpected type coercions. Suggests replacing
| Warning | |
Reports a | Warning | |
Reports a function which must either recurse infinitely or throw an exception. Such functions may not return normally. | Warning | |
Reports a potentially invalid indexed property access, for example, | Warning | |
Reports a usage of a potentially invalid constructor function, for example: a function that is not a constructor after | Warning | |
Reports a
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 | |
Potentially invalid reference to 'this' of a class from closure | Reports an attempt to reference a member of an ECMAScript class via the 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 |
Reports object allocation where the result of the allocated object is ignored, for example, | ||
Reports an assignment in the form | Warning | |
Reports this , a bind call will have no effect on them. See here for details. | Warning | |
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);
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 | |
Reports a return value of a function that doesn't return anything. Calling of such functions always produces an
let a = console.log('foo');
The following usages are ignored:
| Warning |
Control flow issues
Inspection | Description | Default Severity |
---|---|---|
Reports a
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. | ||
Reports an | ||
Reports an | ||
Reports a ternary conditional expression with identical | ||
Reports a conditional expression in the format | Warning | |
Reports duplicate conditions in different branches of an
if (a) {
...
} else if (a) {
...
}
| ||
Reports a | Warning | |
Reports an error caused by invoking a method, accessing a property, or calling a function on an object that is | Warning | |
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 | |
Reports an
if(foo())
{
return true;
}
else
{
return false;
}
After applying the quick-fix the code looks as follows: return foo(); | Warning | |
Reports a conditional expression of the form
condition ? true : false
condition ? false : true
These expressions may be safely converted to
condition
!condition
| Warning | |
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. | ||
Reports an unnecessary | Warning | |
Reports an unnecessary | Warning | |
Reports an unused label. | Warning | |
Reports a labeled | Warning | |
Reports a labeled | Warning | |
Reports code that can never be executed, which almost certainly indicates an error | Warning | |
Reports a
x instanceof A type guard can be unsound in one of the following two cases:
| Warning |
Try statement issues
Inspection | Description | Default Severity |
---|---|---|
Reports a | Warning | |
Reports a | Warning | |
Reports s | Warning | |
Reports an empty catch block mutes the inspection. | ||
Reports an empty | ||
Reports an empty | ||
Reports a | Warning | |
Reports a catch blocks with comments. |
Naming conventions
Inspection | Description | Default Severity |
---|---|---|
Reports a class or a function that is annotated with a JSDoc java.util.regex format for regular expressions. | ||
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 standardjava.util.regex format for regular expressions. | ||
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 standardjava.util.regex format regular expressions. | ||
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 | |
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 standardjava.util.regex format regular expressions. |
Flow type checker
Inspection | Description | Default Severity |
---|---|---|
Reports a JavaScript code fragment that is not covered by the Flow type checker. To use this inspection, configure the Flow executable in Settings | Languages & Frameworks | JavaScript. | ||
Reports errors from Flow. | ||
Reports a | Warning | |
Reports a JavaScript file with a | Warning |
Function metrics
Inspection | Description | Default Severity |
---|---|---|
Reports a function with three or more negation operations ( | ||
Reports a function with multiple loop statements. | ||
Reports a function with multiple return points. Such functions are hard to understand and maintain. | ||
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. | ||
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. | ||
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. | ||
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. |
Code style issues
Inspection | Description | Default Severity |
---|---|---|
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. | ||
Reports a chained equality comparison (i.e. | ||
Reports a function call whose target is another function call, for example, | ||
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. | ||
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. | ||
Reports a function call that is used as an argument in another function call, for example, | ||
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; | No highlighting, only fix | |
Reports a | ||
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 | |
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) | No highlighting, only fix | |
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. |
ES2015 migration aids
Inspection | Description | Default Severity |
---|---|---|
Reports a usage of a 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. | No highlighting, only fix | |
Reports a | No highlighting, only fix | |
Reports a 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. | No highlighting, only fix | |
Reports a 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. | No highlighting, only fix | |
Reports a 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 | |
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) | No highlighting, only fix | |
Reports an indexed for..of loops are introduced in ECMAScript 6 and iterate over iterable objects. | No highlighting, only fix | |
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}.` | No highlighting, only fix |
General
Inspection | Description | Default Severity |
---|---|---|
Reports a usage of a deprecated function variable. | Weak warning | |
Reports multiple destructuring properties with identical keys. Suggests merging the properties. | Weak warning | |
Reports multiple declarations in a scope. | Warning | |
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 | |
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 | |
Reports an ES6 import whose | Warning | |
Reports a reference to a JavaScript member that is marked with s | Warning | |
Reports warnings implied by Google Closure Compiler annotations including correct use of | Warning | |
Reports a duplicated jQuery selector that can be cached or a usage of an attribute or a pseudo-selector (optional). | Warning | |
Reports a class method that can be safely made private methods. | Warning | |
Reports mismatch between the names and the number of parameters within a JSDoc comment and the actual parameters of a function. | Warning | |
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 | |
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 | |
Reports a JavaScript file that is not in the | ||
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 | |
Reports an object property that can be converted to ES6 shorthand style and provides a quick-fix to do it. var obj = {foo:foo} After applying the quick-fix the code looks as follows: var obj = {foo} | No highlighting, only fix | |
Reports a usage of a React JSX tag in JavaScript code. | ||
Reports nested instances of a string or a template literal. Suggests inlining the nested instances into the containing template string. Example:`Hello, ${`Brave ${"New"}`} ${"World"}!` After applying the quick-fix the code looks as follows: `Hello, Brave New World!` | Weak warning | |
Reports access to outer mutable variables from functions. Example:
for (var i = 1; i <= 3; i++) {
setTimeout(function() {
console.log(i); // bad
}, 0);
}
| Warning | |
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 | |
Reports a syntax discrepancy in a documentation comment. | Warning | |
Reports incorrect type of:
| Weak warning | |
Reports unfiltered 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]);
}
}
| ||
Reports an unneeded semicolon. | Warning | |
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 | |
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 | |
Reports an Ext JS | Warning | |
Reports an unresolved function in a call. TypeScript code is ignored. | Weak warning | |
Reports an unresolved referenced variable or field. TypeScript code is ignored. | Weak warning | |
Reports an unresolved file reference in a JavaScript file, including CommonJS and AMD modules references. | Warning | |
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 | |
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. | No highlighting, only fix |
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 |
Switch statement issues
Inspection | Description | Default Severity |
---|---|---|
Reports a | ||
Reports a | No highlighting, only fix | |
Reports a | No highlighting, only fix | |
Reports a | No highlighting, only fix | |
Reports a duplicated | Warning | |
Reports a | Warning | |
Reports a | ||
Reports a labeled statement inside a
switch(x)
{
case 1:
case2: //typo!
case 3:
break;
}
| ||
Reports an unreachable
/**
* @param {('foo' | 'bar')} p
*/
function foo(p) {
switch (p) {
case 'foo': break;
case 'bar': break;
case 'baz': break; // unreachable
}
}
| Warning | |
Variable is declared and being used in different 'case' clauses | Reports a variable that is declared in one var variables if this pattern is used intentionally. | Warning |
Bitwise operation issues
Inspection | Description | Default Severity |
---|---|---|
Reports an expression that includes | ||
Reports a suspicious usage of a bitwise AND (" | Warning | |
Reports a bitwise mask expression which for sure evaluates to
// Incompatible mask: as the last byte in mask is zero,
// something like 0x1200 would be possible, but not 0x1234
if ((mask & 0xFF00) == 0x1234) {...}
| Warning | |
Reports a shift operation where the second operand is a constant outside the reasonable range, for example, an integer shift operation outside the range | Warning |
Unused symbols
Inspection | Description | Default Severity |
---|---|---|
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:
| Warning | |
Reports an unused globally accessible public function, variable, class, or property. | Warning | |
Reports an unused locally accessible parameter, local variable, function, class, or private member declaration. | Warning |
Potentially undesirable code constructs
Inspection | Description | Default Severity |
---|---|---|
Reports a | ||
Reports a labeled | ||
Reports a | ||
Reports a labeled | ||
Reports a | ||
Reports a | ||
Reports a | Warning | |
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 | ||
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 | Warning | |
Reports a ternary conditional expression. Some coding standards prohibit such expressions in favor of explicit | ||
Reports a labeled statement. |