Skip to content

refactor: clear Sonar code smells in the collectors - #309

Draft
ffroliva wants to merge 1 commit into
mainfrom
refactor/sonar-src-collectors
Draft

ffroliva wants to merge 1 commit into
mainfrom
refactor/sonar-src-collectors

Conversation

@ffroliva

Copy link
Copy Markdown
Owner

Clears the 20 open SonarCloud code smells in engine/collectors/ (alembic, health, loggers, threads, vulns) and engine/advisors/retention.py, without changing behaviour.

  • Cognitive complexity (S3776, 7 functions): extracted helpers keep the order of checks, messages and outputs; the alembic.py C901 pin in tests/complexity_baseline.json drops from 2 to 0.
  • S3358 nested conditionals: early returns or a named intermediate. S7508, S6395: redundant call and group removed.
  • S7632: suppressions written as # noqa: BLE001 # reason, which ruff and Sonar both read.
  • Kept with NOSONAR and the reason: [0-9] / [A-Za-z0-9_] (Python \d and \w match non-ASCII), the list() snapshot of loggerDict (another thread can register a logger mid-iteration), and the Alembic revision field name.

sonar-baseline.txt is lowered once the scan reports this pull request's fixed count (after #307).

Verified: ruff check, pyright clean; pytest -n 2 over the vulns, alembic, collectors, loggers, threads, health and advisors tests plus test_code_shape.py and test_import_boundary.py: 1568 passed, 17 skipped.

… advisor

Split the Alembic revision parser and file reader, the OSV interpreter timeline and evaluation, the OSV result validation and the vulnerability enrichment into smaller helpers with unchanged behaviour. Replace nested conditional expressions, drop a redundant list copy, correct the suppression comment syntax, and annotate the ASCII-only character classes and the contract-named field. The pinned C901 count for alembic.py drops from 2 to 0.

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>

This branch has not been deployed

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

1 participant