You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rename Components test suite filename to match sibling lib/util/Components filename.
Extend Components testComponentsDetect function to accept custom instructions, and to accumulate the results of processing those instructions.
Add utility to check whether a CallExpression is a React hook call.
Copy file name to clipboardExpand all lines: lib/util/Components.js
+89
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,8 @@ function mergeUsedPropTypes(propsList, newPropsList) {
46
46
returnpropsList.concat(propsToAdd);
47
47
}
48
48
49
+
constUSE_HOOK_PREFIX_REGEX=/^use/i;
50
+
49
51
constLists=newWeakMap();
50
52
constReactImports=newWeakMap();
51
53
@@ -787,6 +789,93 @@ function componentRule(rule, context) {
787
789
&&!!(node.params||[]).length
788
790
);
789
791
},
792
+
793
+
/**
794
+
* Identify whether a node (CallExpression) is a call to a React hook
795
+
*
796
+
* @param {ASTNode} node The AST node being searched. (expects CallExpression)
797
+
* @param {('useCallback'|'useContext'|'useDebugValue'|'useEffect'|'useImperativeHandle'|'useLayoutEffect'|'useMemo'|'useReducer'|'useRef'|'useState')[]} [expectedHookNames] React hook names to which search is limited.
798
+
* @returns {Boolean} True if the node is a call to a React hook
0 commit comments