@eslint-react/eslint-plugin
ESLint plugin for React function components with TypeScript, built (mostly) from scratch.
Public packages
Supported engines
Node.js
- 18.x LTS Hydrogen
- 20.x Current
Bun
Installation
npm install --save-dev @eslint-react/eslint-plugin
pnpm add --save-dev @eslint-react/eslint-plugin
yarn add --dev @eslint-react/eslint-plugin
bun add --dev @eslint-react/eslint-plugin
Usage
module.exports = {
root: true,
env: { browser: true, es2021: true },
parser: "@typescript-eslint/parser",
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
"plugin:@eslint-react/recommended-legacy",
],
plugins: ["@typescript-eslint", "react-hooks"],
ignorePatterns: ["dist", ".eslintrc.js"],
};
import ts from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import react from "@eslint-react/eslint-plugin";
import reactHooks from "eslint-plugin-react-hooks";
export default [
{
files: ["**/*.ts"],
ignores: ["eslint.config.js"],
languageOptions: {
parser: tsParser,
sourceType: "module",
},
plugins: {
"@typescript-eslint": ts,
},
rules: {
...ts.configs["eslint-recommended"].rules,
...ts.configs["recommended"].rules,
},
},
{
files: ["src/**/*.{ts,tsx}"],
plugins: {
"react-hooks": reactHooks,
},
rules: {
...reactHooks.configs.recommended.rules,
},
},
{
files: ["src/**/*.{ts,tsx}"],
...react.configs.recommended,
},
];
Rules
Rule List ↗
Philosophy
- Focus on code rather than style.
- Linting errors are better than runtime crashes.
- Types are the fundamental unit of correctness.
Rule introduction or modification principles
- TypeScript first. If a behavior can already be enforced by TypeScript built-in checker, don't reimplement it.
- Formatting independent. Rules should check for correctness, not style. We recommend using style focused tools for formatting (e.g. dprint or eslint-stylistic).
- No Auto-fix. Auto-fix is a great feature, but it's not always safe and reliable. We prefer to not to do auto-fix at all than to implement it in a way that can cause more problems than it solves.
- Sensible defaults. Rules should be easy to setup and use with minimal configuration and sensible defaults.
- Rules over Options [1]. Each rule should have a single purpose. Make multiple rules work together to achieve more complex behaviors instead of adding options to a single rule.
Contributing
Before you start working on something, it's best to check if there is an existing issue first. It's also a good idea to reach the maintainer and confirm with the team if it makes sense or if someone else is already working on it.
Please make sure to read the Contributing Guide before making a pull request.
Thank you to everyone contributing to ESLint React!
License
This project is licensed under the MIT License - see the LICENSE file for details.
Inspiration
Prior art