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

[eslint-plugin-react-hooks] Bug: ESLint crashes if there's a useEffect / useLayoutEffect invocation without any arguments. #20343

Closed
latin-1 opened this issue Nov 28, 2020 · 4 comments · Fixed by #20385

Comments

@latin-1
Copy link
Contributor

latin-1 commented Nov 28, 2020

eslint-plugin-react-hooks version: 4.2.0

Steps To Reproduce

I know it shouldn't exist in production code, but it's annoying while editing some files.

import React, { useEffect } from "react";

const App = () => {
  useEffect(); // <-
  return null;
};

export default App;

Link to code example: https://codesandbox.io/s/polished-sun-3wr27?file=/src/App.js

The current behavior

ESLint crashed.

TypeError: Cannot read property 'type' of undefined

The expected behavior

ESLint doesn't crash but reports an error instead.

@latin-1 latin-1 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Nov 28, 2020
@eps1lon eps1lon added Type: Bug and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Dec 5, 2020
@dcastil
Copy link

dcastil commented Jan 11, 2021

I have the same issue, too. It's very annoying to get this warning any time I type useEffect() in VS Code.

Screenshot 2021-01-11 at 17 23 36

Thanks for fixing this! 🙏

@rickhanlonii
Copy link
Member

Thanks @ChrisRu for the fix!

@Alecell
Copy link

Alecell commented Jun 1, 2021

I'm currently facing that error too and the case is the same that when the hook is empty, am I doing something wrong?

"eslint": "^7.27.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",

@dcastil
Copy link

dcastil commented Jun 1, 2021

@Alecell eslint-plugin-react-hooks did not release a new version since this PR was merged. We need to wait until a new version of it gets released (I'm waiting for the release too 😄).

You can use the same workaround as me in the meantime, a code snippet for useEffect:

{
    "React useEffect": {
        "scope": "javascript,javascriptreact,typescript,typescriptreact",
        "prefix": "use effect",
        "body": ["useEffect(() => {$0})"]
    }
}

Then you can create effects by typing ue in a js/ts file.

You can read more about how to create snippets in VS Code here: https://code.visualstudio.com/docs/editor/userdefinedsnippets

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

Successfully merging a pull request may close this issue.

5 participants