@rainstormy/presets-eslint v1.0.0-rc.0
General Preset for ESLint
This package provides a predefined, opinionated ESLint configuration suitable for any TypeScript project.
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/
)
Installation
Install the @rainstormy/presets-eslint
package and its peer dependencies:
npm install --save-dev @rainstormy/presets-eslint eslint typescript
pnpm install --save-dev @rainstormy/presets-eslint eslint typescript
yarn add --dev @rainstormy/presets-eslint eslint typescript
Usage
Create or extend a flat ESLint configuration file (eslint.config.js
) and export the result of eslintPresets
as the configuration object.
For example (with the default options in comments):
import {
eslintPresetAmbientTypeScriptModules,
eslintPresets,
} from "@rainstormy/presets-eslint"
export default eslintPresets({
// targetFilePatterns: ["**/*.@(js|jsx|ts|tsx)"],
// tsconfigFiles: "closest-to-each-source-file",
additionalPresets: [
eslintPresetAmbientTypeScriptModules({
// targetFilePatterns: ["**/*.d.ts"],
}),
],
})
Override Rules
To override some rules or to install additional plugins, use the spread syntax (...
) to add a custom configuration object after the preset configuration object.
For example:
import { eslintPresets } from "@rainstormy/presets-eslint"
export default [
...eslintPresets({
// ...options...
}),
{
files: ["**/*.@(js|jsx|ts|tsx)"],
rules: {
"max-lines": "off",
"prefer-destructuring": "error",
"typescript/no-magic-numbers": "off",
"unicorn/prefer-at": "error",
},
},
]
Custom tsconfig.json
Location
By default, ESLint uses the TypeScript configuration file (tsconfig.json
) that is located closest to each source file being linted.
Use the tsconfigFiles
option to specify a different TypeScript configuration file or set of files.
For example:
import { eslintPresets } from "@rainstormy/presets-eslint"
export default eslintPresets({
tsconfigFiles: ["./tsconfig.eslint.json"],
// ...other options...
})
Ignore Files and Directories
To exclude certain files and directories entirely from linting, use the spread syntax (...
) to add a custom configuration before the preset configuration object.
For example:
import { eslintPresets } from "@rainstormy/presets-eslint"
export default [
{
ignores: ["coverage/**", "dist/**"],
},
...eslintPresets({
// ...options...
}),
]
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 (i.e. opting in to linting instead of opting out).
For example:
eslint "./src/**/*.{ts,tsx}" "./*.config.{js,ts}" "./*.d.ts"
3 months ago