Skip to content

Commit 348586c

Browse files
authored
JS-811 SQ issues on Java code (#5557)
1 parent 461a5e8 commit 348586c

File tree

4 files changed

+11
-18
lines changed

4 files changed

+11
-18
lines changed

sonar-plugin/bridge/src/main/java/org/sonar/plugins/javascript/bridge/NodeDeprecationWarning.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class NodeDeprecationWarning {
3737
static final Version MIN_SUPPORTED_NODE_VERSION;
3838
private static final List<String> RECOMMENDED_NODE_VERSIONS;
3939
public static final Version RECOMMENDED_NODE_VERSION;
40+
private final AnalysisWarningsWrapper analysisWarnings;
4041

4142
static {
4243
Properties props = loadProperties(NODE_PROPERTIES_FILE);
@@ -49,6 +50,10 @@ public class NodeDeprecationWarning {
4950
);
5051
}
5152

53+
public NodeDeprecationWarning(AnalysisWarningsWrapper analysisWarnings) {
54+
this.analysisWarnings = analysisWarnings;
55+
}
56+
5257
static Properties loadProperties(String resourceName) {
5358
try (InputStream inputStream = NodeDeprecationWarning.class.getResourceAsStream(resourceName)) {
5459
return loadProperties(inputStream);
@@ -67,12 +72,6 @@ static Properties loadProperties(@Nullable InputStream inputStream) throws IOExc
6772
}
6873
}
6974

70-
private final AnalysisWarningsWrapper analysisWarnings;
71-
72-
public NodeDeprecationWarning(AnalysisWarningsWrapper analysisWarnings) {
73-
this.analysisWarnings = analysisWarnings;
74-
}
75-
7675
void logNodeDeprecation(Version actualNodeVersion) {
7776
if (!actualNodeVersion.isGreaterThanOrEqual(RECOMMENDED_NODE_VERSION)) {
7877
String msg = String.format(

sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2310.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<p>This rule is deprecated; use {rule:javascript:S127} instead.</p>
21
<h2>Why is this an issue?</h2>
32
<p>Loop counters, such as variables used to track the iteration count in loops, should not be assigned from within the loop body to avoid unexpected
43
behavior and bugs. It can inadvertently lead to an infinite loop or make the loop behavior more complex and harder to reason about.</p>

sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S2310.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
{
22
"title": "Loop counters should not be assigned within the loop body",
33
"type": "CODE_SMELL",
4-
"status": "deprecated",
4+
"status": "ready",
55
"remediation": {
66
"func": "Constant/Issue",
77
"constantCost": "5min"
88
},
99
"tags": [],
10-
"extra": {
11-
"replacementRules": [
12-
"RSPEC-127"
13-
],
14-
"legacyKeys": []
15-
},
1610
"defaultSeverity": "Major",
1711
"ruleSpecification": "RSPEC-2310",
1812
"sqKey": "S2310",

sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/JavaScriptProfilesDefinitionTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public void register(RegistrarContext registrarContext) {
8686
}
8787
},
8888
}
89-
).define(context);
89+
)
90+
.define(context);
9091
}
9192

9293
@Test
@@ -103,7 +104,7 @@ void sonar_way_js() {
103104
.containsOnly(CheckList.JS_REPOSITORY_KEY, "additionalRepository");
104105
assertThat(profile.rules().size()).isGreaterThan(100);
105106

106-
assertThat(deprecatedRulesInProfile(profile, deprecatedJsRules)).hasSize(1);
107+
assertThat(deprecatedRulesInProfile(profile, deprecatedJsRules)).isEmpty();
107108
}
108109

109110
private List<String> deprecatedRulesInProfile(
@@ -128,12 +129,12 @@ void sonar_way_ts() {
128129
assertThat(profile.language()).isEqualTo(TypeScriptLanguage.KEY);
129130
assertThat(profile.name()).isEqualTo(JavaScriptProfilesDefinition.SONAR_WAY);
130131
assertThat(profile.rules()).extracting("repoKey").containsOnly(CheckList.TS_REPOSITORY_KEY);
131-
assertThat(profile.rules().size()).isGreaterThan(100);
132+
assertThat(profile.rules()).hasSizeGreaterThan(100);
132133
assertThat(profile.rules())
133134
.extracting(BuiltInQualityProfilesDefinition.BuiltInActiveRule::ruleKey)
134135
.contains("S5122");
135136

136-
assertThat(deprecatedRulesInProfile(profile, deprecatedTsRules)).hasSize(1);
137+
assertThat(deprecatedRulesInProfile(profile, deprecatedTsRules)).isEmpty();
137138
}
138139

139140
@Test

0 commit comments

Comments
 (0)