-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
React Hooks support and entry point (#18)
All React based "Arctic Ice Studio" projects using at least React version 16.8 (1) that introduced the awesome "Hooks" (2). Since this comes with an entire new API (3) that follows new design/usage pattern, the React team created an official "Hooks" ESLint plugin (4) to help to adhere to the "Rules of Hooks" (5). Since the `@arcticicestudio/eslint-config` package already includes support for React and "JSX A11Y", support for "Hooks" have also been added through a new shareable configuration entry point that - enables the `react-hooks` plugin. - configures both currently available rules `react-hooks/rules-of-hooks` and `react-hooks/exhaustive-deps` rule to `error` level. Since "Hooks" make more use of arrow functions the `react/jsx-no-bind` rule (6) has been adjusted to prevent compatibility problems by setting the `ignoreDOMComponents` and `allowArrowFunctions` options to `true`. Also the `react/display-name` rule has been disabled in order to prevent problems due to missing "display names" for "functional components" that make use of "Hooks" instead of being declared as a class component. The new entry point is available as `@arcticicestudio/eslint-config/react-hooks` and can be composed with all other available entry points (7) to inherit their rules. This feature adds the `eslint-plugin-react-hooks` package as new peer dependency for `@arcticicestudio/eslint-config`. References: (1) https://reactjs.org/blog/2019/02/06/react-v16.8.0.html (2) https://reactjs.org/docs/hooks-intro.html (3) https://reactjs.org/docs/hooks-reference.html (4) https://github.com/facebook/react/tree/master/packages/eslint-plugin-react-hooks (5) https://reactjs.org/docs/hooks-rules.html (6) https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md (7) https://github.com/arcticicestudio/styleguide-javascript/blob/develop/packages/%40arcticicestudio/eslint-config/README.md#entry-points Resolves GH-17
- Loading branch information
1 parent
0bb62ba
commit 833cc51
Showing
7 changed files
with
85 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (C) 2018-present Arctic Ice Studio <development@arcticicestudio.com> | ||
* Copyright (C) 2018-present Sven Greb <development@svengreb.de> | ||
* | ||
* Project: Arctic Ice Studio ESLint Configuration | ||
* Repository: https://github.com/arcticicestudio/styleguide-javascript | ||
* License: MIT | ||
*/ | ||
|
||
/** | ||
* Entry point for the React Hooks plugin integration. | ||
* | ||
* @since 0.8.0 | ||
* @see https://github.com/facebook/react/tree/master/packages/eslint-plugin-react-hooks | ||
* @see https://reactjs.org/docs/hooks-rules.html | ||
* @see https://reactjs.org/docs/hooks-intro.html | ||
*/ | ||
module.exports = { | ||
extends: ["./rules/react-hooks"].map(require.resolve) | ||
}; |
37 changes: 37 additions & 0 deletions
37
packages/@arcticicestudio/eslint-config/rules/react-hooks/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2018-present Arctic Ice Studio <development@arcticicestudio.com> | ||
* Copyright (C) 2018-present Sven Greb <development@svengreb.de> | ||
* | ||
* Project: Arctic Ice Studio ESLint Configuration | ||
* Repository: https://github.com/arcticicestudio/styleguide-javascript | ||
* License: MIT | ||
*/ | ||
|
||
/** | ||
* React Hook plugin rules. | ||
* @since 0.8.0 | ||
* @see https://github.com/facebook/react/tree/master/packages/eslint-plugin-react-hooks | ||
* @see https://reactjs.org/docs/hooks-rules.html | ||
* @see https://reactjs.org/docs/hooks-intro.html | ||
*/ | ||
module.exports = { | ||
plugins: ["react-hooks"], | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true | ||
} | ||
}, | ||
rules: { | ||
/** | ||
* Enforce Rules of Hooks. | ||
* @see https://reactjs.org/docs/hooks-rules.html | ||
* @see https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js | ||
*/ | ||
"react-hooks/rules-of-hooks": "error", | ||
/** | ||
* EVerify the list of the dependencies for Hooks like `useEffect` and similar. | ||
* @see https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js | ||
*/ | ||
"react-hooks/exhaustive-deps": "error" | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters