Skip to content

fix: always parse CLI args so issue map loads for community analyzers#40

Merged
anto-deepsource merged 3 commits intomasterfrom
fix/issue-map-loading
Feb 26, 2026
Merged

fix: always parse CLI args so issue map loads for community analyzers#40
anto-deepsource merged 3 commits intomasterfrom
fix/issue-map-loading

Conversation

@anto-deepsource
Copy link
Copy Markdown
Contributor

@anto-deepsource anto-deepsource commented Feb 26, 2026

Summary

  • The if argv: guard added in feat: modify run_community_analyzer to work for custom analyzers #29 prevented argparse from reading sys.argv when the script runs via __main__ (where argv defaults to None). 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".
  • Remove the guard so parse_args(argv) always runs. When argv is None, argparse falls back to sys.argv[1:]. Custom analyzers still work because args.analyzer is None when --analyzer isn't passed.

Test fixes

  • Pass [] instead of no args in the no-issue-map test: main() with no args means parse_args(None) which reads sys.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 meant analyzer="kube-linter" set by test_community_analyzer persisted as a class attribute and leaked into test_community_analyzer_without_issue_map, causing it to load the kube-linter issue map even without --analyzer.

Test plan

  • Existing tests pass (test_community_analyzer and test_community_analyzer_without_issue_map)
  • Deploy and verify Sanitized issues count is > 0 for community analyzer runs

🤖 Generated with Claude Code

anto-deepsource and others added 3 commits February 26, 2026 12:38
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>
@anto-deepsource anto-deepsource merged commit e32b4ee into master Feb 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants