├── .editorconfig
├── .gitattributes
├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .npmrc
├── eslint.config.js
├── index.js
├── license
├── package.json
├── readme.md
├── space.js
└── test
└── test.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = tab
5 | end_of_line = lf
6 | charset = utf-8
7 | trim_trailing_whitespace = true
8 | insert_final_newline = true
9 |
10 | [*.yml]
11 | indent_style = space
12 | indent_size = 2
13 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto eol=lf
2 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 | on:
3 | - push
4 | - pull_request
5 | jobs:
6 | test:
7 | name: Node.js ${{ matrix.node-version }}
8 | runs-on: ubuntu-latest
9 | strategy:
10 | fail-fast: false
11 | matrix:
12 | node-version:
13 | - 22
14 | - 20
15 | - 18
16 | steps:
17 | - uses: actions/checkout@v4
18 | - uses: actions/setup-node@v4
19 | with:
20 | node-version: ${{ matrix.node-version }}
21 | - run: npm install
22 | - run: npm test
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | yarn.lock
3 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | package-lock=false
2 |
--------------------------------------------------------------------------------
/eslint.config.js:
--------------------------------------------------------------------------------
1 | export {default} from './index.js';
2 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import react from 'eslint-plugin-react';
2 | import reactHooks from 'eslint-plugin-react-hooks';
3 |
4 | export default [
5 | {
6 | plugins: {
7 | react,
8 | 'react-hooks': reactHooks,
9 | },
10 | languageOptions: {
11 | parserOptions: {
12 | ecmaFeatures: {
13 | jsx: true,
14 | },
15 | },
16 | },
17 | settings: {
18 | react: {
19 | version: 'detect',
20 | },
21 | },
22 | rules: {
23 | 'react/boolean-prop-naming': [
24 | 'error',
25 | {
26 | validateNested: true,
27 | },
28 | ],
29 | 'react/button-has-type': 'error',
30 | 'react/checked-requires-onchange-or-readonly': 'error',
31 | 'react/jsx-child-element-spacing': 'error',
32 | 'react/default-props-match-prop-types': 'error',
33 | 'react/forward-ref-uses-ref': 'error',
34 | 'react/function-component-definition': [
35 | 'error',
36 | {
37 | namedComponents: 'function-declaration',
38 | unnamedComponents: 'arrow-function',
39 | },
40 | ],
41 | 'react/hook-use-state': [
42 | 'error',
43 | {
44 | allowDestructuredState: true,
45 | },
46 | ],
47 | 'react/iframe-missing-sandbox': 'error',
48 | 'react/no-access-state-in-setstate': 'error',
49 | 'react/no-array-index-key': 'error',
50 | 'react/no-arrow-function-lifecycle': 'error',
51 | 'react/no-children-prop': 'error',
52 | 'react/no-danger': 'error',
53 | 'react/no-danger-with-children': 'error',
54 | 'react/no-deprecated': 'error',
55 | 'react/no-did-update-set-state': 'error',
56 | 'react/no-direct-mutation-state': 'error',
57 | 'react/no-find-dom-node': 'error',
58 | 'react/no-invalid-html-attribute': 'error',
59 | 'react/no-is-mounted': 'error',
60 | 'react/no-namespace': 'error',
61 | 'react/no-object-type-as-default-prop': 'error',
62 | 'react/no-redundant-should-component-update': 'error',
63 | 'react/no-render-return-value': 'error',
64 | 'react/no-typos': 'error',
65 | 'react/no-string-refs': [
66 | 'error',
67 | {
68 | noTemplateLiterals: true,
69 | },
70 | ],
71 | 'react/no-this-in-sfc': 'error',
72 | 'react/no-unescaped-entities': 'error',
73 | 'react/no-unknown-property': [
74 | 'error',
75 | {
76 | requireDataLowercase: true,
77 | },
78 | ],
79 | 'react/no-unsafe': 'error',
80 | 'react/no-unused-prop-types': 'error',
81 | 'react/no-unused-state': 'error',
82 | 'react/prefer-read-only-props': 'error',
83 | 'react/prop-types': 'error',
84 | 'react/react-in-jsx-scope': 'error',
85 | 'react/require-default-props': [
86 | 'error',
87 | {
88 | forbidDefaultForRequired: true,
89 | ignoreFunctionalComponents: true,
90 | },
91 | ],
92 | 'react/self-closing-comp': 'error',
93 | 'react/state-in-constructor': ['error', 'never'],
94 | 'react/static-property-placement': 'error',
95 | 'react/style-prop-object': [
96 | 'error',
97 | {
98 | allow: [
99 | // This allows react-intl’s ``.
100 | 'FormattedNumber',
101 | ],
102 | },
103 | ],
104 | 'react/void-dom-elements-no-children': 'error',
105 | 'react/jsx-boolean-value': 'error',
106 | 'react/jsx-closing-bracket-location': [
107 | 'error',
108 | {
109 | nonEmpty: 'tag-aligned',
110 | selfClosing: false,
111 | },
112 | ],
113 | 'react/jsx-closing-tag-location': 'error',
114 | 'react/jsx-curly-newline': [
115 | 'error',
116 | {
117 | multiline: 'consistent',
118 | singleline: 'forbid',
119 | },
120 | ],
121 | 'react/jsx-curly-spacing': ['error', 'never'],
122 | 'react/jsx-equals-spacing': ['error', 'never'],
123 | 'react/jsx-first-prop-new-line': 'error',
124 | 'react/jsx-indent': [
125 | 'error',
126 | 'tab',
127 | {
128 | checkAttributes: true,
129 | indentLogicalExpressions: true,
130 | },
131 | ],
132 | 'react/jsx-indent-props': ['error', 'tab'],
133 | 'react/jsx-key': [
134 | 'error',
135 | {
136 | checkFragmentShorthand: true,
137 | checkKeyMustBeforeSpread: true,
138 | warnOnDuplicates: true,
139 | },
140 | ],
141 | 'react/jsx-max-props-per-line': [
142 | 'error',
143 | {
144 | maximum: 3,
145 | when: 'multiline',
146 | },
147 | ],
148 | 'react/jsx-no-bind': [
149 | 'error',
150 | {
151 | allowArrowFunctions: true,
152 | },
153 | ],
154 | 'react/jsx-no-comment-textnodes': 'error',
155 | 'react/jsx-no-constructed-context-values': 'error',
156 | 'react/jsx-no-duplicate-props': [
157 | 'error',
158 | {
159 | ignoreCase: true,
160 | },
161 | ],
162 | 'react/jsx-no-leaked-render': [
163 | 'error',
164 | {
165 | validStrategies: [
166 | 'ternary',
167 | 'coerce',
168 | ],
169 | },
170 | ],
171 | 'react/jsx-no-script-url': [
172 | 'error',
173 | {
174 | includeFromSettings: true,
175 | },
176 | ],
177 | 'react/jsx-no-target-blank': [
178 | 'error',
179 | {
180 | warnOnSpreadAttributes: true,
181 | forms: true,
182 | },
183 | ],
184 | 'react/jsx-no-undef': 'error',
185 | 'react/jsx-no-useless-fragment': 'error',
186 | // Disabled for now as it produces too many errors
187 | // 'react/jsx-one-expression-per-line': ['error', {allow: 'single-child'}],
188 | 'react/jsx-curly-brace-presence': [
189 | 'error',
190 | {
191 | props: 'never',
192 | children: 'never',
193 | propElementValues: 'always',
194 | },
195 | ],
196 | 'react/jsx-fragments': ['error', 'syntax'],
197 | 'react/jsx-pascal-case': 'error',
198 | 'react/jsx-props-no-multi-spaces': 'error',
199 | 'react/jsx-props-no-spread-multi': 'error',
200 | 'react/jsx-sort-props': [
201 | 'error',
202 | {
203 | callbacksLast: true,
204 | shorthandFirst: true,
205 | noSortAlphabetically: true,
206 | reservedFirst: true,
207 | },
208 | ],
209 | 'react/jsx-tag-spacing': [
210 | 'error',
211 | {
212 | closingSlash: 'never',
213 | beforeSelfClosing: 'never',
214 | afterOpening: 'never',
215 | beforeClosing: 'never',
216 | },
217 | ],
218 | 'react/jsx-uses-react': 'error',
219 | 'react/jsx-uses-vars': 'error',
220 | 'react/jsx-wrap-multilines': [
221 | 'error',
222 | {
223 | declaration: 'parens-new-line',
224 | assignment: 'parens-new-line',
225 | return: 'parens-new-line',
226 | arrow: 'parens-new-line',
227 | condition: 'ignore',
228 | logical: 'ignore',
229 | prop: 'ignore',
230 | },
231 | ],
232 |
233 | 'react-hooks/rules-of-hooks': 'error',
234 | 'react-hooks/exhaustive-deps': 'warn',
235 | },
236 | },
237 | ];
238 |
--------------------------------------------------------------------------------
/license:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "eslint-config-xo-react",
3 | "version": "0.28.0",
4 | "description": "ESLint shareable config for React to be used with eslint-config-xo",
5 | "license": "MIT",
6 | "repository": "xojs/eslint-config-xo-react",
7 | "funding": "https://github.com/sponsors/sindresorhus",
8 | "author": {
9 | "name": "Sindre Sorhus",
10 | "email": "sindresorhus@gmail.com",
11 | "url": "https://sindresorhus.com"
12 | },
13 | "type": "module",
14 | "exports": {
15 | ".": "./index.js",
16 | "./space": "./space.js"
17 | },
18 | "sideEffects": false,
19 | "engines": {
20 | "node": ">=18.18"
21 | },
22 | "scripts": {
23 | "test": "eslint && ava"
24 | },
25 | "files": [
26 | "index.js",
27 | "space.js"
28 | ],
29 | "keywords": [
30 | "react",
31 | "jsx",
32 | "eslintconfig",
33 | "xo",
34 | "xoxo",
35 | "hugs",
36 | "kisses",
37 | "happy",
38 | "happiness",
39 | "code",
40 | "quality",
41 | "style",
42 | "lint",
43 | "linter",
44 | "jscs",
45 | "jshint",
46 | "jslint",
47 | "eslint",
48 | "validate",
49 | "code style",
50 | "standard",
51 | "strict",
52 | "check",
53 | "checker",
54 | "verify",
55 | "enforce",
56 | "hint",
57 | "simple"
58 | ],
59 | "dependencies": {
60 | "eslint-plugin-react": "^7.37.4",
61 | "eslint-plugin-react-hooks": "^5.1.0"
62 | },
63 | "devDependencies": {
64 | "ava": "^6.2.0",
65 | "eslint": "^9.18.0",
66 | "react": "^19.0.0"
67 | },
68 | "peerDependencies": {
69 | "eslint": ">=9.18.0"
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # eslint-config-xo-react
2 |
3 | > ESLint [shareable config](http://eslint.org/docs/developer-guide/shareable-configs.html) for React to be used with [eslint-config-xo](https://github.com/xojs/eslint-config-xo)
4 |
5 | ## Install
6 |
7 | ```sh
8 | npm install --save-dev eslint-config-xo eslint-config-xo-react
9 | ```
10 |
11 | ## Usage
12 |
13 | Add some ESLint config to your `eslint.config.js`:
14 |
15 | ```js
16 | import xo from 'eslint-config-xo';
17 | import xoReact from 'eslint-config-xo-react';
18 |
19 | export default [
20 | ...xo,
21 | ...xoReact
22 | ];
23 | ```
24 |
25 | Use the `space` sub-config if you want 2 space indentation instead of tabs:
26 |
27 | ```js
28 | import xoSpace from 'eslint-config-xo/space';
29 | import xoReactSpace from 'eslint-config-xo-react/space';
30 |
31 | export default [
32 | ...xoSpace,
33 | ...xoReactSpace
34 | ];
35 | ```
36 |
37 |
53 |
54 | ## Related
55 |
56 | - [eslint-config-xo](https://github.com/xojs/eslint-config-xo) - ESLint shareable config for XO
57 | - [XO](https://github.com/xojs/xo)
58 |
--------------------------------------------------------------------------------
/space.js:
--------------------------------------------------------------------------------
1 | import configs from './index.js';
2 |
3 | const [config] = configs;
4 |
5 | export default [
6 | {
7 | ...config,
8 | rules: {
9 | ...config.rules,
10 | 'react/jsx-indent-props': ['error', 2],
11 | 'react/jsx-indent': ['error', 2],
12 | },
13 | },
14 | ];
15 |
--------------------------------------------------------------------------------
/test/test.js:
--------------------------------------------------------------------------------
1 | import test from 'ava';
2 | import eslintConfigXoReact from '../index.js';
3 | import eslintConfigXoReactSpace from '../space.js';
4 | import {ESLint} from 'eslint';
5 |
6 | const hasRule = (errors, ruleId) => errors.some(error => error.ruleId === ruleId);
7 |
8 | async function runEslint(string, config) {
9 | const eslint = new ESLint({
10 | overrideConfigFile: true,
11 | overrideConfig: config,
12 | });
13 |
14 | const [firstResult] = await eslint.lintText(string);
15 |
16 | return firstResult.messages;
17 | }
18 |
19 | test('main', async t => {
20 | t.true(Array.isArray(eslintConfigXoReact));
21 |
22 | const errors = await runEslint('var app = Unicorn
', eslintConfigXoReact);
23 | t.true(hasRule(errors, 'react/react-in-jsx-scope'));
24 | });
25 |
26 | test('space', async t => {
27 | t.true(Array.isArray(eslintConfigXoReactSpace));
28 |
29 | const errors = await runEslint('\n\t\n', eslintConfigXoReactSpace);
30 | t.true(hasRule(errors, 'react/jsx-indent'));
31 | });
32 |
33 | test('no errors', async t => {
34 | const errors = await runEslint('var React = require(\'react\');\nvar el = ;', eslintConfigXoReact);
35 | t.deepEqual(errors, []);
36 | });
37 |
--------------------------------------------------------------------------------