Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Linter

Also part of m2-ls, and on the command line as m2-lint.

Rules come in four groups:

  • X, syntax: parse errors, and code that parses but means something else (L.1 is not L#1)
  • E, M2 semantics: things M2 rejects or silently ignores, like installing a method on a plain function, = where := is needed, or return outside a function
  • T, types: an if on something that can’t be Boolean, a declared return type that contradicts the code
  • S, style: unused locals, lowercase option keys, if (c) then, null checks that could be ??

A lot of them come with a quick fix. Unused locals starting with _ are fine.

Each rule has a code and a name (S02 = unused-binding); the full list is in the m2-ls README. Turn rules off or down in settings:

{ "m2-ls": { "diagnostics": { "disabled": ["S06"], "warningsAsHint": ["unused-binding"] } } }

In CI

m2-lint file.m2
m2-lint --deny-warnings --config settings.json file.m2
t.m2:2:4: warning[T02]: if condition must have type `Boolean`, but this expression has type `ZZ`

Exit code 1 on errors (or warnings, with --deny-warnings).