File tree Expand file tree Collapse file tree
packages/eslint-plugin-react-hooks/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "root" : true ,
3- "extends" : [" plugin:react-hooks/recommended-legacy" ],
3+ "extends" : [" plugin:react-hooks/recommended-latest- legacy" ],
44 "parserOptions" : {
55 "ecmaVersion" : 2020 ,
66 "sourceType" : " module" ,
77 "ecmaFeatures" : {
88 "jsx" : true
99 }
10- },
11- "rules" : {
12- "react-hooks/exhaustive-deps" : " error"
1310 }
1411}
Original file line number Diff line number Diff line change @@ -141,3 +141,27 @@ function useHookInLoops() {
141141 useHook4 ( ) ;
142142 }
143143}
144+
145+ /**
146+ * Compiler Rules
147+ */
148+ // Invalid: component factory
149+ function InvalidComponentFactory ( ) {
150+ const DynamicComponent = ( ) => < div > Hello</ div > ;
151+ // eslint-disable-next-line react-hooks/static-components
152+ return < DynamicComponent /> ;
153+ }
154+
155+ // Invalid: mutating globals
156+ function InvalidGlobals ( ) {
157+ // eslint-disable-next-line react-hooks/immutability
158+ window . myGlobal = 42 ;
159+ return < div > Done</ div > ;
160+ }
161+
162+ // Invalid: useMemo with wrong deps - triggers preserve-manual-memoization
163+ function InvalidUseMemo ( { items} ) {
164+ // eslint-disable-next-line react-hooks/preserve-manual-memoization, react-hooks/exhaustive-deps
165+ const sorted = useMemo ( ( ) => [ ...items ] . sort ( ) , [ ] ) ;
166+ return < div > { sorted . length } </ div > ;
167+ }
Original file line number Diff line number Diff line change 11{
22 "root" : true ,
3- "extends" : [" plugin:react-hooks/recommended-legacy" ],
3+ "extends" : [" plugin:react-hooks/recommended-latest- legacy" ],
44 "parserOptions" : {
55 "ecmaVersion" : 2020 ,
66 "sourceType" : " module" ,
77 "ecmaFeatures" : {
88 "jsx" : true
99 }
10- },
11- "rules" : {
12- "react-hooks/exhaustive-deps" : " error"
1310 }
1411}
Original file line number Diff line number Diff line change @@ -141,3 +141,27 @@ function useHookInLoops() {
141141 useHook4 ( ) ;
142142 }
143143}
144+
145+ /**
146+ * Compiler Rules
147+ */
148+ // Invalid: component factory
149+ function InvalidComponentFactory ( ) {
150+ const DynamicComponent = ( ) => < div > Hello</ div > ;
151+ // eslint-disable-next-line react-hooks/static-components
152+ return < DynamicComponent /> ;
153+ }
154+
155+ // Invalid: mutating globals
156+ function InvalidGlobals ( ) {
157+ // eslint-disable-next-line react-hooks/immutability
158+ window . myGlobal = 42 ;
159+ return < div > Done</ div > ;
160+ }
161+
162+ // Invalid: useMemo with wrong deps - triggers preserve-manual-memoization
163+ function InvalidUseMemo ( { items} ) {
164+ // eslint-disable-next-line react-hooks/preserve-manual-memoization, react-hooks/exhaustive-deps
165+ const sorted = useMemo ( ( ) => [ ...items ] . sort ( ) , [ ] ) ;
166+ return < div > { sorted . length } </ div > ;
167+ }
Original file line number Diff line number Diff line change 11{
22 "root" : true ,
3- "extends" : [" plugin:react-hooks/recommended-legacy" ],
3+ "extends" : [" plugin:react-hooks/recommended-latest- legacy" ],
44 "parserOptions" : {
55 "ecmaVersion" : 2020 ,
66 "sourceType" : " module" ,
77 "ecmaFeatures" : {
88 "jsx" : true
99 }
10- },
11- "rules" : {
12- "react-hooks/exhaustive-deps" : " error"
1310 }
1411}
Original file line number Diff line number Diff line change @@ -141,3 +141,27 @@ function useHookInLoops() {
141141 useHook4 ( ) ;
142142 }
143143}
144+
145+ /**
146+ * Compiler Rules
147+ */
148+ // Invalid: component factory
149+ function InvalidComponentFactory ( ) {
150+ const DynamicComponent = ( ) => < div > Hello</ div > ;
151+ // eslint-disable-next-line react-hooks/static-components
152+ return < DynamicComponent /> ;
153+ }
154+
155+ // Invalid: mutating globals
156+ function InvalidGlobals ( ) {
157+ // eslint-disable-next-line react-hooks/immutability
158+ window . myGlobal = 42 ;
159+ return < div > Done</ div > ;
160+ }
161+
162+ // Invalid: useMemo with wrong deps - triggers preserve-manual-memoization
163+ function InvalidUseMemo ( { items} ) {
164+ // eslint-disable-next-line react-hooks/preserve-manual-memoization, react-hooks/exhaustive-deps
165+ const sorted = useMemo ( ( ) => [ ...items ] . sort ( ) , [ ] ) ;
166+ return < div > { sorted . length } </ div > ;
167+ }
Original file line number Diff line number Diff line change 11import { defineConfig } from 'eslint/config' ;
22import reactHooks from 'eslint-plugin-react-hooks' ;
33
4- console . log ( reactHooks . configs [ 'recommended-latest' ] ) ;
5-
64export default defineConfig ( [
75 {
86 languageOptions : {
Original file line number Diff line number Diff line change @@ -141,3 +141,27 @@ function useHookInLoops() {
141141 useHook4 ( ) ;
142142 }
143143}
144+
145+ /**
146+ * Compiler Rules
147+ */
148+ // Invalid: component factory
149+ function InvalidComponentFactory ( ) {
150+ const DynamicComponent = ( ) => < div > Hello</ div > ;
151+ // eslint-disable-next-line react-hooks/static-components
152+ return < DynamicComponent /> ;
153+ }
154+
155+ // Invalid: mutating globals
156+ function InvalidGlobals ( ) {
157+ // eslint-disable-next-line react-hooks/immutability
158+ window . myGlobal = 42 ;
159+ return < div > Done</ div > ;
160+ }
161+
162+ // Invalid: useMemo with wrong deps - triggers preserve-manual-memoization
163+ function InvalidUseMemo ( { items} ) {
164+ // eslint-disable-next-line react-hooks/preserve-manual-memoization, react-hooks/exhaustive-deps
165+ const sorted = useMemo ( ( ) => [ ...items ] . sort ( ) , [ ] ) ;
166+ return < div > { sorted . length } </ div > ;
167+ }
You can’t perform that action at this time.
0 commit comments