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 --nest=false --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. - Applies the appropriate
package.jsonrule when NestJS is selected.
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,
packageJsonRequireType: false,
},
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. |
json.packageJsonRequireType |
true |
Requires a type field in package.json. |
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.
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