Skip to content

refactor: batch BATS rules — raw dispatch, python one-liner, setup-suite path, mise-run-quiet#73

Closed
olavostauros wants to merge 9 commits into
KnickKnackLabs:mainfrom
olavostauros:batch/bats-rules
Closed

refactor: batch BATS rules — raw dispatch, python one-liner, setup-suite path, mise-run-quiet#73
olavostauros wants to merge 9 commits into
KnickKnackLabs:mainfrom
olavostauros:batch/bats-rules

Conversation

@olavostauros

@olavostauros olavostauros commented Jun 26, 2026

Copy link
Copy Markdown

Summary

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

Consolidates 4 BATS-related lint rules (supersedes #68, #65, #61, #64). Includes the shiv-plugin rule (#60) which shipped inside #61.

Rules included

Rule Issue Description
bats-raw-mise-dispatch #38 Flag mise run in BATS test bodies
bats-python-one-liner #47 Flag Python one-liners in BATS tests
bats-setup-suite-path #55 Enforce setup_suite.bash path conventions
mise-run-quiet #42 Require --quiet flag on mise run in tasks

Commits

Commit Description
dbd4e79 feat(lint): add bats-raw-mise-dispatch rule
e239d4a chore: compact test section comments
698f42e feat: add bats-python-one-liner lint rule (#47)
6813143 style: collapse 3-line section comment blocks
c03a0d3 feat: add bats-setup-suite-path lint rule
069e743 feat: add mise-run-quiet lint rule (#42)
4c3408e style: collapse 3-line section comment blocks

Validation

  • mise run test — 289 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
… test bodies

Flag raw `mise run` invocations in BATS test files — tests should call
the tool wrapper (`notes lock`) instead of reconstructing the dispatch
path inline. Complements the existing `bats-test-helper` rule (which
catches direct script invocation) by catching the converse anti-pattern.

Detection scope:
- `mise run <task>` at statement boundaries (line start, after `|`,
  `||`, `&&`, `;`, `(`, `{`, `exec`, `run`)
- `mise -C <dir> run <task>` — remote/targeted dispatch
- Correctly skips patterns inside quoted strings (grep, test descriptions)
- Allowlists test_helper.bash/helpers.bash for wrapper definitions

Known limitation: `bash -c '... mise run ...'` wraps the dispatch in a
quoted string, making it indistinguishable from grep patterns at the
line-scanning level. Not flagged in this implementation.

Closes KnickKnackLabs#38
Detect unreadable Python assertion one-liners (`python3 -c "...assert..."`)
in BATS test files. Prefer heredoc Python scripts for readability.

Closes KnickKnackLabs#47
Adds bats-setup-suite-path lint rule that flags test/setup_suite.bash
files calling `mise env` without preserving BATS_LIBEXEC first. BATS
1.13.0 relies on libexec path resolution; mise env can rewrite PATH
and drop bats's libexec directory, causing 'bats-exec-file: command
not found' before any tests run.

Follows established file-discovery + scan pattern. ShellCheck-clean
(SC2016 excluded on intentional code-snippet echo lines).

Implements KnickKnackLabs#55 (KnickKnackLabs/codebase)
@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