diff --git a/.changeset/curly-socks-boil.md b/.changeset/curly-socks-boil.md new file mode 100644 index 00000000000..e5b52c308f2 --- /dev/null +++ b/.changeset/curly-socks-boil.md @@ -0,0 +1,5 @@ +--- +'@graphql-eslint/eslint-plugin': patch +--- + +fix `require is not defined` in flat configs for Vue/Svelte projects diff --git a/examples/monorepo/eslint.config.js b/examples/monorepo/eslint.config.js index 1f935982bc6..713d01f582e 100644 --- a/examples/monorepo/eslint.config.js +++ b/examples/monorepo/eslint.config.js @@ -14,7 +14,6 @@ export default [ processor: graphql.processors.graphql, languageOptions: { parserOptions: { - sourceType: 'module', ecmaFeatures: { jsx: true, }, diff --git a/examples/multiple-projects-graphql-config/.eslintrc.cjs b/examples/multiple-projects-graphql-config/.eslintrc.cjs deleted file mode 100644 index 2fd9e698c86..00000000000 --- a/examples/multiple-projects-graphql-config/.eslintrc.cjs +++ /dev/null @@ -1,31 +0,0 @@ -module.exports = { - root: true, - // ❗️ It's very important that you don't have any rules configured at the top-level config, - // and to move all configurations into the overrides section. Since JavaScript rules - // can't run on GraphQL files and vice versa, if you have rules configured at the top level, - // they will try to also execute for all overrides, as ESLint's configs cascade - overrides: [ - { - files: ['*.js'], - processor: '@graphql-eslint/graphql', - extends: ['eslint:recommended'], - parserOptions: { - sourceType: 'module', - }, - env: { - es6: true, - }, - }, - { - files: ['schema.*.graphql'], - extends: ['plugin:@graphql-eslint/schema-recommended'], - rules: { - '@graphql-eslint/require-description': 'off', - }, - }, - { - files: ['*.js/*.graphql'], - extends: ['plugin:@graphql-eslint/operations-recommended'], - }, - ], -}; diff --git a/examples/multiple-projects-graphql-config/eslint.config.js b/examples/multiple-projects-graphql-config/eslint.config.js new file mode 100644 index 00000000000..5e03caa73fe --- /dev/null +++ b/examples/multiple-projects-graphql-config/eslint.config.js @@ -0,0 +1,31 @@ +import js from '@eslint/js'; +import * as graphql from '@graphql-eslint/eslint-plugin'; + +export default [ + { + files: ['**/*.js'], + processor: graphql.processors.graphql, + rules: js.configs.recommended.rules, + }, + { + // Setup GraphQL Parser + files: ['**/*.graphql'], + plugins: { + '@graphql-eslint': { rules: graphql.rules }, + }, + languageOptions: { + parser: graphql.parser, + }, + }, + { + files: ['schema.*.graphql'], + rules: { + ...graphql.flatConfigs['schema-recommended'].rules, + '@graphql-eslint/require-description': 'off', + }, + }, + { + files: ['**/*.js/*.graphql'], + rules: graphql.flatConfigs['operations-recommended'].rules, + }, +]; diff --git a/examples/multiple-projects-graphql-config/package.json b/examples/multiple-projects-graphql-config/package.json index 0e7560074e4..69bc563836b 100644 --- a/examples/multiple-projects-graphql-config/package.json +++ b/examples/multiple-projects-graphql-config/package.json @@ -1,10 +1,11 @@ { "name": "@graphql-eslint/example-multiple-projects-graphql-config", "version": "0.0.0", + "type": "module", "author": "Dimitri POSTOLOV", "private": true, "scripts": { - "lint": "ESLINT_USE_FLAT_CONFIG=false eslint --cache ." + "lint": "eslint --cache ." }, "dependencies": { "graphql": "16.9.0" diff --git a/examples/svelte-code-file/.eslintrc.cjs b/examples/svelte-code-file/.eslintrc.cjs deleted file mode 100644 index 97faed2fdbf..00000000000 --- a/examples/svelte-code-file/.eslintrc.cjs +++ /dev/null @@ -1,37 +0,0 @@ -module.exports = { - root: true, - // ❗️ It's very important that you don't have any rules configured at the top-level config, - // and to move all configurations into the overrides section. Since JavaScript rules - // can't run on GraphQL files and vice versa, if you have rules configured at the top level, - // they will try to also execute for all overrides, as ESLint's configs cascade - overrides: [ - { - files: ['*.js', '*.svelte'], - parser: 'svelte-eslint-parser', - processor: '@graphql-eslint/graphql', - extends: ['eslint:recommended'], - env: { - es6: true, - }, - }, - { - files: ['*.graphql'], - parser: '@graphql-eslint/eslint-plugin', - plugins: ['@graphql-eslint'], - rules: { - '@graphql-eslint/no-anonymous-operations': 'error', - '@graphql-eslint/no-duplicate-fields': 'error', - '@graphql-eslint/naming-convention': [ - 'error', - { - OperationDefinition: { - style: 'PascalCase', - forbiddenPrefixes: ['Query', 'Mutation', 'Subscription', 'Get'], - forbiddenSuffixes: ['Query', 'Mutation', 'Subscription'], - }, - }, - ], - }, - }, - ], -}; diff --git a/examples/svelte-code-file/eslint.config.js b/examples/svelte-code-file/eslint.config.js new file mode 100644 index 00000000000..f0f9321df99 --- /dev/null +++ b/examples/svelte-code-file/eslint.config.js @@ -0,0 +1,40 @@ +import svelteParser from 'svelte-eslint-parser'; +import js from '@eslint/js'; +import * as graphql from '@graphql-eslint/eslint-plugin'; + +export default [ + { + files: ['**/*.js', '**/*.svelte'], + processor: graphql.processors.graphql, + rules: js.configs.recommended.rules, + }, + { + files: ['**/*.svelte'], + languageOptions: { + parser: svelteParser, + }, + }, + { + files: ['**/*.graphql'], + languageOptions: { + parser: graphql.parser, + }, + plugins: { + '@graphql-eslint': { rules: graphql.rules }, + }, + rules: { + '@graphql-eslint/no-anonymous-operations': 'error', + '@graphql-eslint/no-duplicate-fields': 'error', + '@graphql-eslint/naming-convention': [ + 'error', + { + OperationDefinition: { + style: 'PascalCase', + forbiddenPrefixes: ['Query', 'Mutation', 'Subscription', 'Get'], + forbiddenSuffixes: ['Query', 'Mutation', 'Subscription'], + }, + }, + ], + }, + }, +]; diff --git a/examples/svelte-code-file/package.json b/examples/svelte-code-file/package.json index f131bf08847..964181b212d 100644 --- a/examples/svelte-code-file/package.json +++ b/examples/svelte-code-file/package.json @@ -5,7 +5,7 @@ "author": "Dimitri POSTOLOV", "private": true, "scripts": { - "lint": "ESLINT_USE_FLAT_CONFIG=false eslint --cache ." + "lint": "eslint --cache ." }, "dependencies": { "graphql": "16.9.0" diff --git a/examples/vue-code-file/.eslintrc.cjs b/examples/vue-code-file/.eslintrc.cjs deleted file mode 100644 index 05d204d8b7e..00000000000 --- a/examples/vue-code-file/.eslintrc.cjs +++ /dev/null @@ -1,37 +0,0 @@ -module.exports = { - root: true, - // ❗️ It's very important that you don't have any rules configured at the top-level config, - // and to move all configurations into the overrides section. Since JavaScript rules - // can't run on GraphQL files and vice versa, if you have rules configured at the top level, - // they will try to also execute for all overrides, as ESLint's configs cascade - overrides: [ - { - files: ['*.js', '*.vue'], - parser: 'vue-eslint-parser', - processor: '@graphql-eslint/graphql', - extends: ['eslint:recommended'], - env: { - es6: true, - }, - }, - { - files: ['*.graphql'], - parser: '@graphql-eslint/eslint-plugin', - plugins: ['@graphql-eslint'], - rules: { - '@graphql-eslint/no-anonymous-operations': 'error', - '@graphql-eslint/no-duplicate-fields': 'error', - '@graphql-eslint/naming-convention': [ - 'error', - { - OperationDefinition: { - style: 'PascalCase', - forbiddenPrefixes: ['Query', 'Mutation', 'Subscription', 'Get'], - forbiddenSuffixes: ['Query', 'Mutation', 'Subscription'], - }, - }, - ], - }, - }, - ], -}; diff --git a/examples/vue-code-file/eslint.config.js b/examples/vue-code-file/eslint.config.js new file mode 100644 index 00000000000..68feeb2294f --- /dev/null +++ b/examples/vue-code-file/eslint.config.js @@ -0,0 +1,40 @@ +import vueParser from 'vue-eslint-parser'; +import js from '@eslint/js'; +import * as graphql from '@graphql-eslint/eslint-plugin'; + +export default [ + { + files: ['**/*.js', '**/*.vue'], + processor: graphql.processors.graphql, + rules: js.configs.recommended.rules, + }, + { + files: ['**/*.vue'], + languageOptions: { + parser: vueParser, + }, + }, + { + files: ['**/*.graphql'], + languageOptions: { + parser: graphql.parser, + }, + plugins: { + '@graphql-eslint': { rules: graphql.rules }, + }, + rules: { + '@graphql-eslint/no-anonymous-operations': 'error', + '@graphql-eslint/no-duplicate-fields': 'error', + '@graphql-eslint/naming-convention': [ + 'error', + { + OperationDefinition: { + style: 'PascalCase', + forbiddenPrefixes: ['Query', 'Mutation', 'Subscription', 'Get'], + forbiddenSuffixes: ['Query', 'Mutation', 'Subscription'], + }, + }, + ], + }, + }, +]; diff --git a/examples/vue-code-file/package.json b/examples/vue-code-file/package.json index f695c1b93d2..3f16030dbd6 100644 --- a/examples/vue-code-file/package.json +++ b/examples/vue-code-file/package.json @@ -5,7 +5,7 @@ "author": "Dimitri POSTOLOV", "private": true, "scripts": { - "lint": "ESLINT_USE_FLAT_CONFIG=false eslint --cache ." + "lint": "eslint --cache ." }, "dependencies": { "graphql": "16.9.0" diff --git a/packages/plugin/package.json b/packages/plugin/package.json index debf5739b8a..095f59ed19b 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -45,7 +45,7 @@ }, "dependencies": { "@graphql-tools/code-file-loader": "^8.0.0", - "@graphql-tools/graphql-tag-pluck": "^8.0.0", + "@graphql-tools/graphql-tag-pluck": "8.3.2-alpha-20240803110708-298aeb8bb2ca4ef649bf09fc42f82fc88c6d5e13", "@graphql-tools/utils": "^10.0.0", "debug": "^4.3.4", "fast-glob": "^3.2.12", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 86876fd898c..cb0489ac183 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -241,8 +241,8 @@ importers: specifier: ^8.0.0 version: 8.1.2(graphql@16.9.0) '@graphql-tools/graphql-tag-pluck': - specifier: ^8.0.0 - version: 8.3.1(graphql@16.9.0) + specifier: 8.3.2-alpha-20240803110708-298aeb8bb2ca4ef649bf09fc42f82fc88c6d5e13 + version: 8.3.2-alpha-20240803110708-298aeb8bb2ca4ef649bf09fc42f82fc88c6d5e13(graphql@16.9.0) '@graphql-tools/utils': specifier: ^10.0.0 version: 10.3.2(graphql@16.9.0) @@ -944,6 +944,12 @@ packages: peerDependencies: graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 + '@graphql-tools/graphql-tag-pluck@8.3.2-alpha-20240803110708-298aeb8bb2ca4ef649bf09fc42f82fc88c6d5e13': + resolution: {integrity: sha512-Y+Sk4y19MO2nDYMG4I/FFP1RJ/LMMypKi0AxE+xrRdemnMBAj0cO2yL05+WpuKHQjryDMYl9KomQzQA1M0Jjnw==} + engines: {node: '>=16.0.0'} + peerDependencies: + graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 + '@graphql-tools/import@7.0.1': resolution: {integrity: sha512-935uAjAS8UAeXThqHfYVr4HEAp6nHJ2sximZKO1RzUTq5WoALMAhhGARl0+ecm6X+cqNUwIChJbjtaa6P/ML0w==} engines: {node: '>=16.0.0'} @@ -6957,6 +6963,19 @@ snapshots: transitivePeerDependencies: - supports-color + '@graphql-tools/graphql-tag-pluck@8.3.2-alpha-20240803110708-298aeb8bb2ca4ef649bf09fc42f82fc88c6d5e13(graphql@16.9.0)': + dependencies: + '@babel/core': 7.24.9 + '@babel/parser': 7.25.0 + '@babel/plugin-syntax-import-assertions': 7.24.7(@babel/core@7.24.9) + '@babel/traverse': 7.25.1 + '@babel/types': 7.25.0 + '@graphql-tools/utils': 10.3.2(graphql@16.9.0) + graphql: 16.9.0 + tslib: 2.6.3 + transitivePeerDependencies: + - supports-color + '@graphql-tools/import@7.0.1(graphql@16.9.0)': dependencies: '@graphql-tools/utils': 10.3.2(graphql@16.9.0)