fix: always parse CLI args so issue map loads for community analyzers#40
Merged
anto-deepsource merged 3 commits intomasterfrom Feb 26, 2026
Merged
fix: always parse CLI args so issue map loads for community analyzers#40anto-deepsource merged 3 commits intomasterfrom
anto-deepsource merged 3 commits intomasterfrom
Conversation
The `if argv:` guard introduced in #29 prevented `argparse` from ever reading `sys.argv` when the script is invoked via `__main__` (where `argv` defaults to `None`). This meant `--analyzer=<name>` was silently ignored, the issue map was never loaded, and every rule lookup failed with "Could not find issue code for rule … in issue map." Remove the guard and always call `parse_args(argv, ...)`. When `argv` is `None`, argparse automatically falls back to `sys.argv[1:]`. Custom analyzers (no `--analyzer` flag) still work because `args.analyzer` will be `None`, keeping `issue_map_path` as `None`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When `main()` is called without arguments, `parse_args(None)` falls back to `sys.argv[1:]` which contains pytest's own flags (--cov, etc.). Pass `[]` explicitly to simulate "no CLI arguments" without leaking the test runner's argv. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ss calls argparse only sets defaults when the attribute doesn't already exist on the namespace. Using the class directly meant attributes set by one call (e.g. analyzer="kube-linter") persisted on the class and were not reset to None on subsequent calls without --analyzer. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
srijan-deepsource
approved these changes
Feb 26, 2026
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.
Summary
if argv:guard added in feat: modify run_community_analyzer to work for custom analyzers #29 preventedargparsefrom readingsys.argvwhen the script runs via__main__(whereargvdefaults toNone). This caused--analyzer=<name>to be silently ignored, the issue map was never loaded, and every rule lookup failed with"Sanitized issues count, with id in map: 0".parse_args(argv)always runs. WhenargvisNone, argparse falls back tosys.argv[1:]. Custom analyzers still work becauseargs.analyzerisNonewhen--analyzerisn't passed.Test fixes
Pass
[]instead of no args in the no-issue-map test:main()with no args meansparse_args(None)which readssys.argv[1:]— in a test runner this contains pytest's own flags (--cov, etc.), causing argparse to error. Passing[]explicitly means "zero CLI arguments."Use
CommunityAnalyzerArgs()instance instead of the class: argparse only sets defaults when the attribute doesn't already exist on the namespace. Using the class directly meantanalyzer="kube-linter"set bytest_community_analyzerpersisted as a class attribute and leaked intotest_community_analyzer_without_issue_map, causing it to load the kube-linter issue map even without--analyzer.Test plan
test_community_analyzerandtest_community_analyzer_without_issue_map)Sanitized issues countis > 0 for community analyzer runs🤖 Generated with Claude Code