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

feat: eslint-plugin-react supports ESLint v9 #139

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 4 additions & 31 deletions lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,6 @@ export class ConfigGenerator {
{ message: "None of these", name: "none" }
]
},
{
type: "select",
name: "eslintVersion",
message: "The React plugin doesn't officially support ESLint v9 yet. What would you like to do?",
initial: 0,
choices: [
{ message: "Install ESLint v9.x with compatibility utilities", name: "9.x" },
{ message: "Install ESLint v8.x", name: "8.x" }
],
skip() {
return this.state.answers.framework !== "react";
}
},
{
type: "select",
name: "language",
Expand Down Expand Up @@ -193,23 +180,10 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug
if (this.answers.language === "typescript") {
extensions.push("tsx");
}
// eslint-plugin-react's flat configs have languageOptions as a non-enumerable property
exportContent = ` { languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } },\n${exportContent}`;

if (this.answers.eslintVersion === "9.x") {
this.result.devDependencies.push("eslint-plugin-react", "@eslint/compat");
if (!this.result.installFlags.includes("--force")) {
this.result.installFlags.push("--force");
}
importContent += "import pluginReactConfig from \"eslint-plugin-react/configs/recommended.js\";\n";
importContent += "import { fixupConfigRules } from \"@eslint/compat\";\n";
exportContent += " ...fixupConfigRules(pluginReactConfig),\n";
} else if (this.answers.eslintVersion === "8.x") {
this.result.devDependencies[0] = "eslint@8.x";
this.result.devDependencies.push("eslint-plugin-react");
importContent += "import pluginReactConfig from \"eslint-plugin-react/configs/recommended.js\";\n";
exportContent += " pluginReactConfig,\n";
}
this.result.devDependencies.push("eslint-plugin-react");
importContent += "import pluginReact from \"eslint-plugin-react\";\n";
exportContent += " pluginReact.configs.flat.recommended,\n";
}

if (this.answers.config) {
Expand Down Expand Up @@ -294,8 +268,7 @@ export default [\n${exportContent}];`;

// removing `--force` when:
// 1. yarn v2+ -- it does not support it.
// 2. eslint v8.x -- it does not need it.
if (packageManager === "yarn" || this.answers.eslintVersion === "8.x") {
if (packageManager === "yarn") {
const index = this.result.installFlags.indexOf("--force");

if (index !== -1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
{
"configContent": "import globals from "globals";
import pluginJs from "@eslint/js";
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";
import { fixupConfigRules } from "@eslint/compat";
import pluginReact from "eslint-plugin-react";


export default [
{files: ["**/*.{js,mjs,cjs,jsx}"]},
{ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } },
{languageOptions: { globals: globals.browser }},
{files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}},
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
pluginJs.configs.recommended,
...fixupConfigRules(pluginReactConfig),
pluginReact.configs.flat.recommended,
];",
"configFilename": "eslint.config.js",
"devDependencies": [
"eslint@9.x",
"globals",
"@eslint/js",
"eslint-plugin-react",
"@eslint/compat",
],
"installFlags": [
"-D",
"--force",
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
"configContent": "import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";
import { fixupConfigRules } from "@eslint/compat";
import pluginReact from "eslint-plugin-react";


export default [
{files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"]},
{ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } },
{languageOptions: { globals: globals.browser }},
{files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}},
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
...fixupConfigRules(pluginReactConfig),
pluginReact.configs.flat.recommended,
];",
"configFilename": "eslint.config.js",
"devDependencies": [
Expand All @@ -21,7 +20,6 @@ export default [
"@eslint/js",
"typescript-eslint",
"eslint-plugin-react",
"@eslint/compat",
],
"installFlags": [
"-D",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"configContent": "import globals from "globals";
import pluginJs from "@eslint/js";
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";
import pluginReact from "eslint-plugin-react";


export default [
{files: ["**/*.{js,mjs,cjs,jsx}"]},
{ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } },
{languageOptions: { globals: globals.browser }},
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
pluginJs.configs.recommended,
pluginReactConfig,
pluginReact.configs.flat.recommended,
];",
"configFilename": "eslint.config.js",
"devDependencies": [
"eslint@8.x",
"eslint@9.x",
"globals",
"@eslint/js",
"eslint-plugin-react",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
"configContent": "import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";
import pluginReact from "eslint-plugin-react";


export default [
{files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"]},
{ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } },
{languageOptions: { globals: globals.browser }},
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
pluginReactConfig,
pluginReact.configs.flat.recommended,
];",
"configFilename": "eslint.config.js",
"devDependencies": [
"eslint@8.x",
"eslint@9.x",
"globals",
"@eslint/js",
"typescript-eslint",
Expand Down
24 changes: 24 additions & 0 deletions tests/__snapshots__/problems-script-react-javascript
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"configContent": "import globals from "globals";
import pluginJs from "@eslint/js";
import pluginReact from "eslint-plugin-react";


export default [
{files: ["**/*.{js,mjs,cjs,jsx}"]},
{files: ["**/*.js"], languageOptions: {sourceType: "script"}},
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
pluginJs.configs.recommended,
pluginReact.configs.flat.recommended,
];",
"configFilename": "eslint.config.js",
"devDependencies": [
"eslint@9.x",
"globals",
"@eslint/js",
"eslint-plugin-react",
],
"installFlags": [
"-D",
],
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
{
"configContent": "import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";
import { fixupConfigRules } from "@eslint/compat";
import pluginReact from "eslint-plugin-react";


export default [
{files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"]},
{ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } },
{languageOptions: { globals: globals.browser }},
{files: ["**/*.js"], languageOptions: {sourceType: "script"}},
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
...fixupConfigRules(pluginReactConfig),
pluginReact.configs.flat.recommended,
];",
"configFilename": "eslint.config.js",
"devDependencies": [
"eslint@9.x",
"globals",
"@eslint/js",
"typescript-eslint",
"eslint-plugin-react",
"@eslint/compat",
],
"installFlags": [
"-D",
Expand Down
21 changes: 21 additions & 0 deletions tests/__snapshots__/syntax-commonjs-react-javascript
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"configContent": "import globals from "globals";
import pluginReact from "eslint-plugin-react";


export default [
{files: ["**/*.{js,mjs,cjs,jsx}"]},
{files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}},
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
pluginReact.configs.flat.recommended,
];",
"configFilename": "eslint.config.js",
"devDependencies": [
"eslint@9.x",
"globals",
"eslint-plugin-react",
],
"installFlags": [
"-D",
],
}
25 changes: 25 additions & 0 deletions tests/__snapshots__/syntax-commonjs-react-typescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"configContent": "import globals from "globals";
import tseslint from "typescript-eslint";
import pluginReact from "eslint-plugin-react";


export default [
{files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"]},
{files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}},
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
...tseslint.configs.recommended,
pluginReact.configs.flat.recommended,
];",
"configFilename": "eslint.config.js",
"devDependencies": [
"eslint@9.x",
"globals",
"typescript-eslint",
"eslint-plugin-react",
],
"installFlags": [
"-D",
"--force",
],
}
24 changes: 0 additions & 24 deletions tests/__snapshots__/syntax-esm-react-eslint9.x-javascript

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
{
"configContent": "import globals from "globals";
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";
import pluginReact from "eslint-plugin-react";


export default [
{files: ["**/*.{js,mjs,cjs,jsx}"]},
{ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } },
{languageOptions: { globals: globals.browser }},
pluginReactConfig,
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
pluginReact.configs.flat.recommended,
];",
"configFilename": "eslint.config.js",
"devDependencies": [
"eslint@8.x",
"eslint@9.x",
"globals",
"eslint-plugin-react",
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"configContent": "import globals from "globals";
import tseslint from "typescript-eslint";
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";
import pluginReact from "eslint-plugin-react";


export default [
{files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"]},
{ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } },
{languageOptions: { globals: globals.browser }},
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
...tseslint.configs.recommended,
pluginReactConfig,
pluginReact.configs.flat.recommended,
];",
"configFilename": "eslint.config.js",
"devDependencies": [
"eslint@8.x",
"eslint@9.x",
"globals",
"typescript-eslint",
"eslint-plugin-react",
Expand Down
21 changes: 21 additions & 0 deletions tests/__snapshots__/syntax-script-react-javascript
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"configContent": "import globals from "globals";
import pluginReact from "eslint-plugin-react";


export default [
{files: ["**/*.{js,mjs,cjs,jsx}"]},
{files: ["**/*.js"], languageOptions: {sourceType: "script"}},
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
pluginReact.configs.flat.recommended,
];",
"configFilename": "eslint.config.js",
"devDependencies": [
"eslint@9.x",
"globals",
"eslint-plugin-react",
],
"installFlags": [
"-D",
],
}
25 changes: 25 additions & 0 deletions tests/__snapshots__/syntax-script-react-typescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"configContent": "import globals from "globals";
import tseslint from "typescript-eslint";
import pluginReact from "eslint-plugin-react";


export default [
{files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"]},
{files: ["**/*.js"], languageOptions: {sourceType: "script"}},
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
...tseslint.configs.recommended,
pluginReact.configs.flat.recommended,
];",
"configFilename": "eslint.config.js",
"devDependencies": [
"eslint@9.x",
"globals",
"typescript-eslint",
"eslint-plugin-react",
],
"installFlags": [
"-D",
"--force",
],
}
Loading
Loading