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

Use the ESLint error message itself as part of the message #528

Open
ricky-wong opened this issue Jul 10, 2024 · 0 comments
Open

Use the ESLint error message itself as part of the message #528

ricky-wong opened this issue Jul 10, 2024 · 0 comments

Comments

@ricky-wong
Copy link

Thanks for this tooling!

We have a codebase with ~100 existing warnings, and we're trying to turn new ones into errors, but let existing ones stay as warnings. I saw from eslint/eslint#13264 (comment) that this isn't possible directly in ESLint, but we circumvented this by putting "FIXME" in our "message", which in-turn triggers a warning that we have enabled (no-warning-comments)

I was wondering, is there a way I can insert the original violation explanation itself into the "message", so that users don't need to uncomment to see the error?

Reason being in my case (react-hooks/exhaustive-deps) the details can be one of several things, and I want it to stand out in the comment for easy scanning.
Some examples of the actual error that I would want to inline into the comment:

React Hook useMemo has a missing dependency: 'variableName'. Either include it or remove the dependency array. eslint(react-hooks/exhaustive-deps)
React Hook useCallback has an unnecessary dependency: 'variableName'. Either exclude it or remove the dependency array. eslint(react-hooks/exhaustive-deps)
React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead. eslint(react-hooks/exhaustive-deps)
React Hook useEffect contains a call to 'functionName'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [variableName, variableName2, variableName3] as a second argument to the useEffect Hook. eslint(react-hooks/exhaustive-deps)
The 'variableName' logical expression could make the dependencies of useEffect Hook (at line 20) change on every render. Move it inside the useEffect callback. Alternatively, wrap the initialization of 'variableName' in its own useMemo() Hook. eslint(react-hooks/exhaustive-deps)
Assignments to the 'variableName' variable from inside React Hook useEffect will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside useEffect. eslint[react-hooks/exhaustive-deps)

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant