Skip to content

chore(cli): add migration-self-contained lintoko example rule#594

Merged
Kamirus merged 4 commits into
mainfrom
chore/migration-self-contained-lint-rule
Jun 26, 2026
Merged

chore(cli): add migration-self-contained lintoko example rule#594
Kamirus merged 4 commits into
mainfrom
chore/migration-self-contained-lint-rule

Conversation

@Kamirus

@Kamirus Kamirus commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Enhanced migration chains stay maintainable when each file is self-contained — importing packages (mo:…), canisters (canister:…), etc., but not sibling .mo modules. This adds a copyable migration-self-contained lintoko example rule that flags relative module imports in migrations/, aligned with the Motoko compiler's Url.Relative classification (import paths without :).

Before: no example rule for local imports in migration files.

After: with [lint.extra] configured:

"migrations/**" = ["lint/migration-self-contained"]
$ mops lint
  × [ERROR]: migration-self-contained
   ╭─[migrations/20250101_000000_Init.mo:3:14]
 2 │ import Backend "canister:backend";
 3 │ import Types "../src/Types";
   ·              ───────┬──────
   ·                     ╰── Migration files must not import local modules (relative paths). Got: "../src/Types"

The rule uses #match? @path "^\"[^:]*\"$" so any new compiler URL scheme (with :) is allowed without updating the rule.

blob:file: imports are out of scope — the compiler classifies those as FileValue, not Relative.

Made with Cursor

Enhanced migration files should not import sibling .mo modules — only
package/canister URLs. Add an example lint rule matching the compiler's
Url.Relative classification (paths without a colon).

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Cursor AI review

👍 APPROVE — looks safe to merge

Category Assessment Details
Summary Adds a migration-self-contained lintoko example rule under cli/tests/lint-extra-example-rules/, with a migration fixture, [lint.extra] wiring, and snapshot coverage in the existing example-rules test. No production CLI, backend, or docs changes.
Code Quality Follows the existing example-rule fixture pattern; the tree-sitter query is minimal and matches the stated Url.Relative heuristic (no : in import path).
Consistency Aligns with sibling rules in lint-extra-example-rules and extends the existing snapshot test rather than adding redundant coverage.
Security Test-only changes; no auth, signing, registry, or package-integrity paths touched.
Tests Snapshot update is targeted to the new rule output (3 violations on relative imports; mo: and canister: imports pass).
Maintainability Rule includes includes = ["**/migrations/**"] so it stays copyable as a standalone rule; changelog/docs/skills updates are not required for internal test fixtures.

Verdict

Decision: APPROVE
Risk: Very Low
Reason: This is a contained test-fixture addition with no user-facing CLI or runtime behavior changes. The lint rule logic and snapshot expectations are consistent with the PR’s intent and existing [lint.extra] test patterns.


Generated for commit b042819

@Kamirus Kamirus enabled auto-merge (squash) June 26, 2026 07:49
@Kamirus Kamirus merged commit 19849d5 into main Jun 26, 2026
26 checks passed
@Kamirus Kamirus deleted the chore/migration-self-contained-lint-rule branch June 26, 2026 07:57
Kamirus added a commit that referenced this pull request Jun 26, 2026
…tions/*.mo (#599)

Follow-up to [#594](#594).

The `migration-self-contained` example rule used `**/migrations/**` for
both lintoko `includes` and `[lint.extra]`, which could match any
`migrations` directory anywhere in the tree and recurse into subfolders.
Projects using enhanced migrations keep a flat `migrations/*.mo` chain
(as configured via `chain = "migrations"` in `mops.toml`), so the
example should mirror that layout.

**Before**

```toml
# migration-self-contained.toml
includes = ["**/migrations/**"]

# mops.toml
[lint.extra]
"migrations/**" = ["lint/migration-self-contained"]
```

**After**

```toml
# migration-self-contained.toml
includes = ["migrations/*.mo"]

# mops.toml
[lint.extra]
"migrations/*.mo" = ["lint/migration-self-contained"]
```

If your chain path differs (e.g. `backend/migrations`), set both
`includes` and `[lint.extra]` to that path with `/*.mo`.

## What is unchanged

No CLI behavior change — only the `lint-extra-example-rules` test
fixture. No CHANGELOG entry.

Made with [Cursor](https://cursor.com)

Co-authored-by: Cursor <cursoragent@cursor.com>
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