Skip to content

Commit 762aad2

Browse files
thomas-serre-sonarsourcesonartech
authored andcommitted
SONARPY-3173 S7512: fix error message (#384)
GitOrigin-RevId: 4a7c8c9882f02bc6772b04396bd980b9116d9dfe
1 parent 3aabc59 commit 762aad2

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private void check(SubscriptionContext ctx) {
5353
if (forStatement.testExpressions().size() == 1
5454
&& (hasIgnoredKey || hasIgnoredValue)
5555
&& (isSensitiveMethodCall(forStatement.testExpressions().get(0)) || isAssignedToSensitiveMethodCall(forStatement.testExpressions().get(0)))) {
56-
var message = hasIgnoredKey ? "Make this loop to iterate over the dict values." : "Make this loop to iterate directly over the dict.";
56+
var message = hasIgnoredKey ? "Modify this loop to iterate over the dictionary's values." : "Modify this loop to iterate directly over the dictionary.";
5757
ctx.addIssue(forStatement.testExpressions().get(0), message);
5858
}
5959
}

python-checks/src/test/resources/checks/inefficientDictIteration.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
def case1():
22
fruit = {'a': 'Apple', 'b': 'Banana'}
33

4-
for _, value in fruit.items(): # Noncompliant
4+
for _, value in fruit.items(): # Noncompliant {{Modify this loop to iterate over the dictionary's values.}}
5+
# ^^^^^^^^^^^^^
56
...
67

7-
for key, _ in fruit.items(): # Noncompliant
8+
for key, _ in fruit.items(): # Noncompliant {{Modify this loop to iterate directly over the dictionary.}}
9+
# ^^^^^^^^^^^^^
810
...
911

1012
items1 = fruit.items()

0 commit comments

Comments
 (0)