-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Message:Refactor the code to remove this label and the need for it.
-
Default Severity:Major
-
Impact:Low
-
Likelihood:High
-
Default Quality Profiles:Sonar way
-
Legacy Key:LabelsShouldNotBeUsedCheck
-
Targeted languages:Flex, PHP, Swift
-
Covered Languages:Java, JavaScript
-
Irrelevant for Languages:C#, C, C++, Objective-C, Python
-
Remediation Function:Constant/Issue
-
Constant Cost:30min
-
Analysis Scope:Main Sources, Test Sources
-
Implementation details:
-
ESLint:no-labels
Labels are not commonly used in Java, and many developers do not understand how they work. Moreover, their usage makes the control flow harder to follow, which reduces the code's readability.
Noncompliant Code Example
int matrix[][] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; outer: for (int row = 0; row < matrix.length; row++) { // Non-Compliant for (int col = 0; col < matrix[row].length; col++) { if (col == row) { continue outer; } System.out.println(matrix[row][col]); // Prints the elements under the diagonal, i.e. 4, 7 and 8 } }
Compliant Solution
for (int row = 1; row < matrix.length; row++) { // Compliant for (int col = 0; col < row; col++) { System.out.println(matrix[row][col]); // Also prints 4, 7 and 8 } }
- contributes to
-
MMF-482 Bunch of valuable JS rules not relying on SE
-
- Closed
-
- is duplicated by
-
RSPEC-3045 "break" should not be used with a label
- Closed
- is related to
-
RSPEC-1219 "switch" statements should not contain non-case labels
- Active
- relates to
-
RSPEC-907 "goto" statement should not be used
- Active
-
RSPEC-1439 Only "while", "do" and "for" statements should be labelled
- Active
- links to
(1 links to)
1.
|
JavaScript | RSPEC-3773 |
|
Active | Unassigned | |
2.
|
Java | RSPEC-4772 |
|
Active | Unassigned |