added rule GCI 110 - avoid wildcard imports#109
added rule GCI 110 - avoid wildcard imports#109dedece35 merged 2 commits intogreen-code-initiative:mainfrom
Conversation
There was a problem hiding this comment.
Hi @hassineabd,
thank you a lot for this interesting PR ...
before accepting this PR, please, you must do following tasks :
- update CHANGELOG.md with your upgrade in the current repository
- follow process for a new rule : https://github.com/green-code-initiative/creedengo-common/blob/main/doc/starter-pack.md#implement-a-new-rule
Please, in the rule documentation in creedengo-rules-specifications, I will particularly vigilent about the proof of your ideas ... please feel free to giver some URLs to prove your idea. A full example : https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/src/main/rules/GCI107/python/GCI107.asciidoc
Please, also, take into account Copilot review, bottom, and adapt / complete your unit tests with new modifications.
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new rule GCI110 to detect and flag wildcard imports in Python code, which helps reduce memory usage and follows PEP 8 best practices.
- Implements a check that detects
from module import *patterns - Adds comprehensive test coverage with both compliant and non-compliant examples
- Integrates the new rule into the existing rule repository and profile configuration
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/org/greencodeinitiative/creedengo/python/checks/AvoidWildcardImportsCheck.java | Main rule implementation that detects wildcard imports |
| src/test/java/org/greencodeinitiative/creedengo/python/checks/AvoidWildcardImportsCheckTest.java | Unit test for the new rule |
| src/test/resources/checks/avoidWildcardImports.py | Test cases showing compliant and non-compliant code examples |
| src/main/java/org/greencodeinitiative/creedengo/python/PythonRuleRepository.java | Registers the new rule in the repository |
| src/main/resources/org/greencodeinitiative/creedengo/python/creedengo_way_profile.json | Adds GCI110 to the profile configuration |
| src/it/test-projects/creedengo-python-plugin-test-project/src/avoidWildcardImports.py | Integration test file with example cases |
| src/it/java/org/greencodeinitiative/creedengo/python/integration/tests/GCIRulesIT.java | Integration test that validates rule behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| 4, 5, 6, 16, 21, 28, 29 | ||
| }; | ||
| int[] endLines = new int[]{ | ||
| 4, 5, 6, 16, 21, 28, 29 |
There was a problem hiding this comment.
The line numbers in the integration test don't match the actual wildcard import lines in the test file. Based on the test file, wildcard imports are on lines 2, 3, 5, and 8, not the specified lines.
| 4, 5, 6, 16, 21, 28, 29 | |
| }; | |
| int[] endLines = new int[]{ | |
| 4, 5, 6, 16, 21, 28, 29 | |
| 2, 3, 5, 8 | |
| }; | |
| int[] endLines = new int[]{ | |
| 2, 3, 5, 8 |
|
Hi @hassineabd, thank you for last modifications but it lacks the part about "creedengo-specifications-rules" in my last comment. |
|
Hello @dedece35 , |
|
Hi @hassineabd, Could you please update your pom.xml to use this 2.6.0 version ? |
|
Hi @hassineabd, after testing your PR, I found some different minor problems (TI ko, not same test file between TU and TI, TU KO) that I corrected quickly locally. Thank you for your work !!! |
this rule detects all wildcard import statements using the from module import * pattern.
using wildcard imports (from module import *) is an anti-pattern that impacts memory
exemple:
why this matters:
-everything in the lib is loaded into memory, even the ones that are not used