Static Analysis
Purpose
Automates detection of bugs, smells, and security flaws. This skill configures and runs analyzers and fixes findings they report; it does NOT perform runtime debugging, design refactors, or gate merges.
When to Use / When NOT to Use
- Use: Setting up CI checks, enforcing code style, pre-commit hooks.
- NOT: Runtime debugging or dynamic analysis.
- NOT: Merge-blocking thresholds and branch protection (use
ci-cd-quality-gates). - NOT: Structural refactoring beyond the lint fix (use
code-quality-refactoring).
Prerequisites & Assumptions
- Source code access. Tool binaries (golangci-lint, eslint, pylint).
Scope & Context Resolution
- Supported scopes: repository (default), directory/module/package, file, linter config file, single rule.
- Rule 1 - Explicit context in the prompt: Stated tools, versions, rulesets and scope are authoritative. Apply the skill strictly within them. MUST NOT add assumptions or expand beyond them. If a user instruction conflicts with a skill rule, follow the user and state the deviation in one line, EXCEPT security/data-loss rules, which stay mandatory (flag the conflict instead).
- Rule 2 - No extra context: Use this skill's Purpose, workflow and rules as the sole context, at repository scope. MUST NOT import unrelated requirements or assumptions.
- Rule 3 - Explicit scope: Operate ONLY inside the named scope. Out-of-scope files may be READ as evidence but MUST NOT be modified; report out-of-scope observations as notes, never as changes. Widening scope requires explicit user approval.
- Mutation boundary: Edits limited to analyzer configuration, hook/CI check steps, and lint fixes in files inside the resolved scope. MUST NOT change behavior beyond what a finding requires.
Step-by-Step Workflow
- Resolve scope and context (see above); state the resolved scope and mutation boundary in one line at the start of the output.
- Select tools (golangci-lint, SonarQube, Semgrep).
- Configure rulesets (start with strict presets).
- Integrate into pre-commit hooks & CI, only for the resolved scope.
- Fix baseline issues in scope before enforcing blocks.
Enterprise Rules & Standards (MUST / SHOULD / MUST NOT)
- MUST: Run linters in CI and fail on errors.
- MUST: Use pre-commit hooks for local feedback.
- MUST: Stay within the resolved scope; MUST NOT modify or expand beyond it without explicit user approval.
- SHOULD: Use strict presets (e.g.,
airbnb,golangci-lintstrict). - MUST NOT: Disable rules globally without documented justification.
- MUST NOT: Fix findings in files outside the resolved scope or reformat unrelated code.
Examples (good vs. bad, with realistic code or output)
- Bad:
//nolint:allat the top of the file. - Good: Fixing the root cause of the lint error.
- Good (scoped): Prompt "fix lint errors only in
internal/auth" -> fix findings in that package; list findings ininternal/dbas notes. - Bad (scope-expanding): Same prompt -> run
--fixrepo-wide and tighten the global.golangci.yml.
Checklist (verifiable, copy-pasteable)
- Scope and context resolved and stated.
- No changes outside the resolved scope.
- Linters in CI pipeline.
- Pre-commit hooks active.
- Zero baseline errors.
Common Pitfalls
- Alert fatigue from too many warnings.
- Ignoring security-focused SAST rules.
- Running auto-fix across the whole repository when asked about one package.