Skip to content

feat: add usage-flag-naming lint rule (#13)#66

Open
olavostauros wants to merge 5 commits into
KnickKnackLabs:mainfrom
olavostauros:feat/usage-flag-naming
Open

feat: add usage-flag-naming lint rule (#13)#66
olavostauros wants to merge 5 commits into
KnickKnackLabs:mainfrom
olavostauros:feat/usage-flag-naming

Conversation

@olavostauros

Copy link
Copy Markdown

Summary

Adds lint:usage-flag-naming rule that detects #USAGE flag directives where the flag name and arg placeholder produce different usage_* env var names — the flag silently does nothing (real bug from codebase#12, found in the scan task).

Fixes #13

Detection

Two-phase file-scan with shared lib/usage-parser.sh:

  1. Parse #USAGE flag directives for flag name (--exclude) and placeholder (<exclude>)
  2. Compare the usage_* names derived from each; flag if they differ
Scenario Severity Example
Mismatched flag/placeholder FAIL --exclude <excludes> → usage_exclude vs usage_excludes
Boolean (no placeholder) OK --verbose → skip
Short-only (no long flag) OK -e → skip

Files changed

File Change
lib/usage-parser.sh New — shared USAGE parsing helpers (117 lines)
.mise/tasks/lint/usage-flag-naming New — lint rule task
test/lint/usage-flag-naming/usage-flag-naming.bats New — 16 BATS tests
test/lint/usage-flag-naming/fixtures/ New — 10 fixture directories
.mise/tasks/scan Fixed — placeholder <excludes><exclude> to match flag name
AGENTS.md Added — lint rules table entry

Commits

  1. feat(lib): add shared usage-parser.sh for #USAGE directive parsing
  2. feat(lint): add usage-flag-naming rule — detect USAGE flag/placeholder mismatches
  3. fix: align scan USAGE placeholder with flag name --exclude
  4. docs: add usage-flag-naming to AGENTS.md lint rules table

Validation

  • mise run test234/234 tests pass (16 new tests at indices 168–183, zero regressions)
  • codebase lint:usage-flag-naming .self-hosting clean (15 files, 0 violations) — fixed the pre-existing mismatch in .mise/tasks/scan
  • bash -n .mise/tasks/lint/usage-flag-naming — syntax valid
  • bash -n lib/usage-parser.sh — syntax valid
  • git diff --check — no whitespace errors

- Extracts flag names, placeholders, and usage_* env var names
- Functions: usage_flag_name, usage_placeholder, usage_env_name,
  parse_usage_flags, discover_task_files
- Reusable by sibling rules (KnickKnackLabs#35, KnickKnackLabs#39, KnickKnackLabs#43)
…r mismatches

Scans .mise/tasks/** for #USAGE flag directives where the flag name
and arg placeholder produce different usage_* env var names. When they
differ, the flag silently does nothing (real bug from codebase#12).

- Two-phase detection: parse #USAGE directives, compare env var names
- Skips boolean flags (no placeholder), short-only (no long name)
- Respects inline and file-level codebase:ignore
- 16 BATS tests, 10 fixture directories
- Reuses lib/usage-parser.sh for directive parsing
The USAGE flag directive declared '--exclude <excludes>' but mise
exports usage_exclude (from the flag name), not usage_excludes.
The task code correctly reads , but the placeholder
was misleading. Caught by the new usage-flag-naming self-hosting check.
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.

Lint: detect USAGE flag/placeholder mismatches that produce silently-broken env vars

1 participant