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

[Bug]: parserOptions.ecmaFeatures.jsx not set when using presets #3523

Closed
2 tasks done
CleyFaye opened this issue Jan 18, 2023 · 2 comments
Closed
2 tasks done

[Bug]: parserOptions.ecmaFeatures.jsx not set when using presets #3523

CleyFaye opened this issue Jan 18, 2023 · 2 comments
Labels

Comments

@CleyFaye
Copy link

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

When extending eslint configuration with "extends": ["plugin:react/recommended"], the parserOptions are not set to enable JSX support.

According to the README, parserOptions.ecmaFeatures.jsx should be set to true by all presets.

% cat .eslintrc.cjs
module.exports = {
  parserOptions: {
    ecmaVersion: "latest",
    sourceType: "module"
  },
  extends: [
    "eslint:recommended",
    "plugin:react/all"
  ],
  settings: {
    react: {
      version: "detect"
    }
  }
}

% npx eslint --print-config somefile.js | jq .parserOptions
{
  "ecmaVersion": "latest",
  "sourceType": "module"
}

This property not being set breaks parsing of JavaScript files containing JSX.

Expected Behavior

According to the documentation:

Note: These configurations will import eslint-plugin-react and enable JSX in parser options.

But using the presets (all and recommended) do not set this property.

It used to work in v7.31.11 but is broken in v7.32.1, which is actually tagged "latest" on npmjs.

With v7.31.11, the example in the overview above yields this result:

% npx eslint --print-config somefile.js | jq .parserOptions
{
  "ecmaVersion": "latest",
  "sourceType": "module",
  "ecmaFeatures": {
    "jsx": true
  }
}

and eslint works fine with files containing JSX.

eslint-plugin-react version

v7.32.1

eslint version

v8.32.0

node version

v18.13.0

@CleyFaye CleyFaye added the bug label Jan 18, 2023
@ljharb
Copy link
Member

ljharb commented Jan 18, 2023

I would suggest using the airbnb config, instead of the "recommended" config (which isn't actually recommended, because it's very out of date due to semver constraints).

@ljharb
Copy link
Member

ljharb commented Jan 18, 2023

That said, it's currently set here: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/configs/all.js#L29-L35 for the flat config, so we should also be setting it for the legacy config, assuming the flat config won't error on it.

@ljharb ljharb closed this as completed in 0479acd Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants