198 Rules

Offering a set of powerful rules, SonarJS is all you need to find bugs, vulnerabilities, and code smells in your JavaScript code. With SonarJS, monitoring your code quality is no longer a daunting task.



Code Smell

Bug Detection Rules

Rule ID Name Sonar way Tags In Action
S2189 Loops should not be infinitecert~279 issues
S3796 Callbacks of array methods should have return statements~81 issues
S3827 Non-existent variables should not be referenced~16,859 issues
S3828 "yield" expressions should not be used outside generatorses2015~6 issues
S3854 "super()" should be invoked appropriately~10 issues
S2549 The "changed" property should not be manipulated directlybackbone
S3785 "in" should not be used with primitive types~177 issues
S3812 Results of "in" and "instanceof" should be negated rather than operands~65 issues
S3834 "Symbol" should not be used as a constructores2015~1 issue
S930 Function calls should not pass extra argumentscert, cwe, misra~4,423 issues
BoundOrA. "eval" and "arguments" should not be bound or assigned~31 issues
S2201 Return values from functions without side effects should not be ignoredcert, misra~584 issues
S1862 Related "if/else if" statements and "cases" in a "switch" should not have the same conditioncert, pitfall, unused~440 issues
S2137 Special identifiers should not be bound or assignedpitfall~914 issues
Unreacha. Jump statements should not be followed by other statementscert, cwe, misra, unused~4,327 issues
S1656 Variables should not be self-assignedcert~504 issues
S905 Non-empty statements should change control flow or have at least one side-effectcwe, misra, unused~1,807 issues
S1764 Identical expressions should not be used on both sides of a binary operatorcert~2,510 issues
S4043 Array-mutating methods should not be used misleadingly~10 issues
S4143 Collection elements should not be replaced unconditionallysuspicious~13 issues
S3981 Collection sizes and array length comparisons should make sense~5 issues
FailedUn. Failed unit tests should be fixed
BitwiseO. Bitwise operators should not be used in boolean contexts~62,546 issues
Construc. Objects should not be created to be dropped immediately without being used~58 issues
Duplicat. Function argument names should be unique~4 issues
Duplicat. Property names should not be duplicated within a class or object literalpitfall~1,142 issues
ForIn "" loops should filter properties before acting on them~7,603 issues
S1143 Jump statements should not occur in "finally" blockscert, cwe, error-handling~471 issues
S1145 Useless "if(true) {...}" and "if(false){...}" blocks should be removedcwe, misra~1 issue
S1154 Results of operations on strings should not be ignoredcert~1 issue
S1697 Short-circuit logic should be used to prevent null pointer dereferences in conditionals
S2123 Values should not be uselessly incrementedunused~1 issue
S2251 A "for" loop update clause should move the counter in the right directioncert~22 issues
S2259 Properties of variables with "null" or "undefined" values should not be accessedcert, cwe~6,169 issues
S2424 Built-in objects should not be overriddenconfusing~74 issues
S2432 Setters should not return values~77 issues
S2550 "defaults" should be a function when objects or arrays are usedbackbone
S2583 Conditionally executed blocks should be reachablecert, cwe, misra, pitfall, unused~8,794 issues
S2688 "NaN" should not be used in comparisonscert~51 issues
S2757 Non-existent operators '=+', '=-' and '=!' should not be used~3 issues
S2769 Selection results should be tested with "length"jquery~5 issues
S2873 Calls should not be made to non-callable values~8,279 issues
S2999 "new" operators should be used with functions~24 issues
S3403 Strict equality operators should not be used with dissimilar types~1,534 issues
S3500 Attempts should not be made to update "const" variableses2015~11 issues
S3531 Generators should "yield" somethingapi-design, es2015~50 issues
S3616 Comma and logical OR operators should not be used in switch cases~5 issues
S3699 The output of functions that don't return anything should not be used~704 issues
S3759 Non-existent properties should not be read~3,798 issues
S3786 Template literal placeholder syntax should not be used in regular strings~25 issues
S3799 Destructuring patterns should not be empty~2 issues
S3923 All branches in a conditional structure should not have exactly the same implementation~363 issues
S3984 Errors should not be created without being thrown
Function. Function declarations should not be made within blockscross-browser, user-experience~519 issues
NamedFun. Named function expressions should not be usedcross-browser, user-experience~1,064 issues
S2427 The base should be provided to "parseInt"user-experience
S2508 The names of model properties should not contain spacesbackbone
S3001 "delete" should be used only with object properties~87 issues
Trailing. Trailing commas should not be usedcross-browser~37 issues
WithStat. "with" statements should not be used~337 issues

Vulnerability Detection Rules

Rule ID Name Sonar way Tags In Action
S2817 Web SQL databases should not be usedhtml5, owasp-a6, owasp-a9
S2819 Cross-document messaging domains should be carefully restrictedhtml5, owasp-a3~165 issues
S3271 Local storage should not be usedowasp-a6
Eval Code should not be dynamically injected and executedcwe, owasp-a3~2,729 issues
S2611 Untrusted content should not be includedcwe, sans-top25-risky~11 issues
S3523 Function constructors should not be usedclumsy~2,490 issues
S2228 Console logging should not be usedowasp-a6, user-experience~9,111 issues
Debugger. Debugger statements should not be usedcwe, user-experience~135 issues
S1442 "alert(...)" should not be usedcwe, user-experience~4,985 issues

Code Smell Detection Rules

Rule ID Name Sonar way Tags In Action
NonEmpty. Switch cases should end with an unconditional "break" statementcert, cwe, misra, suspicious~3,429 issues
FutureRe. "future reserved words" should not be used as identifierslock-in, pitfall~72 issues
OctalNum. Octal values should not be usedcert, misra, pitfall~890 issues
S1219 "switch" statements should not contain non-case labelsmisra, suspicious~109 issues
S1451 Track lack of copyright and license headers~61 issues
S2703 Variables should be declared explicitlypitfall~17,097 issues
S3509 Default parameters should not cause side effectses2015, pitfall
S3516 Function returns should not be invariant~218 issues
Variable. Variables should be declared before they are usedpitfall~13,485 issues
Variable. Variables should not be shadowedcert, misra, suspicious~1,501 issues
S3972 Conditionals should start on new linessuspicious~179 issues
S3973 Conditionally executed code should be denoted by either indentation or curly bracesconfusing, suspicious~121 issues
SwitchWi. "switch" statements should end with "default" clausescert, cwe, misra~5,614 issues
ElseIfWi. "if ... else if" constructs should end with "else" clausescert, misra~900 issues
S888 Equality operators should not be used in "for" loop termination conditionscert, cwe, misra, suspicious~26 issues
Conditio. Internet Explorer's conditional comments should not be usedcross-browser~15 issues
CurlyBra. Control structures should use curly bracescert, misra, pitfall~7,750 issues
Function. Functions should not be too complexbrain-overload~18,570 issues
NestedIf. Control flow statements "if", "for", "while", "switch" and "try" should not be nested too deeplybrain-overload~35,597 issues
S1067 Expressions should not be too complexbrain-overload~17,367 issues
S1186 Functions should not be emptysuspicious~24,245 issues
S1994 "for" loop increment clauses should modify the loops' countersconfusing~330 issues
S2208 Wildcard imports should not be usedes2015, pitfall~1 issue
S2310 Loop counters should not be assigned to from within the loop bodypitfall~2,490 issues
S3353 Unchanged variables should be marked "const"es2015~7,758 issues
S3504 Variables should be declared with "let" or "const"bad-practice, es2015~3 issues
S3525 Class methods should be used instead of "prototype" assignmentses2015
S3735 "void" should not be usedconfusing~6,369 issues
S3776 Cognitive Complexity of functions should not be too highbrain-overload~20,808 issues
StrictMo. "strict" mode should be used with cautioncross-browser, user-experience~1,117 issues
S2589 Boolean expressions should not be gratuitouscert, cwe, misra, redundant~2,001 issues
S2681 Multiline blocks should be enclosed in curly bracescert, cwe~125 issues
Assignme. Assignments should not be made from within sub-expressionscert, cwe, misra, suspicious~14,135 issues
S1854 Dead stores should be removedcert, cwe, unused~67,713 issues
S1751 Jump statements should not be used unconditionallycert, misra, unused~303 issues
UnusedFu. Unused function parameters should be removedcert, misra, unused~46,554 issues
S4144 Functions should not have identical implementationsconfusing, duplicate, suspicious~157 issues
Duplicat. Source files should not have any duplicated blockspitfall~21,069 issues
Insuffic. Branches should have sufficient coverage by testsbad-practice~69 issues
Insuffic. Source files should have a sufficient density of comment linesconvention~61 issues
Insuffic. Lines should have sufficient coverage by testsbad-practice~3,292 issues
SkippedU. Skipped unit tests should be either removed or fixedpitfall
Collapsi. Collapsible "if" statements should be mergedclumsy~6,280 issues
Commente. Sections of code should not be "commented out"misra, unused~23,105 issues
Conditio. The ternary operator should not be usedbrain-overload~23 issues
EmptyBlo. Nested blocks of code should not be left emptysuspicious~9,049 issues
EqEqEq "===" and "!==" should be used instead of "==" and "!="suspicious~6,315 issues
Excessiv. Functions should not have too many parametersbrain-overload~1,890 issues
Function. Functions should not be defined inside loopssuspicious~6,291 issues
LabelPla. Only "while", "do" and "for" statements should be labelledpitfall~1 issue
LineLeng. Lines should not be too longconvention~2,739 issues
OneState. Statements should be on separate linesstyle~147,099 issues
Parenthe. Redundant pairs of parentheses should be removedconfusing~11,325 issues
ParsingE. JavaScript parser failuresuspicious
S104 Files should not have too many linesbrain-overload~167 issues
S1119 Labels should not be usedconfusing~1,935 issues
S1134 Track uses of "FIXME" tagscwe~1,079 issues
S138 Functions should not have too many linesbrain-overload~1,559 issues
S1788 Function parameters with default values should be lastes2015~348 issues
S1871 Two branches in a conditional structure should not have exactly the same implementationdesign, suspicious~6,952 issues
S2234 Parameters should be passed in the correct order~144 issues
S2376 Property getters and setters should come in pairspitfall~1,365 issues
S2392 Variables should be defined in the blocks where they are usedpitfall
S2685 "arguments.caller" and "arguments.callee" should not be usedobsolete~290 issues
S2692 "indexOf" checks should not be for positive numberssuspicious~650 issues
S2714 Element type selectors should not be used with class selectorsjquery, performance, user-experience
S2715 "find" should be used to select the children of an element known by idjquery, performance, user-experience~1 issue
S2716 Universal selectors should not be usedjquery, performance, user-experience
S2762 Selections should be storedjquery, performance, user-experience~2 issues
S2770 Deprecated jQuery methods should not be usedjquery, obsolete
S2814 Variables and functions should not be redeclaredconfusing~63,204 issues
S2870 "delete" should not be used on arrays~167 issues
S2898 "[type=...]" should be used to select elements by typejquery, performance
S3003 Comparison operators should not be used with strings~24 issues
S3358 Ternary operators should not be nestedconfusing~16,358 issues
S3513 "arguments" should not be accessed directlyapi-design, es2015
S3579 Array indexes should be numericbad-practice~495 issues
S3686 Functions should not be called both with and without "new"~808 issues
S3757 Arithmetic operations should not result in "NaN"~455 issues
S3758 Values not convertible to numbers should not be used in numeric comparisons~454 issues
S3760 Arithmetic operators should only have numbers as operandsconfusing
S3782 Arguments to built-in functions should match documented types~338 issues
S3798 Variables and functions should not be declared in the global scope~119 issues
S3800 Functions should always return the same typeconfusing~2,300 issues
S3801 Functions should use "return" consistentlyapi-design, confusing~1,479 issues
S4030 Collection and array contents should be usedsuspicious, unused~145 issues
S4165 Assignments should not be redundantredundant~1,053 issues
S878 Comma operator should not be usedmisra~12,245 issues
S881 Increment (++) and decrement (--) operators should not be used in a method call or mixed with other operators in an expressioncert, misra~878 issues
S1116 Extra semicolons should be removedcert, misra, unused~13,341 issues
S1128 Unnecessary imports should be removedes2015, unused~193 issues
S101 Class names should comply with a naming conventionconvention
ArrayAnd. Array constructors should not be usedsuspicious~4,058 issues
S3863 Imports from the same modules should be mergedes2015~1 issue
Continue. "continue" should not be usedbad-practice, misra~2 issues
HtmlComm. HTML-style comments should not be usedbad-practice~21 issues
MissingN. Files should contain an empty newline at the endconvention~313 issues
Multilin. Multiline string literals should not be usedbad-practice~1,661 issues
Primitiv. Wrapper objects should not be used for primitive typespitfall~1,358 issues
S100 Function and method names should comply with a naming conventionconvention~4,506 issues
S1105 An open curly brace should be located at the end of a lineconvention~7 issues
S1125 Boolean literals should not be used in comparisonsclumsy~1,696 issues
S1126 Return of boolean expressions should not be wrapped into an "if-then-else" statementclumsy~400 issues
S1226 Function parameters, caught exceptions and foreach variables should not be reassignedmisra, pitfall~32 issues
S1264 A "while" loop should be used instead of a "for" loopclumsy~1,377 issues
S1301 "switch" statements should have at least 3 "case" clausesbad-practice, misra~1,540 issues
S1472 Function call arguments should not start on new linessuspicious~1,949 issues
S1488 Local variables should not be declared and then immediately returned or thrownclumsy~2,437 issues
S2138 "undefined" should not be assignedsuspicious~260 issues
S2713 JQuery cache variables should comply with a convention nameconvention, jquery~6 issues
S2990 The global "this" object should not be usedconfusing~982 issues
S3002 Unary operators "+" and "-" should not be used with objectsconfusing~5 issues
S3317 Default export names and file names should matchconfusing, convention, es2015~878 issues
S3402 Strings and non-strings should not be addedconfusing~78 issues
S3498 Object literal shorthand syntax should be usedconvention, es2015~16 issues
S3499 Shorthand object properties should be grouped at the beginning or end of an object declarationconvention, es2015~380 issues
S3512 Template strings should be used instead of concatenationclumsy, es2015~2 issues
S3514 Destructuring syntax should be used for assignmentsclumsy, es2015
S3524 Braces and parentheses should be used consistently with arrow functionsconvention, es2015~37 issues
S3533 "import" should be used to include external codeconvention, es2015, obsolete~48 issues
S3723 Trailing commas should be usedconvention
Semicolo. Statements should end with semicolonsconvention~7,308 issues
SingleQu. Single quotes should be used for string literalsconvention~1,366 issues
TabChara. Tabulation characters should not be usedconvention~175 issues
TooManyB. Loops should not contain more than a single "break" or "continue" statementbrain-overload~3,158 issues
Trailing. Comments should not be located at the end of lines of codeconvention~12 issues
Trailing. Lines should not end with trailing whitespacesconvention~5,841 issues
UnusedVa. Unused local variables and functions should be removedunused~57,395 issues
S1135 Track uses of "TODO" tagscwe~10,354 issues

Back to the top