From a4d1e36b4de8601817e81797e78a41d663b33d35 Mon Sep 17 00:00:00 2001 From: Anthony Garritano Date: Fri, 29 Jan 2021 10:10:18 -0500 Subject: [PATCH 1/3] Add additional messaging for RulesOfHooks lint error --- packages/eslint-plugin-react-hooks/src/RulesOfHooks.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js index bc747e0094f07..b22fd7da440e8 100644 --- a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js +++ b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js @@ -482,7 +482,8 @@ export default { `function "${context.getSource(codePathFunctionName)}" ` + 'that is neither a React function component nor a custom ' + 'React Hook function.' + - ' React component names must start with an uppercase letter.'; + ' React component names must start with an uppercase letter.' + + 'React Hook names should start with the word use.'; context.report({node: hook, message}); } else if (codePathNode.type === 'Program') { // These are dangerous if you have inline requires enabled. From d65ca5a5375c9d1abdbf1407ba72bbbe4a54b80d Mon Sep 17 00:00:00 2001 From: Anthony Garritano Date: Fri, 12 Feb 2021 20:20:01 -0500 Subject: [PATCH 2/3] Fix tests and spacing issue --- .../__tests__/ESLintRulesOfHooks-test.js | 4 +++- packages/eslint-plugin-react-hooks/src/RulesOfHooks.js | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js index 5b8ff6f3e1de4..bab73c300410d 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js @@ -915,7 +915,9 @@ function functionError(hook, fn) { message: `React Hook "${hook}" is called in function "${fn}" that is neither ` + 'a React function component nor a custom React Hook function.' + - ' React component names must start with an uppercase letter.', + ' React component names must start with an uppercase letter.' + + ' React Hook names must start with the word "use".' + , }; } diff --git a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js index bc747e0094f07..66e2d8edba56f 100644 --- a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js +++ b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js @@ -482,7 +482,8 @@ export default { `function "${context.getSource(codePathFunctionName)}" ` + 'that is neither a React function component nor a custom ' + 'React Hook function.' + - ' React component names must start with an uppercase letter.'; + ' React component names must start with an uppercase letter.' + + ' React Hook names must start with the word "use".'; context.report({node: hook, message}); } else if (codePathNode.type === 'Program') { // These are dangerous if you have inline requires enabled. From ec4b81d5d227978f8ddfb24b7bc5f6e414a25e36 Mon Sep 17 00:00:00 2001 From: Anthony Garritano Date: Fri, 12 Feb 2021 20:28:26 -0500 Subject: [PATCH 3/3] Prettify ESLintRulesOfHooks-test --- .../__tests__/ESLintRulesOfHooks-test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js index bab73c300410d..b6b0c8d4a9674 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js @@ -916,8 +916,7 @@ function functionError(hook, fn) { `React Hook "${hook}" is called in function "${fn}" that is neither ` + 'a React function component nor a custom React Hook function.' + ' React component names must start with an uppercase letter.' + - ' React Hook names must start with the word "use".' - , + ' React Hook names must start with the word "use".', }; }