eslint-config-vladpuz-react
v2.2.1
Published
My ESLint config for React
Maintainers
Readme
eslint-config-vladpuz-react
My ESLint config for React
Features:
- Supports JavaScript, TypeScript, mixed codebases, and framework-agnostic React (pure base for use with any framework!)
- Auto fix for formatting via eslint-stylistic (targeted for use without Prettier)
- Does not conflict with TypeScript regardless of tsconfig.json options (TypeScript fully replaces some rules)
- Supports
.gitignoreby default - Ability to customize your own stylistic preferences
- Does not use other pre-configured setups, all rules are manually reviewed (except stylistic, uses a custom preset)
- No warn severity, only error
Principles:
- Safety
- Consistency
- Minimal for readability
- Stability for diff
If you don't need React, use eslint-config-vladpuz.
Installation
npm install --save-dev eslint eslint-config-vladpuz-reactUsage
Create a file eslint.config.js:
import vladpuz from 'eslint-config-vladpuz-react'
export default vladpuz()If you want to use Prettier for formatting other file types (json, md, html,
css, ...), disable Prettier for JavaScript and TypeScript files. For this,
create a file .prettierignore:
# javascript
*.js
*.jsx
*.mjs
*.cjs
# typescript
*.ts
*.tsx
*.mts
*.ctsRun ESLint in check mode:
eslint .Run ESLint in fix mode:
eslint --fix .Options
Overview:
interface Options {
filesJs?: string[] // Default - ['**/*.js', '**/*.jsx', '**/*.mjs', '**/*.cjs']
filesTs?: string[] // Default - ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts']
env?: Array<keyof typeof globals> // Default - ['builtin', 'node', 'browser']
gitignore?: boolean | GitignoreOptions // Default - true
typescript?: boolean | ParserOptions // Default - true
stylistic?: boolean | StylisticOptions // Default - true
react?: ReactSettings // Default - undefined
hooks?: HooksSettings // Default - undefined
refresh?: boolean | RefreshOptions // Default - true
}filesJs, filesTs
Type: string[]
Default for js: ['**/*.js', '**/*.jsx', '**/*.mjs', '**/*.cjs']
Default for ts: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts']
Override patterns for js and ts files:
import vladpuz, { FILES_JS, FILES_TS } from 'eslint-config-vladpuz-react'
// For example any additional extensions
export default vladpuz({
filesJs: [...FILES_JS, '**/*.extension'],
filesTs: [...FILES_TS, '**/*.extension'],
})env
Type: string[]
Default: ['builtin', 'node', 'browser']
Overrides environments providing predefined global variables:
import vladpuz from 'eslint-config-vladpuz-react'
export default vladpuz({
env: ['node'], // For example only node
})gitignore
Type: boolean | GitignoreOptions
Default: true
Enables/disables support for .gitignore or configures its search options.
import vladpuz from 'eslint-config-vladpuz-react'
export default vladpuz({
// Default gitignore config is:
gitignore: {
strict: false,
},
// You can disable gitignore:
// gitignore: false,
})typescript
Type: boolean | ParserOptions
Default: true
Enables/disables TypeScript or customizes its parser options.
import vladpuz from 'eslint-config-vladpuz-react'
export default vladpuz({
// Default typescript config is:
typescript: {
projectService: true,
ecmaFeatures: {
jsx: options.jsx,
},
},
// You can disable typescript:
// typescript: false,
})stylistic
Type: boolean | StylisticOptions
Default: true
Enables/disables Stylistic or configures your own stylistic preferences:
import vladpuz from 'eslint-config-vladpuz-react'
export default vladpuz({
// Default stylistic config is:
stylistic: {
indent: 2,
quotes: 'single',
semi: false,
},
// You can disable stylistic:
// stylistic: false,
})react
Type: ReactSettings
Default: undefined
Details: Configure Analyzer
Configures rules for react-x:
import vladpuz from 'eslint-config-vladpuz-react'
export default vladpuz({
// Example:
react: {
version: '19.2.0', // Specify the React version for semantic analysis (can be "detect" for auto-detection)
importSource: 'react', // Customize the import source for the React module (defaults to "react")
polymorphicPropName: 'as', // Define the prop name used for polymorphic components (e.g., <Component as="div">)
},
})hooks
Type: HooksSettings
Default: undefined
Details: #34497
Configures rules for react-hooks:
import vladpuz from 'eslint-config-vladpuz-react'
export default vladpuz({
// Example:
hooks: {
additionalEffectHooks: '(useMyEffect|useServerEffect)',
},
})refresh
Type: boolean | RefreshOptions
Default: true
Details: Refresh Options
Enables/disables or customizes the react-refresh plugin:
import vladpuz from 'eslint-config-vladpuz-react'
export default vladpuz({
// Default react-refresh config is:
refresh: {
allowExportNames: [],
allowConstantExport: false,
customHOCs: [],
checkJS: false,
},
// You can disable react-refresh:
// refresh: false,
})Additional
errorify(target)
Converts severity of rules warn/1 to error/2.
- target (
Linter.Config[] | Linter.Config | Linter.RulesRecord)
Return: Linter.Config[] | Linter.Config | Linter.RulesRecord
Intended for adding external configs while preserving the overall severity style (without warn):
import vladpuz, { errorify } from 'eslint-config-vladpuz-react'
import x from 'eslint-plugin-x'
export default [...vladpuz(), errorify(x.configs.recommended)]getCompilerOptions(parserOptions?, force?)
Gets compiler options from tsconfig.json.
- parserOptions (
ParserOptions = {}) - Parser options for searching tsconfig.json. - force (
boolean = false) - Disables cache.
Return: CompilerOptions
Intended for dynamic management of rules depending on compiler options from tsconfig.json:
import { getCompilerOptions } from 'eslint-config-vladpuz-react'
const compilerOptions = getCompilerOptions()
console.log(compilerOptions.strict)
console.log(compilerOptions.noEmit)testPluginConfig(pluginName, pluginRules, config, recommendedRules?)
Tests plugin config via node:test.
- pluginName (
string | null) - Plugin name. - pluginRules (
Record<string, Rule.RuleModule>) - Plugin rules. - config (
Linter.Config) - Tested config. - recommendedRules (
Partial<Linter.RulesRecord> = {}) - Preset of recommended plugin rules. Will throw an error if any recommended rule is disabled in the tested configuration.
Return: void
Intended for testing plugin configs inside eslint-config-vladpuz and extended configs (e.g. eslint-config-vladpuz-react/src/configs.test.ts):
import { testPluginConfig } from 'eslint-config-vladpuz-react'
import unicorn from 'eslint-plugin-unicorn'
testPluginConfig(
'unicorn',
unicorn.rules ?? {},
{
name: 'vladpuz/unicorn',
plugins: {
unicorn,
},
rules: {
// ...
},
},
unicorn.configs.unopinionated.rules ?? {},
)FAQ
Prettier?
Why no warn severity?
ESLint Warnings Are an Anti-Pattern
Where is the list of rules?
Versioning Policy
This project follows Semantic Versioning. However, since this is just a configuration requiring opinions and many changeable components, we don't consider rule changes critical.
For complete stability, you can pin a specific version of a package:
"devDependencies": {
- "eslint-config-vladpuz-react": "^2.2.0",
+ "eslint-config-vladpuz-react": "2.2.0",
}