@mdor/eslint-config
v0.0.3
Published
Shared ESLint flat configuration for MDOR JavaScript projects
Downloads
27
Maintainers
Readme
@mdor/eslint-config
Shared ESLint flat configuration for JavaScript and TypeScript projects. The package is written in JavaScript, has no build output, and combines Perfectionist, RegExp, SonarJS, and Unicorn rules in one JavaScript configuration object. It does not configure framework-specific plugins. It is ESM-only and ships TypeScript declarations.
Requirements
- Node.js 22.13 or newer
- npm 10 or newer
- ESLint 10.8 or newer within the 10.x release line (
^10.8.0) - TypeScript 5.5.4 or newer within the supported range
Install
npm install --save-dev @mdor/eslint-configESLint, TypeScript ESLint, TypeScript, and the other four plugins are peer dependencies because the consuming project owns their versions. npm 7 and newer installs compatible peers automatically when needed. Package managers configured not to install peers automatically require the peer dependencies explicitly.
npm install --save-dev eslint@^10.8.0 eslint-plugin-perfectionist@^5.10.1 eslint-plugin-regexp@^3.1.1 eslint-plugin-sonarjs@^4.2.0 eslint-plugin-unicorn@^73.0.0 typescript typescript-eslint@^8.67.0Use
// eslint.config.js
import mdorConfig from "@mdor/eslint-config";
export default mdorConfig;Add project-specific settings by composing the exported array:
// eslint.config.js
import mdorConfig from "@mdor/eslint-config";
export default [
...mdorConfig,
{
files: ["scripts/**/*.js"],
rules: {
"no-console": "off",
},
},
];The named eslintConfig export references the same flat-config array.
Plugin examples
Use the complete preset
The default export enables the shared rules and all five plugins for JavaScript, JSX, TypeScript, and TSX files:
// eslint.config.js
import mdorConfig from "@mdor/eslint-config";
export default [
...mdorConfig,
{
rules: {
// Project overrides go last and therefore take precedence.
"perfectionist/sort-imports": "off",
"unicorn/prefer-at": "warn",
"sonarjs/cognitive-complexity": ["error", 25],
"@typescript-eslint/no-explicit-any": "warn",
},
},
];Override plugins for specific files
Flat-config entries are applied in order. Put file-specific exceptions after the shared preset:
// eslint.config.js
import mdorConfig from "@mdor/eslint-config";
export default [
...mdorConfig,
{
files: ["tests/**/*.js"],
rules: {
"perfectionist/sort-objects": "off",
"sonarjs/no-duplicate-string": "off",
"unicorn/no-null": "off",
},
},
{
files: ["scripts/**/*.cjs"],
rules: {
"unicorn/prefer-module": "off",
},
},
];Enable or tune individual rules
Rules use their standard plugin prefixes:
// eslint.config.js
import mdorConfig from "@mdor/eslint-config";
export default [
...mdorConfig,
{
rules: {
// Consistent natural ordering.
"perfectionist/sort-imports": "error",
"perfectionist/sort-named-imports": "error",
// RegExp correctness and performance.
"regexp/no-dupe-characters-character-class": "error",
"regexp/no-super-linear-backtracking": "error",
// Maintainability and bug detection.
"sonarjs/cognitive-complexity": ["warn", 20],
"sonarjs/no-identical-functions": "error",
// Modern JavaScript conventions.
"unicorn/prefer-at": "error",
"unicorn/prefer-node-protocol": "error",
},
},
];For example, these plugins can sort imports and objects naturally, report
duplicate regular-expression characters, detect catastrophic backtracking risks,
find duplicated or overly complex functions, and flag older JavaScript patterns
such as items[items.length - 1].
Public API
- The default and named
eslintConfigexports contain the complete flat-config array.
Plugin-specific configuration objects are intentionally not exported. All plugin registrations, settings, and rules are consolidated into the preset's single JavaScript and TypeScript configuration object.
Scope
The preset applies to .js, .mjs, .cjs, .jsx, .ts, .mts, .cts, and
.tsx files. It parses JavaScript and TypeScript without requiring type-aware
linting or a tsconfig.json. It enables correctness and bug-prevention rules,
treats unused ESLint disable comments as errors, and ignores common generated
directories. It also enables TypeScript ESLint's recommended rules, natural ordering from
eslint-plugin-perfectionist, recommended RegExp and SonarJS rules, and selected
Unicorn rules. Formatting rules unrelated to statement ordering are intentionally
left to Prettier.
Rules that require TypeScript type information are disabled in this portable
preset. Consumers that want rules such as no-floating-promises or
no-confusing-void-expression should add a project-specific type-aware config
with parserOptions.projectService: true after this preset.
Runtime enforcement
The package declares Node.js and npm requirements through engines. npm reports
incompatible consumer environments and rejects them when engine-strict=true.
The matching devEngines policy uses onFail: "error" when this package is
developed directly with npm.
Activate the repository runtime before running package commands:
nvm use 22.13.0Validate and release
npm run typecheck --workspace @mdor/eslint-config
npm test --workspace @mdor/eslint-config
npm pack --workspace @mdor/eslint-config --dry-run
npm run release-patch-try --workspace @mdor/eslint-configPublishing requires npm authentication with access to the @mdor organization.
