Skip to content

Commit 5f7ef27

Browse files
committed
after merging GCI99, correction of small review feedbacks
1 parent 52d81ac commit 5f7ef27

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

src/it/java/org/greencodeinitiative/creedengo/python/integration/tests/GCIRulesIT.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,21 @@ void testGCI97(){
302302

303303
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_1MIN);
304304
}
305+
306+
@Test
307+
void testGCI99(){
308+
String filePath = "src/avoidCSVFormat.py";
309+
String ruleId = "creedengo-python:GCI99";
310+
String ruleMsg = "Use Parquet or Feather format instead of CSV";
311+
int[] startLines = new int[]{
312+
4, 6, 10, 12, 14, 15, 17, 18, 23, 39, 47, 48
313+
};
314+
int[] endLines = new int[]{
315+
4, 6, 10, 12, 14, 15, 17, 18, 23, 39, 47, 48
316+
};
317+
318+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN);
319+
}
305320

306321
@Test
307322
void testGCI103(){
@@ -320,21 +335,6 @@ void testGCI103(){
320335

321336
}
322337

323-
@Test
324-
void testGCI99(){
325-
String filePath = "src/avoidCSVFormat.py";
326-
String ruleId = "creedengo-python:GCI99";
327-
String ruleMsg = "Use Parquet or Feather format instead of CSV";
328-
int[] startLines = new int[]{
329-
4, 6, 10, 12, 14, 15, 17, 18, 23, 39, 47, 48
330-
};
331-
int[] endLines = new int[]{
332-
4, 6, 10, 12, 14, 15, 17, 18, 23, 39, 47, 48
333-
};
334-
335-
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN);
336-
}
337-
338338
@Test
339339
void testGCI106() {
340340
String filePath = "src/avoidSqrtInLoop.py";

src/main/java/org/greencodeinitiative/creedengo/python/checks/AvoidCSVFormat.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import java.util.HashSet;
2929
import java.util.Set;
30-
import java.util.regex.Matcher;
3130
import java.util.regex.Pattern;
3231

3332
import org.sonar.plugins.python.api.PythonSubscriptionCheck;
@@ -36,7 +35,7 @@
3635
public class AvoidCSVFormat extends PythonSubscriptionCheck {
3736

3837
public static final String DESCRIPTION = "Use Parquet or Feather format instead of CSV";
39-
protected static final Pattern CSV_EXTENSION = Pattern.compile("\\.csv");
38+
protected static final Pattern CSV_EXTENSION = Pattern.compile("\\.csv$", Pattern.CASE_INSENSITIVE);
4039
private final Set<Integer> reportedLines = new HashSet<>();
4140

4241
@Override
@@ -53,7 +52,7 @@ public void visitCallExpression(SubscriptionContext ctx) {
5352
QualifiedExpression qualifiedExpression = (QualifiedExpression) callee;
5453
String methodName = qualifiedExpression.name().name();
5554

56-
if (methodName.equals("read_csv") || methodName.equals("to_csv")) {
55+
if ("read_csv".equals(methodName) || "to_csv".equals(methodName)) {
5756
int line = callExpression.firstToken().line();
5857

5958
if (!reportedLines.contains(line)) {
@@ -71,10 +70,8 @@ public void visitNodeString(SubscriptionContext ctx) {
7170
if (reportedLines.contains(line)) {
7271
return;
7372
}
74-
String strValue = stringLiteral.trimmedQuotesValue();
75-
Matcher matcher = CSV_EXTENSION.matcher(strValue);
7673

77-
if (matcher.find()) {
74+
if (CSV_EXTENSION.matcher(stringLiteral.trimmedQuotesValue()).find()) {
7875
reportedLines.add(line);
7976
ctx.addIssue(stringLiteral, DESCRIPTION);
8077
}

0 commit comments

Comments
 (0)