Skip to content

Commit debe362

Browse files
Wohopssonartech
authored andcommitted
SONARPY-3284 Fix a few open issues from NEXT (#470)
Addressed open issues raised by rules: - S6204: Simply use 'toList()' - S6068: Remove useless eq(...) - S6353: Simplify regex with concise characters - S1130: Remove exceptions that are not thrown - S116: Make field a constant GitOrigin-RevId: 0af0794facc0710a0369a2db60dcf9688c708138
1 parent e6dac54 commit debe362

8 files changed

Lines changed: 11 additions & 11 deletions

File tree

its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/RuffReportTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
class RuffReportTest {
3333

34-
private final String PROJECT = "ruff_project";
34+
private static final String PROJECT = "ruff_project";
3535

3636
@RegisterExtension
3737
public static final ConcurrentOrchestratorExtension ORCHESTRATOR = TestsUtils.dynamicOrchestrator;

python-checks/src/main/java/org/sonar/python/checks/StringFormat.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public class StringFormat {
4444
%\
4545
(?<field>(?:\\((?<mapkey>.*?)\\))?\
4646
(?<flags>[#\\-+0 ]*)?\
47-
(?<width>[0-9]*|\\*)?\
48-
(?:\\.(?<precision>[0-9]*|\\*))?\
47+
(?<width>\\d*|\\*)?\
48+
(?:\\.(?<precision>\\d*|\\*))?\
4949
(?:[lLH])?\
5050
(?<type>[diueEfFgGoxXrsac]|%))?""");
5151

52-
private static final Pattern FORMAT_FIELD_PATTERN = Pattern.compile("^(?<name>[^.\\[!:{}]+)?(?:(?:\\.[a-zA-Z0-9_]+)|(?:\\[[^]]+]))*");
52+
private static final Pattern FORMAT_FIELD_PATTERN = Pattern.compile("^(?<name>[^.\\[!:{}]+)?(?:(?:\\.\\w+)|(?:\\[[^]]+]))*");
5353
private static final Pattern FORMAT_NUMBER_PATTERN = Pattern.compile("^\\d+$");
5454
private static final Pattern FORMAT_UNICODE_PATTERN = Pattern.compile("^\\\\N\\{[a-zA-Z0-9-_\\s]*}");
5555

python-checks/src/main/java/org/sonar/python/checks/hotspots/ClearTextProtocolsCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
@Rule(key = "S5332")
5050
public class ClearTextProtocolsCheck extends PythonSubscriptionCheck {
5151
private static final List<String> SENSITIVE_PROTOCOLS = Arrays.asList("http://", "ftp://", "telnet://");
52-
private static final Pattern LOOPBACK = Pattern.compile("localhost|127(?:\\.[0-9]+){0,2}\\.[0-9]+$|^(?:0*\\:)*?:?0*1", Pattern.CASE_INSENSITIVE);
52+
private static final Pattern LOOPBACK = Pattern.compile("localhost|127(?:\\.\\d+){0,2}\\.\\d+$|^(?:0*\\:)*?:?0*1", Pattern.CASE_INSENSITIVE);
5353
private static final Map<String, String> ALTERNATIVES = Map.of(
5454
"http", "https",
5555
"ftp", "sftp, scp or ftps",

python-checks/src/test/java/org/sonar/python/checks/OpenSourceCheckListTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void test_no_deprecated_rule_in_default_profile() throws IOException, ParseExcep
130130
}
131131

132132
@Test
133-
void test_locally_deprecated_rules_stay_deprecated() throws IOException, ParseException {
133+
void test_locally_deprecated_rules_stay_deprecated() throws IOException {
134134
// Some rules have been deprecated only for Python. When executed, rule-api reverts those rule to "ready" status, which is incorrect.
135135
// This test is here to ensure it doesn't happen.
136136
List<String> locallyDeprecatedRules = Arrays.asList("S1523", "S4721");

python-checks/src/test/java/org/sonar/python/checks/regex/ReluctantQuantifierWithEmptyContinuationCheckTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class ReluctantQuantifierWithEmptyContinuationCheckTest {
2323

2424
@Test
25-
void test() throws Exception {
25+
void test() {
2626
PythonCheckVerifier.verify("src/test/resources/checks/regex/reluctantQuantifierWithEmptyContinuationCheck.py", new ReluctantQuantifierWithEmptyContinuationCheck());
2727
}
2828

python-checks/src/test/java/org/sonar/python/checks/utils/CheckUtilsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private static FileInput parseFile(String path) throws IOException {
234234
}
235235
}
236236

237-
private static FileInput parseFileWithSymbols(String path) throws IOException {
237+
private static FileInput parseFileWithSymbols(String path) {
238238
return TestPythonVisitorRunner
239239
.createContext(new File(path))
240240
.rootTree();
@@ -260,6 +260,6 @@ private static List<FunctionDef> descendantFunctions(Tree tree) {
260260
}
261261
return tree.children().stream()
262262
.flatMap(child -> descendantFunctions(child).stream())
263-
.collect(Collectors.toUnmodifiableList());
263+
.toList();
264264
}
265265
}

python-commons/src/test/java/org/sonar/plugins/python/coverage/PythonCoverageSensorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void test_unique_report() {
199199
List<Integer> actual = IntStream.range(1, 18).mapToObj(line -> context.lineHits(FILE4_KEY, line)).toList();
200200
Integer coverageAtLine6 = actual.get(5);
201201
assertThat(coverageAtLine6).isOne();
202-
verify(analysisWarnings, times(1)).addUnique(eq("Property 'sonar.python.coverage.reportPath' has been removed. Please use 'sonar.python.coverage.reportPaths' instead."));
202+
verify(analysisWarnings, times(1)).addUnique("Property 'sonar.python.coverage.reportPath' has been removed. Please use 'sonar.python.coverage.reportPaths' instead.");
203203
}
204204

205205
@Test

python-commons/src/test/java/org/sonar/plugins/python/xunit/PythonXUnitSensorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void shouldLogWarningWhenGivenInvalidTime() {
120120
the following exception occurred: java.text.ParseException: Unparseable number: "brrrr"\
121121
""");
122122
verify(analysisWarnings, times(1))
123-
.addUnique(eq("An error occurred while trying to import XUnit report(s): 'xunit-reports/invalid-time-xunit-report.xml'"));
123+
.addUnique("An error occurred while trying to import XUnit report(s): 'xunit-reports/invalid-time-xunit-report.xml'");
124124
}
125125

126126
@Test

0 commit comments

Comments
 (0)