Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule for documenting effects #69

Open
kaisermann opened this issue Sep 29, 2020 · 4 comments
Open

Rule for documenting effects #69

kaisermann opened this issue Sep 29, 2020 · 4 comments
Assignees
Labels
enhancement stale This will not be worked on

Comments

@kaisermann
Copy link
Contributor

kaisermann commented Sep 29, 2020

Is your feature request related to a problem? Please describe.

A single useEffect can be easy to understand. However, multiple useEffect calls in a relatively complex application can be hard to understand.

Describe the solution you'd like

I propose a rule vtex/react-explicit-effects, or vtex/react-documented-effects, that looks for effect react hooks (not only useEffect) and enforces one of two ways to document the purpose of the hook:

  • Adding a comment above the hook call, explaining the effect use-case.
import { useEffect } from 'react'

const Potato = () => {
  // do this and do that
  useEffect(() => {
    /// ...
  })
}
  • Using a named function instead of an arrow function:
import { useEffect } from 'react'

const Potato = () => {
  useEffect(function doThisAndThat() {
    /// ...
  })
}

Describe alternatives you've considered

Leave people to document effects themselves (which is a big no-no)

@kaisermann kaisermann self-assigned this Sep 29, 2020
@stale
Copy link

stale bot commented Oct 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
You can add the fresh label to prevent me from taking any action.
If this is a discussion thread, the most voted option will be final. Thank you for your contributions.

@stale stale bot added the stale This will not be worked on label Oct 6, 2020
@kaisermann
Copy link
Contributor Author

If anyone still wants this, I've made a basic version of this rule on my personal preset (which is basically the same as VTEX's):
https://github.com/kaisermann/kiwi/blob/main/packages/eslint-plugin/docs/rules/react-descriptive-effect.md

@stale stale bot removed the stale This will not be worked on label Jul 1, 2021
@igorbrasileiro
Copy link
Contributor

It would be good to have something like that, it enhances the readability and maintainability of the code. Interesting rule, I like it @kaisermann 👏

@stale
Copy link

stale bot commented Jul 15, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
You can add the fresh label to prevent me from taking any action.
If this is a discussion thread, the most voted option will be final. Thank you for your contributions.

@stale stale bot added the stale This will not be worked on label Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement stale This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants