Open
Conversation
… and tests, update unit tests
a8e6d00 to
d14e5b5
Compare
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.
Update
The current implementation has been refactored since the original PR description.
The Magic Number detector is now implemented under:
src/magic_number/The previous implementation under:
src/violations/has been removed.
For review purposes, please focus on the following modules:
src/magic_number/ detect_magic_number.py → main detection engine magic_number_filter.py → filtering rules magic_number_patterns.py → configurations magic_number_runner.py → repository test runner test/test_magic_number_unit.py → unit testSummary
This PR introduces a magic Number detector integrated with the full-file PR analysis pipeline.
Instead of analyzing patch snippets only, the system retrieves the full file content
at the PR head commit and performs numeric literal detection across the entire file.
The detector identifies numeric literals that are not part of:
• Constant definitions
• Known safe literals
• Styling / presentation contexts
• Regex / string / comment content
and reports them as Magic Number violations for code quality analysis.
Files Added/Updated
src/extractors/pull_request_extractor.py: Updates PR data extraction to support full-file analysis.extract_file_content_at_ref(...).scripts/enrich_full_files.py: Implements full-file enrichment for PR-level data.src/magic_number/detect_magic_number.pyMain detection engine that scans source code line-by-line and identifies numeric literals that may represent Magic Numbers.
src/magic_number/magic_number_filter.pyContext filtering utilities to eliminate false positives including:
• Comments
• Strings
• Regex literals
• Styling / presentation contexts
• HTTP status codes
• Object key numbers
• CSS unit values
src/magic_number/magic_number_patterns.pyDefines numeric literal patterns, safe literals, and language mappings.
src/magic_number/magic_number_runner.pyA repository runner that reads enriched PR data and applies the detector
to generate violation reports.
test/test_magic_number_unit.pyUnit tests validating detection correctness and filtering behavior.
Unit test results:
35 tests passed.