An opinionated ESLint flat config for TypeScript-first projects, with built-in support for React, Vue, Node.js, JSON, YAML, TOML, Tailwind CSS, UnoCSS, and formatting rules.
- Type-aware TypeScript rules powered by
typescript-eslint. - React, Vue, Node.js, import, stylistic, and RegExp rules out of the box.
- Linting for JSON, JSONC, JSON5,
package.json, YAML, and TOML files. - Prettier-powered formatting for HTML, CSS, SCSS, Less, GraphQL, XML, and SVG.
- Automatic Tailwind CSS and UnoCSS integration when detected in the project.
- Interactive CLI for creating or migrating an ESLint setup.
Rows marked as Planned are not wired into the current published config yet.
- Node.js
^22.23.1 || >=24 - ESLint
^10.5.0 - ESM package consumption
Run the wizard from the project root:
pnpm dlx @dhzh/eslint-config@latestThe wizard can also run non-interactively by passing answers as flags:
pnpm dlx @dhzh/eslint-config@latest --replace-lint=true --replace-lint-fix=trueBoolean flags without a value mean true; use --flag=false or --no-flag for false. If a flag is omitted, its corresponding prompt remains interactive.
The wizard:
- Adds the required development dependencies and lint scripts to
package.json. - Creates
eslint.config.jsfor ESM packages oreslint.config.mjsotherwise. - Configures ESLint as the formatter in
.vscode/settings.json. - Adds flat config files to
.npmignore.
Then install the updated dependencies and lint the project:
pnpm install
pnpm lint-fixImportant
The wizard overwrites the target ESLint config file. Back up an existing config before running it.
Install the package with ESLint:
pnpm add -D eslint @dhzh/eslint-configCreate eslint.config.mjs:
import { defineConfig } from '@dhzh/eslint-config';
export default defineConfig();defineConfig() accepts additional ignore patterns, a source type, and options for each included config:
import { defineConfig } from '@dhzh/eslint-config';
export default defineConfig({
ignorePatterns: ['**/generated/**'],
sourceType: 'module',
configs: {
typescript: {
typeSafe: true,
strict: true,
overrides: {
'@typescript-eslint/no-explicit-any': 'warn',
},
},
react: {
language: 'typescript',
overrides: {
hooks: {
'react-hooks/exhaustive-deps': 'warn',
},
},
},
json: {
indent: 2,
},
yml: {
quotes: 'double',
},
imports: {
closeOrder: false,
},
format: {
enable: {
html: true,
css: true,
graphql: false,
xml: false,
svg: false,
},
customPrettierOptions: {
printWidth: 100,
},
},
},
});| Option | Default | Description |
|---|---|---|
ignorePatterns |
[] |
Additional patterns appended to the built-in ignores. |
sourceType |
'module' |
Use 'module' or 'commonjs' for source files. |
react.language |
'typescript' |
Selects the TypeScript or JavaScript React preset. |
typescript.typeSafe |
false |
Keeps unsafe TypeScript rules disabled unless enabled. |
typescript.strict |
false |
Keeps selected strict rules disabled unless enabled. |
json.indent |
2 |
Sets JSON, JSONC, and JSON5 indentation. |
imports.closeOrder |
true |
Set to false to enable simple-import-sort. |
format.enable |
All formats enabled | Accepts false to disable formatting. When passing an object, explicitly enable each desired format. |
format.customPrettierOptions |
{} |
Overrides the shared Prettier options. |
yml.indent / toml.indent |
2 |
Sets YAML or TOML indentation. |
yml.quotes |
'single' |
Selects single or double quotes for YAML. |
overrides |
{} |
Overrides rules after the corresponding preset is applied. |
React, JSON, and disable configs expose grouped overrides for their individual rule sets. See src/types/index.ts for the complete option types.
The package-json/require-type rule is enabled by default for non-NestJS projects and NestJS 12 or later. It is disabled automatically for older NestJS projects. In a workspace, the oldest detected @nestjs/core or @nestjs/common major version determines the behavior for the entire repository.
Override the automatic behavior through the package.json rule overrides when needed:
export default defineConfig({
configs: {
json: {
overrides: {
packageJson: {
'package-json/require-type': 'off',
},
},
},
},
});Tailwind CSS and UnoCSS rules are enabled automatically when tailwindcss or unocss is installed in the project.
XML and SVG formatting works out of the box because @prettier/plugin-xml is included as a dependency.
MIT License © 2022 Lyle Zheng