Skip to content

Conversation

@hassineabd
Copy link

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:

  • explicit imports: from module import function1, function2
  • module imports: import module

why this matters:
-everything in the lib is loaded into memory, even the ones that are not used

  • PEP 8 discourages this
  • increases memory usage -> higher energy consumption ( especially in long running apps)

Copy link
Member

@dedece35 dedece35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hassineabd,

thank you a lot for this interesting PR ...
before accepting this PR, please, you must do following tasks :

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.

Copy link
Contributor

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

Comment on lines 471 to 474
4, 5, 6, 16, 21, 28, 29
};
int[] endLines = new int[]{
4, 5, 6, 16, 21, 28, 29
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Copilot uses AI. Check for mistakes.
@dedece35
Copy link
Member

Hi @hassineabd,

thank you for last modifications but it lacks the part about "creedengo-specifications-rules" in my last comment.

@hassineabd
Copy link
Author

hassineabd commented Oct 27, 2025

Hello @dedece35 ,
thank you for your feedback , i have added the requested doc on the other repos, please check this PR :
green-code-initiative/creedengo-rules-specifications#422

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants