Files
low-code-react-app-b/codeql/custom-queries/queries/ComponentHooksUsage.ql
2026-01-19 09:23:22 +00:00

31 lines
776 B
Plaintext

/**
* @name React hook usage in components
* @description Flags component files that call React hooks (likely needs custom hook extraction).
* @kind problem
* @severity warning
* @id custom/component-hooks-usage
*/
import javascript
predicate isComponentFile(File f) {
f.getRelativePath().regexpMatch("^(src/)?components/.*\\.tsx$")
}
predicate isReactHookName(string name) {
name = "useState" or
name = "useEffect" or
name = "useMemo" or
name = "useCallback" or
name = "useReducer" or
name = "useLayoutEffect" or
name = "useRef"
}
from CallExpr call, File f, VarRef ref
where
f = call.getFile() and
isComponentFile(f) and
ref = call.getCallee() and
isReactHookName(ref.getName())
select call, "React hook call in component: " + ref.getName()