0.1.1 • Published 12 months ago

eslint-plugin-no-unnecessary-hook-definition v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

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!

0.1.1

12 months ago

0.1.0

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago