-
Notifications
You must be signed in to change notification settings - Fork 19
GCI105 StringConcatenation #Python #DLG #Build #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: DataLabGroupe-CreditAgricole <[email protected]>
This PR has been automatically marked as stale because it has no activity for 30 days. |
Co-authored-by: DataLabGroupe-CreditAgricole <[email protected]>
src/main/java/org/greencodeinitiative/creedengo/python/checks/Utils.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new rule GCI105 for detecting inefficient string concatenation patterns in Python code, recommending the use of f-strings or str.join() instead of the += operator for better performance.
Key Changes:
- Added new rule GCI105 to detect string concatenation using += operator
- Implemented comprehensive test coverage for various concatenation scenarios
- Updated project configuration and version dependencies
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
StringConcatenation.java | Main rule implementation that detects += operations on string variables |
StringConcatenationTest.java | Unit test class for the new rule |
Utils.java | New utility class with helper methods for AST analysis |
stringConcatenation.py | Test resource files with compliant and non-compliant examples |
PythonRuleRepository.java | Registration of the new rule in the repository |
creedengo_way_profile.json | Addition of GCI105 to the default profile |
GCIRulesIT.java | Integration test for the new rule |
pom.xml | Version bump for creedengo-rules-specifications |
CHANGELOG.md | Documentation of the new feature |
Comments suppressed due to low confidence (2)
src/main/java/org/greencodeinitiative/creedengo/python/checks/StringConcatenation.java:10
- The test case on line 10 shows concatenating a string with a list comprehension, which would result in a TypeError at runtime. This appears to be an invalid test case as it represents code that would fail to execute.
* This program is distributed in the hope that it will be useful,
src/main/java/org/greencodeinitiative/creedengo/python/checks/StringConcatenation.java:85
- The closing braces are incorrectly formatted. There should be proper spacing and alignment of the closing braces for the nested if statements and method.
}}}
context.addIssue(lhsExpression.firstToken(), DESCRIPTION); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule implementation may produce false positives because it tracks string variables globally but doesn't account for variable reassignment to non-string types. A variable initially assigned a string could later be reassigned to a different type, making += operations valid.
context.addIssue(lhsExpression.firstToken(), DESCRIPTION); | |
} | |
// Ensure the variable is still a string before flagging | |
context.addIssue(lhsExpression.firstToken(), DESCRIPTION); | |
} |
Copilot uses AI. Check for mistakes.
try { | ||
return Objects.requireNonNull(callExpression.argumentList()).arguments(); | ||
} catch (NullPointerException e) { | ||
return List.of(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a try-catch block to handle NullPointerException is not a best practice. Consider using null checks instead: return callExpression.argumentList() != null ? callExpression.argumentList().arguments() : List.of();
try { | |
return Objects.requireNonNull(callExpression.argumentList()).arguments(); | |
} catch (NullPointerException e) { | |
return List.of(); | |
} | |
return callExpression.argumentList() != null ? callExpression.argumentList().arguments() : List.of(); |
Copilot uses AI. Check for mistakes.
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
|
|||
### Added | |||
|
|||
- [#78](https://github.com/green-code-initiative/creedengo-python/pull/78) Add rule GCI 105 on String Concatentation. This rule maybe apply to other rule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are spelling and grammatical errors: 'Concatentation' should be 'Concatenation', and the sentence 'This rule maybe apply to other rule' should be 'This rule may also apply to other rules'.
- [#78](https://github.com/green-code-initiative/creedengo-python/pull/78) Add rule GCI 105 on String Concatentation. This rule maybe apply to other rule | |
- [#78](https://github.com/green-code-initiative/creedengo-python/pull/78) Add rule GCI 105 on String Concatenation. This rule may also apply to other rules |
Copilot uses AI. Check for mistakes.
Verified that the rule does not exist.
Confirmed that the rule is not listed in Rules.MD, so a new ID GCI105 was created.
Added a corresponding Python unit test.
Updated the CHANGELOG accordingly.