Skip to content

Commit 77f1ff0

Browse files
committed
correction after GCI108 merging
1 parent a520fc0 commit 77f1ff0

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- [#70](https://github.com/green-code-initiative/creedengo-python/pull/70) Add rule GCI97 Prefer Append Left (a rule to prefer the use of `append` over `insert` for list, using deques)
12+
- [#70](https://github.com/green-code-initiative/creedengo-python/pull/70) Add rule GCI108 Prefer Append Left (a rule to prefer the use of `append` over `insert` for list, using deques)
1313
- [#78](https://github.com/green-code-initiative/creedengo-python/pull/78) Add rule GCI105 on String Concatenation. This rule may also apply to other rules
1414
- [#74](https://github.com/green-code-initiative/creedengo-python/pull/74) Add rule GCI101 Avoid Conv Bias Before Batch Normalization, a rule specific to Deeplearning
1515
- [#75](https://github.com/green-code-initiative/creedengo-python/pull/75) Add rule GCI102 avoid non pinned memory for dataloader. This rule is specific to PyTorch and so AI

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030

3131
import static org.sonar.plugins.python.api.tree.Tree.Kind.*;
3232

33-
3433
@Rule(key = "GCI108")
3534
public class PreferAppendLeft extends PythonSubscriptionCheck {
35+
3636
public static final String DESCRIPTION = "Use appendleft with deque instead of .insert(0, val) for modification at the beginning of a list";
3737

3838
@Override
@@ -44,19 +44,12 @@ private void visitCallExpression(SubscriptionContext context) {
4444
CallExpression callExpression = (CallExpression) context.syntaxNode();
4545
if (callExpression.callee().is(QUALIFIED_EXPR)) {
4646
QualifiedExpression qualifiedExpression = (QualifiedExpression) callExpression.callee();
47-
4847
if (qualifiedExpression.name().name().equals("insert")) {
4948
List<org.sonar.plugins.python.api.tree.Argument> arguments = callExpression.arguments();
50-
if (arguments.size() >= 2) {
51-
Expression firstArg;
52-
firstArg = ((RegularArgument) arguments.get(0)).expression();
53-
if (arguments.get(0) instanceof RegularArgument) {
54-
firstArg = ((RegularArgument) arguments.get(0)).expression();
55-
if (firstArg.is(NUMERIC_LITERAL)) {
56-
if (isZeroLiteral(firstArg)) {
57-
context.addIssue(callExpression, DESCRIPTION);
58-
}
59-
}
49+
if (arguments.size() >= 2 && arguments.get(0) instanceof RegularArgument) {
50+
Expression firstArg = ((RegularArgument) arguments.get(0)).expression();
51+
if (firstArg.is(NUMERIC_LITERAL) && isZeroLiteral(firstArg)) {
52+
context.addIssue(callExpression, DESCRIPTION);
6053
}
6154
}
6255
}

0 commit comments

Comments
 (0)