Skip to content

feat(cli): add [lint.extra] for per-file lint rules#476

Open
Kamirus wants to merge 7 commits intomainfrom
feat/lint-extra
Open

feat(cli): add [lint.extra] for per-file lint rules#476
Kamirus wants to merge 7 commits intomainfrom
feat/lint-extra

Conversation

@Kamirus
Copy link
Copy Markdown
Collaborator

@Kamirus Kamirus commented Apr 8, 2026

Problem

All lint rules currently apply uniformly to every .mo file in a project. There's no way to enforce file-specific constraints — e.g. "Types.mo must only contain type declarations" or "migration files must not expose public functions other than migration()" — without maintaining separate lintoko invocations outside of mops lint.

Solution

Add a [lint.extra] section to mops.toml that maps file globs to additional rule directories:

[lint.extra]
"src/main.mo" = ["lint/no-types"]
"src/Types.mo" = ["lint/types-only"]
"migrations/*.mo" = ["lint/migration-only", "lint/no-types"]

Each entry triggers a separate lintoko invocation on matched files, in addition to the base rules that always run on all files.

Design decisions

  • Run all, then fail — all runs (base + extra) execute even when earlier runs find errors, so users see every lint failure in a single pass
  • --rules CLI flag only affects the base run[lint.extra] entries always run independently, keeping CLI overrides scoped to the main rule set
  • Filter intersectionmops lint <filter> scopes extra runs to the same file set as the base run (no surprising out-of-scope linting)
  • Missing rule dir → hard error; no matched files → warning and skip
  • [lint] args and CLI extra args are forwarded to all runs (base + extra) via a shared buildCommonArgs helper
  • Success message deferred — "Lint succeeded" only printed after all runs pass

Test plan

  • All 11 lint tests pass (6 existing + 5 new snapshot tests)
  • Pre-commit hooks pass (prettier, eslint, tsc, svelte-check)
  • Manual smoke test: validated example tree-sitter queries (no-types, types-only, migration-only) against real Motoko files with lintoko 0.7.0
  • Verified run-all behavior: base failure does not prevent extra runs from executing

Kamirus added 5 commits April 8, 2026 10:30
Enable per-file lint rule sets via a new `[lint.extra]` config section
in mops.toml. Each entry maps a file glob to additional rule directories,
triggering separate lintoko invocations on matched files alongside the
base rules that always run on all files.

Made-with: Cursor
Replace per-fixture symlinks with relative paths in mops.toml
pointing to ../_shared-rules. Symlinks remain only for dirs
discovered by convention (lints/, rules/) that can't be configured.

Made-with: Cursor
Point new test fixtures to ../lint/lints in mops.toml instead of
maintaining a separate _shared-rules directory. Pre-existing test
fixtures are restored to their original state (zero diff).

Made-with: Cursor
Merge 9 fixture directories into 4. Use snapshot tests to capture
verbose lintoko output for the interesting cases (extra fail, edge
cases, base+extra, --rules isolation with multi-rules).

Made-with: Cursor
@Kamirus Kamirus marked this pull request as ready for review April 9, 2026 09:58
@Kamirus Kamirus requested a review from a team as a code owner April 9, 2026 09:58
Kamirus added 2 commits April 9, 2026 13:49
- runLintoko returns boolean instead of calling cliError on lint failure;
  failures accumulate across base + extra runs so users see all errors
  in a single pass
- Fix types-only example query (use @filter allowlist instead of
  blacklisting individual node kinds)
- Add lint-extra-example-rules test fixture with no-types, types-only,
  and migration-only rules validated against real Motoko files
- Make no-match glob warning unconditional (consistent with other warns)
- Remove lintoko rule examples from mops docs (lintoko's domain)
- Clarify that [lint] args applies to all runs (base + extra)

Made-with: Cursor
@Kamirus Kamirus requested a review from rvanasa April 9, 2026 13:12
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