Eslint-plugin-react: Handle new JSX transform

Created on 18 Oct 2020  Â·  7Comments  Â·  Source: yannickcr/eslint-plugin-react

We've added support for the new JSX transform into Create React App (https://github.com/facebook/create-react-app/pull/9645, https://github.com/facebook/create-react-app/pull/9788), and we've been discussing how best to support this in our ESLint config.

I'm not sure if this is a good idea, and wanted some thoughts. I wondered if we should update jsx-uses-react to warn when using a React version that ships with the new transform, and do one of the following:

  • Add an autofix (remove all React imports).
  • Recommend running the codemod.

For now, we're:

  • Auto-detecting support for the new transform (see base.js#L14-L21).
  • Updating rules based on that detection, leaving jsx-uses-react on to avoid confusion (see base.js#L52-L58).

Most helpful comment

Using React does not guarantee you're using JSX, or Babel, or transpiling at all, so I'm afraid not.

All 7 comments

If the jsx-uses-react rule is simply disabled, a “no unused imports” or “no unused variables” rule would already catch an unnecessary React import. When there’s a React version that doesn’t allow the current jsx transform, then the jsx-uses-react rule can be updated to throw an error, but otherwise I’m not sure any change is needed in this plugin.

I was thinking more about explaining why React is no longer needed to be imported.

I agree 100% that you could just rely on a no-unused variable, and as I said I was just interested in thoughts. As the community transitions, some members will obviously be confused... but a change to this plugin may not help, you're right.

We can close this off for now, again I was just interested in thoughts at this stage - thanks for your time!

Hello,

It would be nice to detect "runtime": "automatic" for the babel/preset-react option and disable errors from react-in-jsx-scope when applicable, since this rule is recommended.

I’d rather not couple this plugin to babel so tightly.

Obviously. Though I predict that after the release of Babel 8, many people will ask the same thing (or to remove it from recommended rules).

Perhaps the React version detection in this plugin could alter behaviour of the related rule?

Using React does not guarantee you're using JSX, or Babel, or transpiling at all, so I'm afraid not.

Was this page helpful?
0 / 5 - 0 ratings