diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S108.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S108.html index 844691397d2..d64cef4b5c3 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S108.html +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S108.html @@ -2,9 +2,13 @@
An empty code block is confusing. It will require some effort from maintainers to determine if it is intentional or indicates the implementation is incomplete.
-for (var i = 0; i < length; i++) {} // Noncompliant: is the block empty on purpose, or is code missing? +for (let i = 0; i < length; i++) {} // Noncompliant: is the block empty on purpose, or is code missing?
Removing or filling the empty code blocks takes away ambiguity and generally results in a more straightforward and less surprising code.
The rule ignores: * code blocks that contain comments * catch
blocks
The rule ignores:
+catch
blocks import
=== Related rules
- import
TODO
tags are commonly used to mark places where some more code is required, but which the developer wants to implement later.
Sometimes the developer will not have the time or will simply forget to get back to that tag.
-This rule is meant to track those tags and to ensure that they do not go unnoticed.
+Developers often use TOOO
tags to mark areas in the code where additional work or improvements are needed but are not implemented
+immediately. However, these TODO
tags sometimes get overlooked or forgotten, leading to incomplete or unfinished code. This code smell
+class aims to identify and address such unattended TODO
tags to ensure a clean and maintainable codebase. This description will explore
+why this is a problem and how it can be fixed to improve the overall code quality.
Unattended TODO
tags in code can have significant implications for the development process and the overall codebase.
Incomplete Functionality: When developers leave TODO
tags without implementing the corresponding code, it results in incomplete
+functionality within the software. This can lead to unexpected behavior or missing features, adversely affecting the end-user experience.
Missed Bug Fixes: If developers do not promptly address TODO
tags, they might overlook critical bug fixes and security updates.
+Delayed bug fixes can result in more severe issues and increase the effort required to resolve them later.
Impact on Collaboration: In team-based development environments, unattended TODO
tags can hinder collaboration. Other team members
+might not be aware of the intended changes, leading to conflicts or redundant efforts in the codebase.
Codebase Bloat: Accumulation of unattended TODO
tags over time can clutter the codebase and make it difficult to distinguish between
+work in progress and completed code. This bloat can make it challenging to maintain an organized and efficient codebase.
Addressing this code smell is essential to ensure a maintainable, readable, reliable codebase and promote effective collaboration among +developers.
function doSomething() { diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S1481.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S1481.html index ab998609ab8..a4d8ca9b3c4 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S1481.html +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S1481.html @@ -61,8 +61,8 @@Resources
Documentation
Identify and remove unreachable statements from your code.
-+function func(a) { let i = 10; return i + a; diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2310.json b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2310.json index df06d1d691e..4a60676352b 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2310.json +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2310.json @@ -1,5 +1,5 @@ { - "title": "Loop counters should not be assigned to from within the loop body", + "title": "Loop counters should not be assigned within the loop body", "type": "CODE_SMELL", "status": "ready", "remediation": { diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2692.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2692.html index d0f0b352f36..9ffd1946615 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2692.html +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2692.html @@ -1,8 +1,8 @@Why is this an issue?
Most checks against an
-indexOf
value compare it with -1 because 0 is a valid index. Checking against> 0
ignores the first element, which is likely a bug.-var arr = ["blue", "red"]; ++let arr = ["blue", "red"]; if (arr.indexOf("blue") > 0) { // Noncompliant // ... @@ -10,8 +10,8 @@Why is this an issue?
Moreover, if the intent is merely to check the presence of the element, and if your browser version supports it, consider using
-includes
instead.-var arr = ["blue", "red"]; +++let arr = ["blue", "red"]; if (arr.includes("blue")) { // ... @@ -19,6 +19,7 @@Why is this an issue?
This rule raises an issue when an
indexOf
value retrieved from an array is tested against> 0
.Resources
-Array.prototype.includes() -documentation at MDN
+Documentation
+MDN - +
diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2737.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2737.html index fe444009479..7af8690d733 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2737.html +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2737.html @@ -21,4 +21,10 @@Array.prototype.includes()
Why is this an issue?
throw ex; }Resources
+Documentation
+
try...catch
throw
-var {a: {}} = myObj; // Noncompliant: this does not create any variable +let {a: {}} = myObj; // Noncompliant: this does not create any variable function foo({p: []}) { // Noncompliant: this does not define any parameter // ... } diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S3981.json b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S3981.json index 28d2a147f86..7874ff93262 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S3981.json +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S3981.json @@ -1,5 +1,5 @@ { - "title": "Collection sizes and array length comparisons should make sense", + "title": "Collection size and array length comparisons should make sense", "type": "BUG", "status": "ready", "remediation": { diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4030.json b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4030.json index e49a487541e..11e7cb3781e 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4030.json +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4030.json @@ -1,5 +1,5 @@ { - "title": "Collection and array contents should be used", + "title": "Collection contents should be used", "type": "CODE_SMELL", "status": "ready", "remediation": { diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4043.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4043.html index 931c88f3245..25fce65d98e 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4043.html +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4043.html @@ -17,12 +17,12 @@-Why is this an issue?
const reversed = a.toReversed(); const sorted = b.toSorted();
Alternatively, change a mutating method into a non-mutating alternative using the spread syntax (…
) or slice()
to create
-a copy first.
Alternatively, change a mutating method into a non-mutating alternative using the spread syntax (…
).
const reversed = [...a].reverse(); const sorted = [...b].sort();+
Or slice()
to create a copy first.
const reversed = a.slice().reverse(); const sorted = b.slice().sort(); diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4143.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4143.html index f56499df94c..272cef17e7a 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4143.html +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4143.html @@ -3,14 +3,14 @@+Why is this an issue?
a "dead store".This rule detects repeatedly adding an element at the same index or key in a collection or adding identical elements to a set.
- fruits[1] = "banana"; - fruits[1] = "apple"; // Noncompliant +fruits[1] = "banana"; +fruits[1] = "apple"; // Noncompliant - myMap.set("key", 1); - myMap.set("key", 2); // Noncompliant +myMap.set("key", 1); +myMap.set("key", 2); // Noncompliant - mySet.add(1); - mySet.add(1); // Noncompliant +mySet.add(1); +mySet.add(1); // NoncompliantThis practice is redundant and will cause confusion for the reader. More importantly, it is often an error and not what the developer intended to do.
diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4524.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4524.html index 0380b7a725c..9bc56850c0c 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4524.html +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4524.html @@ -17,4 +17,9 @@Why is this an issue?
break; }
switch
When used on an array, it will compare against the indexes of the array, not the values. This is likely not to be the expected behavior.
-function func1() { +function func() { const arr = ["a", "b", "c"]; const expectedValue = "b"; @@ -22,7 +22,7 @@Why is this an issue?
const expectedValue = "b"; if (arr.includes(expectedValue)) { - return expectedValue + " was found in the array"; + return expectedValue + " found in the array"; } else { return expectedValue + " not found"; } diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4822.json b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4822.json index 6626a5c1de3..7d8e5db34c7 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4822.json +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S4822.json @@ -1,5 +1,5 @@ { - "title": "Promise rejections should not be caught by \u0027try\u0027 block", + "title": "Promise rejections should not be caught by \u0027try\u0027 blocks", "type": "BUG", "status": "ready", "remediation": { diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6092.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6092.html index 630edb7d144..aacfaf02f94 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6092.html +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6092.html @@ -112,13 +112,16 @@Why is this an issue?
easier to do so when the test is focused on a single behavior or functionality.Resources
Documentation
-Chai.js -
+.by
Chai.js --.change
Chai.js -.decrease
Chai.js -.finite
Chai.js -.include
Chai.js -.increase
Chai.js -.members
Chai.js -.ownPropertyDescriptor
Chai.js -.property
Chai.js -.throw
.by
.change
.decrease
.finite
.include
.increase
.members
.ownPropertyDescriptor
.property
.throw
A redundant boolean cast affects code readability. Not only the condition becomes more verbose but it also misleads the reader who might question -the intent behind the extra cast.
-The condition can be written without the Boolean cast.
+the intent behind the extra cast. The condition can be written without the Boolean cast.if (foo) { // ... @@ -25,11 +24,11 @@Why is this an issue?
Resources
Documentation
The rule reports an issue on a call to String.match()
whenever it can be replaced with semantically equivalent
RegExp.exec()
.
Rewrite the pattern matching from string.match(regex)
to regex.exec(string)
.
'foo'.match(/bar/);-
Rewrite the pattern matching from string.match(regex)
to regex.exec(string)
.
/bar/.exec('foo');
String.prototype.match()
RegExp.prototype.exec()
Object.defineProperty()
Initializing a variable to undefined
is unnecessary and should be avoided. A variable will automatically be set to
undefined
if you declare it without initialization, so the initialization code is redundant in this case.
-var foo = undefined; // Non-compliant, replace with var foo; -let bar = undefined; // Non-compliant, replace with let foo; +var foo = undefined; // Noncompliant: replace with var foo; +let bar = undefined; // Noncompliant: replace with let foo;
If the class declaration does not include a constructor, one is automatically created, so there is no need to provide an empty constructor, or one that just delegates to the parent class.
-+class Foo { constructor() {} // Noncompliant, empty } class Bar extends Foo { - constructor(params) { // Noncompliant, just delegates to the parent + constructor(params) { // Noncompliant: just delegates to the parent super(params); } }Instead, you can safely remove the empty constructor without affecting the functionality.
-+class Foo {} class Bar extends Foo {} diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6650.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6650.html index 85f2c11c76f..4d190425181 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6650.html +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6650.html @@ -1,13 +1,13 @@Why is this an issue?
Renaming imports, exports, or destructuring assignments to the same name is redundant and can be safely removed. You may accidentally end up with such code if you do a refactoring and change the local name in several places.
-+import { foo as foo } from "bar"; export { foo as foo }; let { foo: foo } = bar;Fix your code to remove the unnecessary renaming.
-+import { foo } from "bar"; export { foo }; let { foo } = bar; diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6654.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6654.html index 21cd68230b1..8767a695217 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6654.html +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6654.html @@ -1,5 +1,5 @@Why is this an issue?
-Javascript has a prototypical inheritance model. Each object has an internal property that points to another object, called a +
JavaScript has a prototypical inheritance model. Each object has an internal property that points to another object, called a
prototype
. That prototype object has a prototype of its own, and the whole sequence is called a prototype chain. When accessing a property or a method of an object, if it is not found at the top level, the search continues through the object’s prototype and then further down the prototype chain. This feature allows for very powerful dynamic inheritance patterns but can also lead to confusion when compared to @@ -7,13 +7,13 @@Why is this an issue?
To simplify the access to the prototype of an object some browsers introduced the
-__proto__
property, which was later deprecated and removed from the language. The current ECMAScript standard includesObject.getPrototype
andObject.setPrototype
static methods that should be used instead of the__proto__
property.-let prototype = foo.__proto__; // Noncompliant, use Object.getPrototype -foo.__proto__ = bar; // Noncompliant, use Object.setPrototype ++let prototype = foo.__proto__; // Noncompliant: use Object.getPrototype +foo.__proto__ = bar; // Noncompliant: use Object.setPrototypeTo fix your code replace
-__proto__
with calls toObject.getPrototype
andObject.setPrototype
static methods.+let prototype = Object.getPrototype(foo); Object.setPrototype(foo, bar);diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6657.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6657.html index 338b436fe0a..701c17380d1 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6657.html +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6657.html @@ -2,17 +2,17 @@Why is this an issue?
Octal escape sequences in string literals have been deprecated since ECMAScript 5 and should not be used in modern JavaScript code.
Many developers may not have experience with this format and may confuse it with the decimal notation.
-var message = "Copyright \251"; // Noncompliant +let message = "Copyright \251"; // NoncompliantThe better way to insert special characters is to use Unicode or hexadecimal escape sequences.
-var message1 = "Copyright \u00A9"; // unicode -var message2 = "Copyright \xA9"; // hexadecimal +let message1 = "Copyright \u00A9"; // unicode +let message2 = "Copyright \xA9"; // hexadecimalResources
Documentation
Object.assign()