A comprehensive collection of ESLint rules optimized for React applications, bundling best practices for React, React Hooks, accessibility, imports, and more.
# Using npm
npm install --save-dev eslint-plugin-jsx-a11y eslint-plugin-import eslint-plugin-react eslint-react-rules
# Using yarn
yarn add --dev eslint-plugin-jsx-a11y eslint-plugin-import eslint-plugin-react eslint-react-rules
# Using pnpm
pnpm add -D eslint-plugin-jsx-a11y eslint-plugin-import eslint-plugin-react eslint-react-rules
If you are using ESLint 9 or later, you can easily extend the recommended configuration provided by this package.
To use the recommended configuration, add the following to your ESLint eslint.config.js
file:
import eslintReactRules from 'eslint-react-rules';
import importPlugin from "eslint-plugin-import";
import pluginReact from "eslint-plugin-react";
import jsxA11y from 'eslint-plugin-jsx-a11y';
export default tseslint.config({
extends: [
// other configs...
pluginReact.configs.flat.recommended,
importPlugin.flatConfigs.recommended,
eslintReactRules.recommended,
],
plugins: {
// other plugins...
'jsx-a11y': jsxA11y,
},
rules: {
// other rules...
"react/react-in-jsx-scope": "off"
},
...
If you are using ESLint 8 or earlier, you can add the recommended configuration to your .eslintrc.js
or .eslintrc.json
file:
module.exports = {
extends: [
// other configs...
"eslint-plugin-import/recommended",
"eslint-react-rules/recommended",
"plugin:react/recommended",
],
plugins: [
// other plugins...
"jsx-a11y",
],
// Your other ESLint configuration
};
This package includes curated rule sets for:
- React - Core React best practices
- React Hooks - Rules for proper React Hooks usage
- Accessibility (a11y) - Ensuring your React applications are accessible
- Best Practices - General JavaScript best practices
- Variables - Variable declaration and usage rules
- Imports - Module import/export rules
- Errors - Common error prevention
- Style - Code style consistency
- Node - Node.js specific rules
- ES6 - Modern JavaScript rules
The package provides the following rule sets:
best-practices.cjs
- Common JavaScript best practicesreact-hooks.cjs
- Rules for React Hooksreact-a11y.cjs
- Accessibility rules for Reactvariables.cjs
- Variable usage rulesimports.cjs
- Import/export ruleserrors.cjs
- Error prevention rulesstyle.cjs
- Code style rulesreact.cjs
- React-specific rulesnode.cjs
- Node.js-specific ruleses6.cjs
- ES6+ JavaScript rules
You can also extend individual rule sets for more granular control:
module.exports = {
extends: [
// Base rules
"eslint-react-rules/rules/best-practices",
"eslint-react-rules/rules/react",
// Add only the rule sets you need
],
rules: {
// Your custom rule overrides
},
};