Add additional messaging for RulesOfHooks lint error (#20692)
* Add additional messaging for RulesOfHooks lint error * Fix tests and spacing issue * Prettify ESLintRulesOfHooks-test
Anthony Garritano committed
Feb 22, 2021 at 19:17 UTC
c62986cfd8cbf994348407c8ece06b04ec1c86f4
2 files changed
+4
-2
packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js
+2
-1
@@ -915,7 +915,8 @@ function functionError(hook, fn) {
915
message:
916
`React Hook "${hook}" is called in function "${fn}" that is neither ` +
917
'a React function component nor a custom React Hook function.' +
918
- ' React component names must start with an uppercase letter.',
918
+ ' React component names must start with an uppercase letter.' +
919
+ ' React Hook names must start with the word "use".',
920
};
921
}
922
packages/eslint-plugin-react-hooks/src/RulesOfHooks.js
+2
-1
@@ -482,7 +482,8 @@ export default {
482
`function "${context.getSource(codePathFunctionName)}" ` +
483
'that is neither a React function component nor a custom ' +
484
'React Hook function.' +
485
- ' React component names must start with an uppercase letter.';
485
+ ' React component names must start with an uppercase letter.' +
486
+ ' React Hook names must start with the word "use".';
487
context.report({node: hook, message});
488
} else if (codePathNode.type === 'Program') {
489
// These are dangerous if you have inline requires enabled.