From c62986cfd8cbf994348407c8ece06b04ec1c86f4 Mon Sep 17 00:00:00 2001 From: Anthony Garritano Date: Mon, 22 Feb 2021 19:17:13 -0500 Subject: [PATCH] Add additional messaging for RulesOfHooks lint error (#20692) * Add additional messaging for RulesOfHooks lint error * Fix tests and spacing issue * Prettify ESLintRulesOfHooks-test --- .../__tests__/ESLintRulesOfHooks-test.js | 3 ++- packages/eslint-plugin-react-hooks/src/RulesOfHooks.js | 3 ++- 2 files changed, 4 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..b6b0c8d4a9674 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js @@ -915,7 +915,8 @@ 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.