Prevent comma abuse by implementing new rule#581
Open
jgengo wants to merge 2 commits into42school:masterfrom
Open
Prevent comma abuse by implementing new rule#581jgengo wants to merge 2 commits into42school:masterfrom
jgengo wants to merge 2 commits into42school:masterfrom
Conversation
Contributor
|
Hello, @jgengo! Can you add tests for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Detect comma operator abuse to bypass line count rules
Issues Fixed
Problem
Students were exploiting comma operators wrapped in parentheses to bypass the 25-line function limit and "too many instructions" rules:
These expressions passed validation despite chaining multiple function calls on a single line.
Solution
CheckCommaOperatorAbusethat detects multiple function calls or assignments chained with comma operators within parenthesesCOMMA_OP_ABUSEerror type with message: "Comma operator used to chain multiple function calls or assignments"Verification Steps
Please ensure the following steps have been completed:
tests/rules/samples/ko_comma_operator_abuse.c(negative test)tests/rules/samples/ok_comma_in_params.c(positive test)poetry run flake8to check for linting issues.poetry run pytestto ensure unit tests pass (517/517 passed).poetry run toxto validate compatibility across Python versions.Testing Results
COMMA_OP_ABUSEerrorprintf("%d %d", a, b)→ OKFiles Changed
norminette/rules/check_comma_operator_abuse.py(new, 155 lines)norminette/norm_error.py(modified, +1 error definition)tests/rules/samples/ko_comma_operator_abuse.c(new)tests/rules/samples/ko_comma_operator_abuse.out(new)tests/rules/samples/ok_comma_in_params.c(new)tests/rules/samples/ok_comma_in_params.out(new)Additional Notes
The new rule scans for opening parentheses and counts:
If 2+ function calls or 2+ assignments are chained with commas, the rule flags a
COMMA_OP_ABUSEerror.The implementation properly handles nested parentheses to avoid false positives on legitimate patterns like
func(a, func2(b, c)).