@rainstormy/preset-eslint-base v1.0.0-alpha.3
General Preset for ESLint
This package provides a predefined, opinionated ESLint configuration suitable for any TypeScript project.
Installation
Install the @rainstormy/preset-eslint-base
package and its peer dependencies:
npm install --save-dev @rainstormy/preset-eslint-base eslint typescript
pnpm install --save-dev @rainstormy/preset-eslint-base eslint typescript
yarn add --dev @rainstormy/preset-eslint-base eslint typescript
In addition to the built-in rules of ESLint, this preset configures a subset of rules from the following plugins, which are installed along with the preset package:
- eslint-plugin-eslint-comments (with rule names prefixed by
eslint-comments/
) - eslint-plugin-functional (with rule names prefixed by
functional/
) - eslint-plugin-import (with rule names prefixed by
import/
) - @limegrass/eslint-plugin-import-alias (with rule names prefixed by
import-alias/
) - eslint-plugin-no-barrel-files (with rule names prefixed by
no-barrel-files/
) - eslint-plugin-redundant-undefined (with rule names prefixed by
redundant-undefined/
) - @typescript-eslint/eslint-plugin (with rule names prefixed by
typescript/
) - eslint-plugin-unicorn (with rule names prefixed by
unicorn/
)
Usage
Create or extend a flat ESLint configuration file (eslint.config.js
) to target TypeScript files (and optionally also JavaScript files, e.g. configuration files).
For example:
import {
eslintAmbientTypeScriptModules,
eslintBase
} from "@rainstormy/preset-eslint-base"
export default [
eslintBase({ files: ["**/*.+(js|ts|tsx)"] }),
// `eslintAmbientTypeScriptModules` must follow `eslintBase` to take effect.
eslintAmbientTypeScriptModules({ files: ["**/*.d.ts"] }),
]
To override a subset of the rules configured by this preset, add an extra configuration at the end of the array to take precedence over the preset. For example:
import {
eslintAmbientTypeScriptModules,
eslintBase
} from "@rainstormy/preset-eslint-base"
export default [
eslintBase({ files: ["**/*.+(js|ts|tsx)"] }),
// `eslintAmbientTypeScriptModules` and custom configurations must follow `eslintBase` to take effect.
eslintAmbientTypeScriptModules({ files: ["**/*.d.ts"] }),
{
files: ["**/*.+(js|ts|tsx)"],
rules: {
"max-lines": "off",
"prefer-destructuring": "error",
"typescript/no-magic-numbers": "off",
"unicorn/prefer-at": "error",
},
},
]
By default, this preset assumes that the TypeScript configuration file is ./tsconfig.json
.
Use the tsconfig
option to specify a different file or set of files.
For example:
import {
eslintAmbientTypeScriptModules,
eslintBase
} from "@rainstormy/preset-eslint-base"
export default [
eslintBase({
files: ["**/*.+(js|ts|tsx)"],
tsconfig: ["./configs/tsconfig.eslint.json"],
}),
// `eslintAmbientTypeScriptModules` must follow `eslintBase` to take effect.
eslintAmbientTypeScriptModules({ files: ["**/*.d.ts"] }),
]
To exclude certain files and directories from linting, add an extra configuration at the beginning of the array. For example:
import {
eslintAmbientTypeScriptModules,
eslintBase
} from "@rainstormy/preset-eslint-base"
export default [
{
ignores: ["coverage/**", "dist/**"],
},
eslintBase({ files: ["**/*.+(js|ts|tsx)"] }),
// `eslintAmbientTypeScriptModules` must follow `eslintBase` to take effect.
eslintAmbientTypeScriptModules({ files: ["**/*.d.ts"] }),
]
Alternatively, you can avoid the need for ignore patterns altogether by explicitly listing the directories you want to include when you run ESLint from the terminal. For example:
eslint "./src/**/*.{ts,tsx}" "./*.config.{js,ts}" "./*.d.ts"