From 6736f3dc19682d2cead9aef67b0f27ec51700658 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Mon, 10 Jun 2024 13:58:33 +0200 Subject: [PATCH] fix: enable linting `.jsx` files when React is selected (#126) --- lib/config-generator.js | 1 + tests/__snapshots__/problems-esm-react-eslint8.x-javascript | 1 + tests/__snapshots__/problems-esm-react-eslint8.x-typescript | 1 + tests/__snapshots__/problems-esm-react-eslint9.x-javascript | 1 + tests/__snapshots__/problems-esm-react-eslint9.x-typescript | 1 + tests/__snapshots__/syntax-esm-react-eslint8.x-javascript | 1 + tests/__snapshots__/syntax-esm-react-eslint8.x-typescript | 1 + tests/__snapshots__/syntax-esm-react-eslint9.x-javascript | 1 + tests/__snapshots__/syntax-esm-react-eslint9.x-typescript | 1 + 9 files changed, 9 insertions(+) diff --git a/lib/config-generator.js b/lib/config-generator.js index bc1615e5..3e364fae 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -181,6 +181,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug } if (this.answers.framework === "react") { + exportContent += " { files: [\"**/*.jsx\"], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } },\n"; if (this.answers.eslintVersion === "9.x") { this.result.devDependencies.push("eslint-plugin-react", "@eslint/compat"); if (!this.result.installFlags.includes("--force")) { diff --git a/tests/__snapshots__/problems-esm-react-eslint8.x-javascript b/tests/__snapshots__/problems-esm-react-eslint8.x-javascript index c7dde98a..c91ae4d5 100644 --- a/tests/__snapshots__/problems-esm-react-eslint8.x-javascript +++ b/tests/__snapshots__/problems-esm-react-eslint8.x-javascript @@ -7,6 +7,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ {languageOptions: { globals: globals.browser }}, pluginJs.configs.recommended, + { files: ["**/*.jsx"], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-esm-react-eslint8.x-typescript b/tests/__snapshots__/problems-esm-react-eslint8.x-typescript index 0766165e..b51f1553 100644 --- a/tests/__snapshots__/problems-esm-react-eslint8.x-typescript +++ b/tests/__snapshots__/problems-esm-react-eslint8.x-typescript @@ -9,6 +9,7 @@ export default [ {languageOptions: { globals: globals.browser }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, + { files: ["**/*.jsx"], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-esm-react-eslint9.x-javascript b/tests/__snapshots__/problems-esm-react-eslint9.x-javascript index efcf1803..1f1f178b 100644 --- a/tests/__snapshots__/problems-esm-react-eslint9.x-javascript +++ b/tests/__snapshots__/problems-esm-react-eslint9.x-javascript @@ -8,6 +8,7 @@ import { fixupConfigRules } from "@eslint/compat"; export default [ {languageOptions: { globals: globals.browser }}, pluginJs.configs.recommended, + { files: ["**/*.jsx"], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, ...fixupConfigRules(pluginReactConfig), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-esm-react-eslint9.x-typescript b/tests/__snapshots__/problems-esm-react-eslint9.x-typescript index 1a3caf6e..ea4069eb 100644 --- a/tests/__snapshots__/problems-esm-react-eslint9.x-typescript +++ b/tests/__snapshots__/problems-esm-react-eslint9.x-typescript @@ -10,6 +10,7 @@ export default [ {languageOptions: { globals: globals.browser }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, + { files: ["**/*.jsx"], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, ...fixupConfigRules(pluginReactConfig), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-react-eslint8.x-javascript b/tests/__snapshots__/syntax-esm-react-eslint8.x-javascript index 558a41e0..d7edee3b 100644 --- a/tests/__snapshots__/syntax-esm-react-eslint8.x-javascript +++ b/tests/__snapshots__/syntax-esm-react-eslint8.x-javascript @@ -5,6 +5,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ {languageOptions: { globals: globals.browser }}, + { files: ["**/*.jsx"], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-react-eslint8.x-typescript b/tests/__snapshots__/syntax-esm-react-eslint8.x-typescript index 7de661a8..340ee960 100644 --- a/tests/__snapshots__/syntax-esm-react-eslint8.x-typescript +++ b/tests/__snapshots__/syntax-esm-react-eslint8.x-typescript @@ -7,6 +7,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ {languageOptions: { globals: globals.browser }}, ...tseslint.configs.recommended, + { files: ["**/*.jsx"], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-react-eslint9.x-javascript b/tests/__snapshots__/syntax-esm-react-eslint9.x-javascript index 30938718..8694f3d3 100644 --- a/tests/__snapshots__/syntax-esm-react-eslint9.x-javascript +++ b/tests/__snapshots__/syntax-esm-react-eslint9.x-javascript @@ -6,6 +6,7 @@ import { fixupConfigRules } from "@eslint/compat"; export default [ {languageOptions: { globals: globals.browser }}, + { files: ["**/*.jsx"], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, ...fixupConfigRules(pluginReactConfig), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-react-eslint9.x-typescript b/tests/__snapshots__/syntax-esm-react-eslint9.x-typescript index a5fb880f..e77935b5 100644 --- a/tests/__snapshots__/syntax-esm-react-eslint9.x-typescript +++ b/tests/__snapshots__/syntax-esm-react-eslint9.x-typescript @@ -8,6 +8,7 @@ import { fixupConfigRules } from "@eslint/compat"; export default [ {languageOptions: { globals: globals.browser }}, ...tseslint.configs.recommended, + { files: ["**/*.jsx"], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } } }, ...fixupConfigRules(pluginReactConfig), ];", "configFilename": "eslint.config.js",