Skip to content

use tslint rules for React hooks linting

Warren Gifford requested to merge lint-react-hooks into master

Created by: sqs

Uses https://github.com/Gelio/tslint-react-hooks for linting React hooks code to find common mistakes, as recommended by https://reactjs.org/docs/hooks-rules.html.

Addresses https://github.com/sourcegraph/sourcegraph/pull/3392#discussion_r275895266.

Note: We plan to switch from TSLint to ESLint soon (https://github.com/sourcegraph/sourcegraph/issues/2461). In that case, we will use the more standard ESLint rules for React hooks instead.

Confirmed working; if I add a useEffect in an if-statement, it reports:

/home/sqs/src/github.com/sourcegraph/sourcegraph/shared/src/components/linkPreviews/WithLinkPreviews.tsx:27:9
ERROR: 27:9     react-hooks-nesting               A hook cannot appear inside an if statement

Merge request reports

Loading