Skip to content

Linting

monoswan checks your monorepo against rules and structures that you can configure.

Package selection follows a fixed pipeline: workspace patterns establish membership, the command path narrows the selected packages, the root ignore configuration skips packages globally, and rule-level ignores skip individual rules. Ignore configuration does not alter workspace membership.

Run monoswan lint . to run in your current working directory.

Run monoswan lint . --fix to automatically fix any autofixable issues.

We recommend putting monoswan lint scripts in your package.json, and running these as part of any pre-commit hooks.

Root package.json

package.json
"scripts": {
"monoswan": "monoswan lint .",
"monoswan:fix": "monoswan lint . --fix"
}

Rules inspect each discovered package and return any issues they find. Add them to the root configuration.

monoswan.config.ts
import { defineConfig, enforceVariants, requireMonoswanConfig, sortPackageJson } from "monoswan";
export default defineConfig({
rules: [requireMonoswanConfig({ requireVariant: true }), enforceVariants(), sortPackageJson()],
});

Each rule receives the package name, path, package.json, and resolved variant. Issues can include a file location and an autofix. Rules without options can be called with no arguments.

You may want to turn off monoswan rules for certain workspace packages. monoswan supports both paths and packages ignore lists. Both ignore lists support glob patterns.

You can ignore certain packages for the entire lint operation. A matching path or package name is not checked by any lint rule, but remains a discovered workspace package.

monoswan.config.ts
import { defineConfig, sortPackageJson } from "monoswan";
export default defineConfig({
rules: [sortPackageJson()],
ignore: { packages: ["@monorepo/legacy-lib"] },
});

You can also ignore packages for specific rules. A matching path or package name skips the rule.

monoswan.config.ts
import { defineConfig, sortPackageJson } from "monoswan";
export default defineConfig({
rules: [
sortPackageJson(undefined, {
ignore: { paths: ["packages/legacy/**"] },
}),
],
});

Path globs are matched against forward-slash paths relative to the workspace root containing the nearest monoswan configuration. They do not start with ./, so use packages/legacy/**, not ./packages/legacy/**. Package globs are matched separately against the package’s name. A match in either list is sufficient to skip the package.

Since monoswan works at the repository level, linting tasks should be configured as root tasks for turborepo.

turbo.json
{
"$schema": "https://turborepo.com/schema.json",
"tasks": {
"//#monoswan": {},
"//#monoswan:fix": {
"cache": false
}
}
}