Built-in rules
enforceVariants
Section titled “enforceVariants”Checks the resolved variant against package.json, TypeScript configs, additional JSON files, and text files.
import { defineConfig, enforceVariants } from "monoswan";
export default defineConfig({ rules: [enforceVariants()],});sortPackageJson
Section titled “sortPackageJson”Checks package.json property order and provides an autofix. The default follows common package.json ordering and alphabetizes dependency groups. This is defined in DEFAULT_PACKAGE_JSON_SORT_OPTIONS.
Sorting options support alphabetical, fixed, custom, and none orders. Use children for nested values and overrides for named properties.
alphabeticalcompares keys or string-array entries lexicographically.fixedrequires akeysarray. Listed keys appear first in that order; unlisted keys follow usingfallbackCompare, which defaults to alphabetical order.customrequires acompare(keyA, keyB)function.nonedisables sorting at that location.childrenapplies one sorting rule recursively to child values.overridesassigns a different rule to a named property and takes precedence overchildren.
The default orders common package fields, sorts dependency groups and scripts alphabetically,
and sorts selected string arrays such as files, keywords, and bundled dependencies. Its
autofix rewrites package.json with tab indentation and a trailing newline. Import
DEFAULT_PACKAGE_JSON_SORT_OPTIONS to extend or inspect the complete default.
sortPackageJson({ order: "fixed", keys: ["name", "version", "private"], fallbackCompare: (left, right) => left.localeCompare(right), overrides: { scripts: { order: "alphabetical" }, },});import { defineConfig, sortPackageJson } from "monoswan";
export default defineConfig({ rules: [sortPackageJson()],});requireMonoswanConfig
Section titled “requireMonoswanConfig”Requires a package-level monoswan config. Set requireVariant: true to require at least one selected variant. Missing config has an autofix that creates monoswan.json.
import { defineConfig, requireMonoswanConfig } from "monoswan";
export default defineConfig({ rules: [requireMonoswanConfig({ requireVariant: true })],});