Skip to content

feat(lint): add bats-raw-mise-dispatch rule — flag 'mise run' in BATS test bodies (#38)#68

Open
olavostauros wants to merge 2 commits into
KnickKnackLabs:mainfrom
olavostauros:feat/bats-raw-mise-dispatch
Open

feat(lint): add bats-raw-mise-dispatch rule — flag 'mise run' in BATS test bodies (#38)#68
olavostauros wants to merge 2 commits into
KnickKnackLabs:mainfrom
olavostauros:feat/bats-raw-mise-dispatch

Conversation

@olavostauros

@olavostauros olavostauros commented Jun 24, 2026

Copy link
Copy Markdown

Summary

Add a lint rule that flags 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 via bash .mise/tasks/foo) by catching the converse anti-pattern: using mise run in test bodies instead of the wrapper function.

Both converge on the same principle from fold bats-tool-testing.md ('Call the Tool, Not the Script').

Detection

  • 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 patterns, printf, test descriptions) via odd-quote-count heuristic
  • Allowlists test_helper.bash / helpers.bash as canonical wrapper definition files
  • Excludes */fixtures/* paths (lint-rule synthetic inputs)

Known limitation

bash -c '... mise run ...' wraps the dispatch in a quoted string, making it indistinguishable from grep -q '... mise run ...' at the line-scanning level. Not flagged in this implementation — documented in tests.

Fixtures (6 scenarios)

Fixture Expectation
clean wrapper-based tests, passes
dirty run mise run -q lock, flagged
dirty-bash-c bash -c '... mise run ...', known limitation
ignored-inline inline # codebase:ignore, passes
ignored-repo codebase:ignore in mise.toml, skips
empty no test/ dir, passes

Self-hosting

The codebase repo itself passes cleanly after adding inline ignores to two exec mise run test fixture lines in caller-pwd-contract.bats (these define wrapper scripts inside multi-line test strings, not test dispatch).

Validation

  • mise run test — all 230 tests pass (12 new + 218 existing)
  • codebase lint "$PWD" — self-hosting passes
  • readme build --check — N/A (codebase does not use README.tsx)
  • git diff --check — clean

Fixes #38

… 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
@olavostauros olavostauros changed the title feat(lint): add bats-raw-mise-dispatch rule — flag 'mise run' in BATS test bodies feat(lint): add bats-raw-mise-dispatch rule (#38) — flag 'mise run' in BATS test bodies Jun 24, 2026
@olavostauros olavostauros changed the title feat(lint): add bats-raw-mise-dispatch rule (#38) — flag 'mise run' in BATS test bodies feat(lint): add bats-raw-mise-dispatch rule — flag 'mise run' in BATS test bodies (#38) Jun 24, 2026
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: flag raw mise dispatch in BATS tests

1 participant