Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cleophass
Copy link
Contributor

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.

Copy link

github-actions bot commented Jul 4, 2025

This PR has been automatically marked as stale because it has no activity for 30 days.
Please add a comment if you want to keep the issue open. Thank you for your contributions!

@github-actions github-actions bot added the stale label Jul 4, 2025
@cleophass cleophass requested a review from dedece35 July 21, 2025 12:26
@github-actions github-actions bot removed the stale label Jul 22, 2025
@dedece35 dedece35 requested a review from Copilot July 24, 2025 20:40
Copy link

@Copilot Copilot AI left a 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.
  }}}

Comment on lines +83 to +84
context.addIssue(lhsExpression.firstToken(), DESCRIPTION);
}
Copy link
Preview

Copilot AI Jul 24, 2025

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.

Suggested change
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.

Comment on lines +76 to +80
try {
return Objects.requireNonNull(callExpression.argumentList()).arguments();
} catch (NullPointerException e) {
return List.of();
}
Copy link
Preview

Copilot AI Jul 24, 2025

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();

Suggested change
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
Copy link
Preview

Copilot AI Jul 24, 2025

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'.

Suggested change
- [#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants