Skip to content

refactor: batch config/meta rules — usage examples, flag naming, CI enforcement#75

Closed
olavostauros wants to merge 19 commits into
KnickKnackLabs:mainfrom
olavostauros:batch/config-meta
Closed

refactor: batch config/meta rules — usage examples, flag naming, CI enforcement#75
olavostauros wants to merge 19 commits into
KnickKnackLabs:mainfrom
olavostauros:batch/config-meta

Conversation

@olavostauros

@olavostauros olavostauros commented Jun 26, 2026

Copy link
Copy Markdown

Summary

Stacked batch 4/4. See ricon-family/olavo#9.

Consolidates 3 config/meta lint rules (supersedes #66, #70, #58). Includes the shared usage-parser.sh library and documentation updates.

Rules included

Rule Issue Description
usage-flag-naming #13 Detect #USAGE flag/placeholder mismatches (flag silently does nothing)
mise-usage-examples #43 Enforce #USAGE example directives for public argument-bearing tasks
ci-lint-enforcement #49 Require configured codebase lints in CI workflows

Shared library

File Description
lib/usage-parser.sh Shared #USAGE directive parsing library

Commits

Commit Description
70da2bd feat(lib): add shared usage-parser.sh for #USAGE directive parsing
aec74ec feat(lint): add usage-flag-naming rule
334e8ff fix: align scan USAGE placeholder with flag name
408355b docs: add usage-flag-naming to AGENTS.md lint rules table
1118024 style: collapse 3-line section comment blocks
befa66a feat(lint): add mise-usage-examples rule (#43)
2337baf feat: add ci-lint-enforcement rule (#49)
3cb68dc style: replace decorative rulers with single-line headers

Validation

  • mise run test — 353 tests passing
  • git diff --check — clean

The codebase_target_for_rule() function treated the entire scope value as
a single path, so a TOML string like or-true = ".mise/tasks lib" would
produce a single target /repo/.mise/tasks lib (with space) instead of
two separate targets /repo/.mise/tasks and /repo/lib.

This meant multi-path scope overrides either errored (path doesn't exist)
or silently scanned nothing — users thought they had multi-path coverage
but got false passes.

Changes:
- lib/codebase-config.sh: Replace codebase_target_for_rule() with
  codebase_targets_for_rule() that splits the scope value on whitespace
  and emits one target line per token.
- .mise/tasks/lint/_default: Iterate over the multi-line output so each
  target is linted independently.
- test/lint/default.bats: Add test covering multi-path scope with
  space-separated path list.

The fix uses shell word-splitting on the scope string (unquoted  in
a for loop), which naturally handles TOML string values with internal spaces.
Each token is resolved as a relative path against the repo root, or passed
through unchanged if absolute.

Fixes KnickKnackLabs#22
Adds first-class lint groups/presets so repos can opt into convention
bundles with a single @maintained-tool reference instead of enumerating
every lint rule individually.

Includes:
- lib/lint-groups.sh — built-in group registry, expansion, and
  discoverability functions
- lib/codebase-config.sh — source lint-groups.sh, expand @group
  references in codebase_configured_lint_rules(), support lint_exclude
- .mise/tasks/lint/_default — show expanded group count in preamble;
  updated error hint to mention groups
- .mise/tasks/lint/groups — new lint:groups discoverability task
- test/lint/lint-groups/ — 17 BATS tests

Closes KnickKnackLabs#69
Adds bash-empty-array-expansions lint rule that flags ${array[@]}
and ${array[*]} under set -u (nounset), suggesting the Bash-3-safe
alternate-value form ${arr[@]+"${arr[@]}"}.

Shares nounset detection pattern with bash-empty-argv-forwarding (KnickKnackLabs#48):
- has_nounset() - detect set -u / set -eu / set -euo pipefail
- is_safe_context() - exclude for loops and local array assignments
- has_safe_form() - exclude already-safe alternate-value forms

Standard text-based ripgrep approach with 11 fixture scenarios and
15 BATS tests. ShellCheck-clean.

Implements KnickKnackLabs#57 (KnickKnackLabs/codebase)
Adds bash-empty-argv-forwarding lint rule that flags "$@" and "${@}"
as command arguments in files with nounset enabled (set -u). This pattern
causes fatal unbound-variable errors on macOS Bash 3.2 when the argument
list is empty, while Linux Bash 5+ handles it silently.

The rule follows the established text-based ripgrep pattern from or-true,
caller-pwd-contract, etc. It correctly excludes safe contexts (for loops,
array assignments), already-safe alternate-value forms (${@+"$@"}),
and files without nounset.

Implements KnickKnackLabs#48 (KnickKnackLabs/codebase)
Scans .mise/tasks/* for #USAGE directives with var=#true, then flags
dangerous consumption of the resulting usage_* vars:
  - eval 'ARRAY=${usage_X}'    → ERROR: injection vector
  - read -ra ARRAY <<< "$usage_X"  → WARN: loses quoting

The correct pattern uses xargs printf for bash or shlex.split() for
Python tasks, per mise-conventions.md.
…r suppression

Adds text-based detection for 'exec' with stderr redirection
(2>/dev/null, 2>&-, 2>!) that persists for the current shell.

- Detection via bash regex: \bexec\b[^#]*2> with dangerous target
- Fixtures: clean, dirty, ignored-inline, ignored-file, broad-walk, no-toml, empty
- 17 BATS tests covering detection, ignore mechanisms, discovery, edge cases
- Self-hosting verified: task file does not self-report
- Follows or-true pattern for output format, ignore conventions, and scope
- 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.
…ts in CI

Implements KnickKnackLabs#49 — a new lint rule that detects repos with [_.codebase].lint configured but no aggregate codebase lint enforcement in CI workflows.

Key features:
- Scans workflow YAMLs for direct patterns (codebase lint "$PWD"),
  mise exec indirection, and indirect delegation via local tasks
- Warns on drift-prone hard-coded per-rule loops
- --fix mode adds aggregate enforcement step and provisions codebase CLI tooling
- Respects codebase:ignore mechanism
- 13 BATS tests across 7 fixture scenarios (direct, indirect, missing,
  hardcoded-loop, loop-only, no-config, ignored, no-workflows)

All 232 tests pass (13 ci-lint-enforcement tests at indices 45-57).
@olavostauros

Copy link
Copy Markdown
Author

Closing this stacked batch in favor of individual re-evaluation. See ricon-family/olavo#9 for context.

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