Skip to content

Commit ea15e1d

Browse files
authored
feat: sync the recommended rules of react plugins (#693)
* feat: sync the recommended rules of react plugins * --amend
1 parent 99470cc commit ea15e1d

File tree

1 file changed

+60
-53
lines changed

1 file changed

+60
-53
lines changed

src/configs/react.ts

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable perfectionist/sort-objects */
12
import type { OptionsFiles, OptionsOverrides, OptionsTypeScriptParserOptions, OptionsTypeScriptWithTypes, TypedFlatConfigItem } from '../types'
23

34
import { isPackageExists } from 'local-pkg'
@@ -93,23 +94,78 @@ export async function react(
9394
},
9495
name: 'antfu/react/rules',
9596
rules: {
96-
// recommended rules from @eslint-react/dom
97-
'react-dom/no-children-in-void-dom-elements': 'warn',
97+
// recommended rules from eslint-plugin-react-x https://eslint-react.xyz/docs/rules/overview#core-rules
98+
'react/no-access-state-in-setstate': 'error',
99+
'react/no-array-index-key': 'warn',
100+
'react/no-children-count': 'warn',
101+
'react/no-children-for-each': 'warn',
102+
'react/no-children-map': 'warn',
103+
'react/no-children-only': 'warn',
104+
'react/no-children-to-array': 'warn',
105+
'react/no-clone-element': 'warn',
106+
'react/no-comment-textnodes': 'warn',
107+
'react/no-component-will-mount': 'error',
108+
'react/no-component-will-receive-props': 'error',
109+
'react/no-component-will-update': 'error',
110+
'react/no-context-provider': 'warn',
111+
'react/no-create-ref': 'error',
112+
'react/no-default-props': 'error',
113+
'react/no-direct-mutation-state': 'error',
114+
'react/no-duplicate-jsx-props': 'warn',
115+
'react/no-duplicate-key': 'warn',
116+
'react/no-forward-ref': 'warn',
117+
'react/no-implicit-key': 'warn',
118+
'react/no-missing-key': 'error',
119+
'react/no-nested-component-definitions': 'error',
120+
'react/no-prop-types': 'error',
121+
'react/no-redundant-should-component-update': 'error',
122+
'react/no-set-state-in-component-did-mount': 'warn',
123+
'react/no-set-state-in-component-did-update': 'warn',
124+
'react/no-set-state-in-component-will-update': 'warn',
125+
'react/no-string-refs': 'error',
126+
'react/no-unsafe-component-will-mount': 'warn',
127+
'react/no-unsafe-component-will-receive-props': 'warn',
128+
'react/no-unsafe-component-will-update': 'warn',
129+
'react/no-unstable-context-value': 'warn',
130+
'react/no-unstable-default-props': 'warn',
131+
'react/no-unused-class-component-members': 'warn',
132+
'react/no-unused-state': 'warn',
133+
'react/no-use-context': 'warn',
134+
'react/no-useless-forward-ref': 'warn',
135+
'react/use-jsx-vars': 'warn',
136+
137+
// recommended rules from eslint-plugin-react-dom https://eslint-react.xyz/docs/rules/overview#dom-rules
98138
'react-dom/no-dangerously-set-innerhtml': 'warn',
99139
'react-dom/no-dangerously-set-innerhtml-with-children': 'error',
100140
'react-dom/no-find-dom-node': 'error',
141+
'react-dom/no-flush-sync': 'error',
142+
'react-dom/no-hydrate': 'error',
101143
'react-dom/no-missing-button-type': 'warn',
102144
'react-dom/no-missing-iframe-sandbox': 'warn',
103145
'react-dom/no-namespace': 'error',
146+
'react-dom/no-render': 'error',
104147
'react-dom/no-render-return-value': 'error',
105148
'react-dom/no-script-url': 'warn',
106149
'react-dom/no-unsafe-iframe-sandbox': 'warn',
107150
'react-dom/no-unsafe-target-blank': 'warn',
151+
'react-dom/no-use-form-state': 'error',
152+
'react-dom/no-void-elements-with-children': 'error',
108153

109-
// recommended rules react-hooks
154+
// recommended rules eslint-plugin-react-hooks https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks/src/rules
110155
'react-hooks/exhaustive-deps': 'warn',
111156
'react-hooks/rules-of-hooks': 'error',
112-
// react refresh
157+
158+
// recommended rules from eslint-plugin-react-hooks-extra https://eslint-react.xyz/docs/rules/overview#hooks-extra-rules
159+
'react-hooks-extra/no-direct-set-state-in-use-effect': 'warn',
160+
'react-hooks-extra/no-unnecessary-use-prefix': 'warn',
161+
162+
// recommended rules from eslint-plugin-react-web-api https://eslint-react.xyz/docs/rules/overview#web-api-rules
163+
'react-web-api/no-leaked-event-listener': 'warn',
164+
'react-web-api/no-leaked-interval': 'warn',
165+
'react-web-api/no-leaked-resize-observer': 'warn',
166+
'react-web-api/no-leaked-timeout': 'warn',
167+
168+
// preconfigured rules from eslint-plugin-react-refresh https://github.com/ArnaudBarre/eslint-plugin-react-refresh/tree/main/src
113169
'react-refresh/only-export-components': [
114170
'warn',
115171
{
@@ -144,55 +200,6 @@ export async function react(
144200
],
145201
},
146202
],
147-
// recommended rules from @eslint-react/web-api
148-
'react-web-api/no-leaked-event-listener': 'warn',
149-
150-
'react-web-api/no-leaked-interval': 'warn',
151-
'react-web-api/no-leaked-resize-observer': 'warn',
152-
153-
'react-web-api/no-leaked-timeout': 'warn',
154-
155-
// recommended rules from @eslint-react
156-
'react/ensure-forward-ref-using-ref': 'warn',
157-
'react/jsx-no-duplicate-props': 'warn',
158-
'react/jsx-uses-vars': 'warn',
159-
'react/no-access-state-in-setstate': 'error',
160-
'react/no-array-index-key': 'warn',
161-
'react/no-children-count': 'warn',
162-
'react/no-children-for-each': 'warn',
163-
'react/no-children-map': 'warn',
164-
'react/no-children-only': 'warn',
165-
'react/no-children-to-array': 'warn',
166-
'react/no-clone-element': 'warn',
167-
'react/no-comment-textnodes': 'warn',
168-
'react/no-component-will-mount': 'error',
169-
'react/no-component-will-receive-props': 'error',
170-
'react/no-component-will-update': 'error',
171-
'react/no-context-provider': 'warn',
172-
'react/no-create-ref': 'error',
173-
'react/no-default-props': 'error',
174-
'react/no-direct-mutation-state': 'error',
175-
'react/no-duplicate-key': 'error',
176-
'react/no-forward-ref': 'warn',
177-
'react/no-implicit-key': 'warn',
178-
'react/no-missing-key': 'error',
179-
'react/no-nested-components': 'error',
180-
'react/no-prop-types': 'error',
181-
'react/no-redundant-should-component-update': 'error',
182-
'react/no-set-state-in-component-did-mount': 'warn',
183-
'react/no-set-state-in-component-did-update': 'warn',
184-
'react/no-set-state-in-component-will-update': 'warn',
185-
'react/no-string-refs': 'error',
186-
'react/no-unsafe-component-will-mount': 'warn',
187-
'react/no-unsafe-component-will-receive-props': 'warn',
188-
'react/no-unsafe-component-will-update': 'warn',
189-
'react/no-unstable-context-value': 'warn',
190-
'react/no-unstable-default-props': 'warn',
191-
'react/no-unused-class-component-members': 'warn',
192-
'react/no-unused-state': 'warn',
193-
'react/prefer-destructuring-assignment': 'warn',
194-
'react/prefer-shorthand-boolean': 'warn',
195-
'react/prefer-shorthand-fragment': 'warn',
196203

197204
// overrides
198205
...overrides,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy