Skip to content

Commit

Permalink
SONARJS-600 Update message of ForInCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
vilchik-elena authored and pynicolas committed Dec 22, 2015
1 parent 2c023cb commit 6faec0d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
@SqaleConstantRemediation("5min")
public class ForInCheck extends BaseTreeVisitor {

private static final String MESSAGE = "Insert an if statement at the beginning of this loop to filter items.";
private static final String MESSAGE = "Restrict what this loop acts on by testing each property.";

@Override
public void visitForInStatement(ForInStatementTree tree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,16 @@
*/
package org.sonar.javascript.checks;

import java.io.File;
import org.junit.Test;
import org.sonar.javascript.checks.utils.JavaScriptCheckVerifier;
import org.sonar.plugins.javascript.api.tests.TreeCheckTest;
import org.sonar.squidbridge.checks.CheckMessagesVerifier;

public class ForInCheckTest extends TreeCheckTest {

@Test
public void test() {

CheckMessagesVerifier.verify(getIssues("src/test/resources/checks/forIn.js", new ForInCheck()))
.next().atLine(1).withMessage("Insert an if statement at the beginning of this loop to filter items.")
.next().atLine(21)
.next().atLine(33)
.next().atLine(37)
.noMore();
JavaScriptCheckVerifier.verify(new ForInCheck(), new File("src/test/resources/checks/forIn.js"));
}

}
10 changes: 5 additions & 5 deletions javascript-checks/src/test/resources/checks/forIn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
for (key in arr) { // NOK
for (key in arr) { // Noncompliant {{Restrict what this loop acts on by testing each property.}}
print(arr[key]);
print(arr[key]);
}
Expand All @@ -18,7 +18,7 @@ for (name in object) { // OK
print(object[name]);
}

for (key in arr) { // NOK
for (key in arr) { // Noncompliant
function f() {}
print(arr[key]);
}
Expand All @@ -30,12 +30,12 @@ for (key in obj) { // OK
a[key] = b[key];
}

for (key in obj) { // NOK
for (key in obj) { // Noncompliant
val = b[key];
}

for (key in obj) {
a.b = key; // NOK
for (key in obj) { // Noncompliant
a.b = key;
}


0 comments on commit 6faec0d

Please sign in to comment.