Skip to content

Commit e346945

Browse files
committed
small correction on GCI97
1 parent 589a877 commit e346945

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-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-
- Add rule GCI97 Optimize square computation (scalar vs vectorized method)
12+
- [#72](https://github.com/green-code-initiative/creedengo-python/pull/72) Add rule GCI97 Optimize square computation (scalar vs vectorized method)
1313

1414
### Changed
1515

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public void initialize(Context context) {
4040
context.registerSyntaxNodeConsumer(POWER, this::checkPowerOf2);
4141
}
4242

43-
4443
private boolean isNumericLiteralWithValue(Expression expr, String value) {
4544
if (expr.is(NUMERIC_LITERAL)) {
4645
NumericLiteral numericLiteral = (NumericLiteral) expr;
@@ -51,22 +50,19 @@ private boolean isNumericLiteralWithValue(Expression expr, String value) {
5150

5251
private void checkMathPowCall(SubscriptionContext context) {
5352
CallExpression callExpression = (CallExpression) context.syntaxNode();
54-
55-
53+
5654
if (isMathPowCall(callExpression)) {
5755
context.addIssue(callExpression, DESCRIPTION);
5856
}
5957
}
6058

6159
private boolean isMathPowCall(CallExpression callExpression) {
6260
Expression callee = callExpression.callee();
63-
64-
61+
6562
if (callee.is(QUALIFIED_EXPR)) {
6663
QualifiedExpression qualifiedExpr = (QualifiedExpression) callee;
6764
String name = qualifiedExpr.name().name();
68-
69-
65+
7066
if ("pow".equals(name)) {
7167

7268
if (callExpression.arguments().size() >= 2) {
@@ -79,11 +75,9 @@ private boolean isMathPowCall(CallExpression callExpression) {
7975
return false;
8076
}
8177

82-
8378
private void checkPowerOf2(SubscriptionContext context) {
8479
BinaryExpression power = (BinaryExpression) context.syntaxNode();
85-
86-
80+
8781
if (isNumericLiteralWithValue(power.rightOperand(), "2")) {
8882
context.addIssue(power, DESCRIPTION);
8983
}

src/main/resources/org/greencodeinitiative/creedengo/python/creedengo_way_profile.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"GCI72",
1111
"GCI74",
1212
"GCI89",
13+
"GCI97",
1314
"GCI203",
14-
"GCI404",
15-
"GCI97"
15+
"GCI404"
1616
]
1717
}

0 commit comments

Comments
 (0)