eslint-plugin-no-unnecessary-hook-definition

0.1.1 • Public • Published

eslint-plugin-no-unnecessary-hook-definition — Formidable, We build the modern web

eslint-plugin-no-unnecessary-hook-definition

This library contains a simple ESLint plugin with a single rule to disallow defining React "hooks" that perhaps shouldn't be considered "hooks". This library enforces the following rule:

A function should only be considered a React "hook" (e.g., its name starts with use) if it calls another hook.

This rule ensures your codebase is not littered with "fake hooks" like the following:

// ❌ This will get flagged
const useFirstName = (person) => {
  return person.firstName;
};

since this function, as an example, has no reliance on React or its hook ecosystem and is probably best declared as a plain 'ol function like getFirstName.

Setup & Usage

Start by installing the plugin:

npm install -D eslint-plugin-no-unnecessary-hook-definition

# Or...

yarn add -D eslint-plugin-no-unnecessary-hook-definition

Then add the plugin to your .eslintrc configuration file in both the plugins and rules fields:

{
  "plugins": ["no-unnecessary-hook-definition", "..."],
  "rules": {
    "no-unnecessary-hook-definition/rule": 2
  }
}

That's it! Happy coding!

Readme

Keywords

Package Sidebar

Install

npm i eslint-plugin-no-unnecessary-hook-definition

Weekly Downloads

4

Version

0.1.1

License

MIT

Unpacked Size

10.7 kB

Total Files

5

Last publish

Collaborators

  • scottianstewart
  • keithluchtel
  • ceceppa
  • robwalkerco
  • sarahformidable
  • scott-rippey
  • michaelmerrill
  • sarmeyer
  • mariano-formidable
  • ryan.roemer
  • formidable-owner
  • formidablelabs
  • carbonrobot
  • masiddee
  • gksander