@perfective/eslint-config provides
a shareable ESLint configuration
that is used for the development of the @perfective packages.
These rules are primarily configured for TypeScript projects.
In addition to the core ESLint,
@typescript-eslint,
and ESLint Stylistic plugin rules,
@perfective/eslint-config includes configurations for the ESLint plugins:
-
eslint-plugin-cypress(optional); -
eslint-plugin-jest(optional); -
eslint-plugin-jest-dom(optional); -
eslint-plugin-rxjs-x(optional); -
eslint-plugin-testing-library(optional);
To simplify configuring ESLint support in the IDEs and editors,
the severity of all fixable rules is a warning.
In addition, it allows distinguishing errors that have to be fixed manually
from issues that will be fixed automatically.
|
Important
|
@perfective/eslint-config only support ES module syntax.
If your project uses CommonJS by default
you need to use eslint.config.mjs file instead of eslint.config.js to run it in ESM mode.
|
-
Install
@perfective/eslint-configas a dev dependency:npm install --save-dev @perfective/eslint-config
Required peer dependencies are installed automatically.
-
Import
perfectiveEslintConfigtoeslint.config.js.import { perfectiveEslintConfig } from '@perfective/eslint-config'; const eslintConfig = perfectiveEslintConfig(); export default eslintConfig;
-
Optional Install optional peer dependencies to add tool-specific linting rules.
npm install --save-dev \ eslint-plugin-cypress \ eslint-plugin-jest \ eslint-plugin-jest-dom \ eslint-plugin-rxjs-x \ eslint-plugin-testing-libraryImport configurations to
eslint.config.js.import { perfectiveEslintConfig } from '@perfective/eslint-config'; // Optional dependencies. import { cypressConfig } from '@perfective/eslint-config/cypress'; import { jestConfig } from '@perfective/eslint-config/jest'; import { jestDomConfig } from '@perfective/eslint-config/jest-dom'; import { rxjsConfig } from '@perfective/eslint-config/rxjs'; import { testingLibraryConfig } from '@perfective/eslint-config/testing-library'; const eslintConfig = perfectiveEslintConfig([ cypressConfig, jestConfig, jestDomConfig, rxjsConfig, testingLibraryConfig, ]); export default eslintConfig;
-
Optional Customize configuration rules in
eslint.config.jsimport { perfectiveEslintConfig, typescriptFiles } from '@perfective/eslint-config'; // (1) const eslintConfig = perfectiveEslintConfig([ // ...Optional configurations... { // These rules are overridden to all files rules: { '@stylistic/indent': ['warn', 2], }, }, { // These rules are overridden to TypeScript files only files: typescriptFiles, rules: { '@stylistic/indent': ['warn', 4], }, }, ]); export default eslintConfig;
-
See the list of available globs below.
-
|
Note
|
*.d.ts files and dist directories are ignored by the configuration.
node_modules and dot-files are ignored by the eslint.
If more directories or file types need to be ignored, see the
.eslintignore file docs.
|
Some rules have complex configuration objects or arrays that are not merged but are completely overridden by ESLint. Therefore, it requires copying and pasting a rule config instead of just extending it. Maintaining rules updates is challenging and is simplified by the custom config functions.
These functions and related types are exported from the subpackages
and match the rule name in camelCase.
If you need an extended configuration,
you can use these functions in the eslint.config.js file:
import perfectiveEslintConfig from '@perfective/eslint-config';
import { simpleImportSortImports } from '@perfective/eslint-config/simple-import-sort'; // (1)
const eslintConfig = perfectiveEslintConfig([
// ...Optional configurations...
{
rules: {
'simple-import-sort/imports': ['warn', simpleImportSortImports([
'@perfective',
])],
},
},
]);
export default eslintConfig;-
Framework-specific packages, based on
@perfective/eslint-config, re-export all the rules. So rules should be required from those packages for correctnode_modulesresolution.
The following is the list of available packages and their exports.
-
perfectiveEslintConfig— a function that creates an array of flat configs. -
type Glob = stringa nominal type for glob patterns.-
javascriptFiles: Glob[]— a list of glob patterns for JS and JSX files. -
jsxFiles: Glob— a glob pattern for JSX files. -
typescriptFiles: Glob[]— a list of glob patterns for TypeScript source files. -
tsxFiles: Glob— a glob pattern for TSX files. -
typescriptDeclarationFiles: Glob— a glob pattern for TypeScript declaration files. -
configurationFiles: Glob— a glob pattern for JavaScript tools configuration files. -
jestFiles: Glob[]— the default glob patterns Jest uses to find test files. -
cypressFiles: Glob— the default glob pattern Cypress uses to load test files.
-
-
ESLint language options:
-
languageOptions(): Linter.LanguageOptions— creates ESLintlanguageOptionsobject for all files. -
javascriptLanguageOptions(): Linter.LanguageOptions— creates ESLintlanguageOptionsobject for JavaScript files. -
typescriptLanguageOptions(): Linter.LanguageOptions— creates ESLintlanguageOptionsobject for TypeScript files.
-
-
type LinterConfig = Linter.Config | (() ⇒ Linter.Config)— an ESLint flat config or a function that returns one.-
linterConfig(config: LinterConfig): Linter.Config— a function to instantiate ESLint flat config.
-
-
Optional plugins:
-
hasEslintPlugin— returns true if a given ESLint plugin exists. -
optionalRule(rule: string, config: unknown): Record<string, unknown>— returns an object with rule as a key and its config as a value, if a given rule belongs to an installed ESLint plugin.
-
-
cypressConfig(files: Glob[] = [cypressFiles]): Linter.Config— creates a flat config foreslint-plugin-cypressfor a given list of files globs. Overrides some rules forperfectiveEslintConfigfor compatibility with Cypress.
-
interface ImportNoExtraneousDependencies— configuration options for theimport/no-extraneous-dependenciesrule.-
importNoExtraneousDependencies(overrides: Partial<ImportNoExtraneousDependencies> = {}): ImportNoExtraneousDependencies— returns configuration options for theimport/no-extraneous-dependenciesrule.
-
-
jestConfig(files: Glob[] = jestFiles): Linter.Config— creates a flat config foreslint-plugin-jestfor a given list of files globs.
-
jestDomConfig(files: Glob[] = jestFiles): Linter.Config— creates a flat config foreslint-plugin-jest-domfor a given list of files globs.
-
rxjsConfig(files: Glob[] = typescriptFiles): Linter.Config— creates a flat config foreslint-plugin-rxjs-xfor a given list of files globs.
-
interface SimpleImportSortImports— configuration options for thesimple-import-sort/importsrule.-
simpleImportSortImports(internal: string[] = []): SimpleImportSortImports— creates configuration for thesimple-import-sort/importsESLint rule. Allows to spliceinternalscope packages imports between the global and relative imports.
-
-
testingLibraryConfig(files: Glob[] = jestFiles): Linter.Config— creates a flat config foreslint-plugin-testing-libraryfor a given list of files globs.
-
interface TypescriptEslintNamingConvention— configuration options for the@typescript-eslint/naming-conventionrule.-
type TypescriptEslintNamingConventionSelector— values for the@typescript-eslint/naming-conventionruleselectoroption.-
type TypescriptEslintNamingConventionIndividualSelector— values for individual selectors for the@typescript-eslint/naming-conventionruleselectoroption. -
type TypescriptEslintNamingConventionGroupSelector— values for grouped of individual selectors for the@typescript-eslint/naming-conventionruleselectoroption.
-
-
type TypescriptEslintNamingConventionFormat— values for the@typescript-eslint/naming-conventionruleformatoption. -
type TypescriptEslintNamingConventionUnderscore— values for the@typescript-eslint/naming-conventionruleleadingUnderscoreandtrailingUnderscoreoptions. -
function typescriptEslintNamingConvention(extensions: TypescriptEslintNamingConvention[] = []): TypescriptEslintNamingConvention[]— creates configuration with the given extensions for the@typescript-eslint/naming-conventionrule.
-
-
interface UnicornPreventAbbreviations— configuration options for theunicorn/prevent-abbreviationrule.-
type UnicornPreventAbbreviationReplacements— nominal type for thereplacementsoption of theunicorn/prevent-abbreviationrule. -
function unicornPreventAbbreviations( replacements: UnicornPreventAbbreviationReplacements = {}, options: Partial<Pick<UnicornPreventAbbreviations, 'checkProperties'>> = {}): UnicornPreventAbbreviations— creates configuration for theunicorn/prevent-abbreviationrule with the given replacements and options.
-