Commit graph

3 commits

Author SHA1 Message Date
Claude
0e41cb2357
feat(code-reviewer): C-specific smell detector + fixtures
Phase 2 / Tier 1 of the post-#769 audit. Until now, the deterministic
analyzer (scripts/code_quality_checker.py) had language-specific smell
detectors only for C# and Java; C / C++ / Rust / Ruby / PHP / Dart all
fell through to generic checks. This PR brings C onto the same footing
as C# and Java -- the security delta is largest for memory-unsafe
languages, so C goes first per the audit ranking.

What's detected (CERT C + CWE catalogue patterns)

  - Banned functions: gets, strcpy, strcat, sprintf, vsprintf
    (CWE-242 / CWE-120 family -- no bounds check on any of them)
  - Format-string vulnerability: printf(var) / syslog(var) where the
    first arg is a bare identifier instead of a literal (CWE-134).
    Suppressed when the first arg is a literal string.
  - Unbounded scanf: %s without a width specifier (CWE-120).
    Suppressed when a width is present (e.g. %31s).
  - malloc/calloc/realloc result not NULL-checked within 5 lines
    (CWE-690). Recognises if (p == NULL), if (NULL == p), if (!p),
    if (p != NULL).
  - free(p) without setting p = NULL on the next real line
    (CWE-416 use-after-free guardrail). Low severity since some
    style guides skip the zeroing convention.
  - system() with a non-literal argument (CWE-78 command injection).
    Suppressed when the argument is a string literal or NULL.

Implementation

  - New function check_c_specific_smells() in code_quality_checker.py,
    placed after check_java_specific_smells(). Reuses the existing
    _strip_csharp_comments helper -- C, C#, and Java share // and /* */
    comment syntax.
  - Wired into analyze_file() via the existing dispatcher pattern:
    `if language == "c": smells.extend(check_c_specific_smells(content))`.

Fixtures (regression-detection harness)

  - assets/sample_c_smells.c -- 67 lines, every detector pattern
    labelled inline with its CWE. Smells fixture produces 10 C-specific
    detector hits (strcpy fires twice intentionally, once in each
    function). Score: 4/100 (F).
  - assets/sample_c_clean.c -- same surface area refactored per
    rules/universal.md + languages/c.md. Zero C-specific hits.
    Score: 100/100 (A).
  - expected_outputs/sample_c_smells_quality.json and
    expected_outputs/sample_c_clean_quality.json -- committed JSON
    output mirrors the existing C# / Java regression-guard pattern.

Documentation

  - engineering-team/skills/code-reviewer/README.md
    - "Language-specific smell packs" line extended to enumerate the
      6 C-pack patterns alongside the existing C# and Java packs.
    - Bundled-fixtures table adds the 2 new C fixture rows.
  - engineering-team/skills/code-reviewer/SKILL.md
    - "Adding a New Language" step 5 reference: C# and Java -> C#,
      Java, and C.
    - "Regression Fixtures" paragraph reference: C# and Java -> C#,
      Java, and C.
  - docs/skills/engineering-team/code-reviewer.md mirrors the same
    SKILL.md updates.
  - CHANGELOG.md gets a new [Unreleased] section above the existing
    code-reviewer entry, documenting the detector + fixtures.

Regression

  - All 6 fixtures (C# / Java / C x smells / clean) pass byte-for-byte
    against expected_outputs/*.json. No drift introduced in C# or Java
    behaviour.

Not in this PR (Phase 2 audit, subsequent PRs)

  - check_<name>_specific_smells for C++, Rust, Python, Kotlin, PHP,
    Ruby, Dart, Go, Swift, TypeScript, JavaScript. C++ and Rust are
    the next-highest-leverage targets (smart-pointer ownership,
    unsafe block discipline). Same fixture + expected_outputs pattern
    will apply to each.

https://claude.ai/code/session_01SnXMhpyuAwrws26Wy4fizz
2026-05-28 14:27:26 +00:00
Claude
5ff4375603
feat(code-reviewer): wire Java into analyzer + complete the refactor
Builds on @mitnick2012's universal+per-language restructure (PR #742).

- Add Java as a first-class deterministic language in code_quality_checker.py
  (LANGUAGE_EXTENSIONS + function/class/method patterns + check_java_specific_smells),
  so the documented `--language java` command works instead of erroring on an
  invalid choice. Add Java debug + @SuppressWarnings signals to pr_analyzer.py.
- Add Java regression fixtures (sample_java_smells/clean.java) with committed
  expected_outputs JSON, mirroring the existing C# fixtures.
- Delete references/{code_review_checklist,coding_standards,common_antipatterns}.md,
  now duplicated by rules/universal.md + languages/*.md; repoint README and the
  C# clean fixture header at the new structure.
- Document the optional analyzer-wiring + fixture steps in the "Adding a New
  Language" guide and restore a Regression Fixtures section in SKILL.md.

https://claude.ai/code/session_01DjuELpoFdFbFscr3kAatni
2026-05-26 14:02:19 +00:00
Claude
7dc7fae1fe
feat(code-reviewer): raise quality score 54.8/D → 72.5/B- with assets, expected outputs, README
Addresses the Phase 3 quality_scorer roadmap items from the plugin audit:
adds the bundled fixtures, sample outputs, and quick-reference README that
the scorer expects, without diverging from the project's minimal-frontmatter
SKILL.md convention.

assets/:
- sample_csharp_smells.cs: a C# fixture with every pattern the skill
  detects (async void, blocking on Task, swallowed Exception, undisposed
  IDisposable, new HttpClient(), missing await, null-forgiving, hardcoded
  connection string, unsafe, dynamic, #pragma warning disable,
  [SuppressMessage], SQL concatenation), each smell labelled inline
- sample_csharp_clean.cs: the same code refactored per the standards in
  references/coding_standards.md — verifies the analyzer produces 0 HIGH
  smells on idiomatic code

expected_outputs/:
- sample_csharp_smells_quality.json: committed analyzer output for the
  smells fixture (F/45, 3 HIGH smells)
- sample_csharp_clean_quality.json: committed analyzer output for the
  clean fixture (A/98, 0 HIGH smells)

These act as a regression harness: diff the live output against the
committed JSON to detect any behaviour change in the analyzer.

scripts/code_quality_checker.py:
- Add _strip_csharp_comments() that removes // line and /* */ block
  comments before running C#-specific regex detectors. Fixes false
  positives where comment prose ("// FIX: await instead of .Result")
  matched a detection pattern.

SKILL.md:
- New ## Examples section pointing at the fixtures + showing how to
  reproduce the expected output with diff
- TOC updated to list "C# / .NET Review Notes" and "Examples"

README.md (new):
- Quick-reference card with how-to, 3 worked examples (one per script),
  pointer to fixtures, pointer to references

Phase re-scores after this change:
- Structure: 86.4/GOOD → 91.3/EXCELLENT (+4.9)
- Quality:   54.8/D    → 72.5/B-       (+17.7)
- Scripts:   3/3 PASS (unchanged)
- Security:  0/0       (unchanged)
2026-05-23 02:24:39 +00:00