Skip to content
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
6 changes: 6 additions & 0 deletions .changeset/lovely-laws-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-eslint/eslint-plugin': patch
---

add `meta` object with `name` and `version` to `parser` and `processor` to be compatible with ESLint
9
8 changes: 4 additions & 4 deletions examples/code-file/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import js from '@eslint/js';
import * as graphqlESLint from '@graphql-eslint/eslint-plugin';
import * as graphql from '@graphql-eslint/eslint-plugin';

export default [
{
files: ['**/*.js'],
processor: graphqlESLint.processors.graphql,
processor: graphql.processors.graphql,
rules: {
...js.configs.recommended.rules,
'no-console': 'error',
Expand All @@ -13,10 +13,10 @@ export default [
{
files: ['**/*.graphql'],
plugins: {
'@graphql-eslint': graphqlESLint,
'@graphql-eslint': { rules: graphql.rules },
},
languageOptions: {
parser: graphqlESLint,
parser: graphql.parser,
},
rules: {
'@graphql-eslint/no-anonymous-operations': 'error',
Expand Down
2 changes: 1 addition & 1 deletion examples/code-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Dotan Simha <[email protected]>",
"private": true,
"scripts": {
"lint": "eslint ."
"lint": "eslint --cache ."
},
"dependencies": {
"graphql": "16.9.0"
Expand Down
6 changes: 3 additions & 3 deletions examples/graphql-config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import js from '@eslint/js';
import * as graphqlESLint from '@graphql-eslint/eslint-plugin';
import * as graphql from '@graphql-eslint/eslint-plugin';

export default [
{
Expand All @@ -9,10 +9,10 @@ export default [
{
files: ['**/*.graphql'],
plugins: {
'@graphql-eslint': graphqlESLint,
'@graphql-eslint': { rules: graphql.rules },
},
languageOptions: {
parser: graphqlESLint,
parser: graphql.parser,
},
rules: {
'@graphql-eslint/no-anonymous-operations': 'error',
Expand Down
2 changes: 1 addition & 1 deletion examples/graphql-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Dotan Simha <[email protected]>",
"private": true,
"scripts": {
"lint": "eslint ."
"lint": "eslint --cache ."
},
"dependencies": {
"graphql": "16.9.0"
Expand Down
12 changes: 6 additions & 6 deletions examples/monorepo/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import js from '@eslint/js';
import * as graphqlESLint from '@graphql-eslint/eslint-plugin';
import * as graphql from '@graphql-eslint/eslint-plugin';

const SCHEMA_PATH = 'server/**/*.gql';

Expand All @@ -11,7 +11,7 @@ export default [
{
files: ['client/**/*.tsx'],
// Setup processor for operations/fragments definitions on code-files
processor: graphqlESLint.processors.graphql,
processor: graphql.processors.graphql,
languageOptions: {
parserOptions: {
sourceType: 'module',
Expand All @@ -25,20 +25,20 @@ export default [
// Setup GraphQL Parser
files: ['**/*.{graphql,gql}'],
plugins: {
'@graphql-eslint': graphqlESLint,
'@graphql-eslint': { rules: graphql.rules },
},
languageOptions: {
parser: graphqlESLint,
parser: graphql.parser,
},
},
{
// Setup recommended config for schema files
files: [SCHEMA_PATH],
...graphqlESLint.flatConfigs['schema-recommended'],
...graphql.flatConfigs['schema-recommended'],
},
{
// Setup recommended config for operations files
files: ['client/**/*.{graphql,gql}'],
...graphqlESLint.flatConfigs['operations-recommended'],
...graphql.flatConfigs['operations-recommended'],
},
];
2 changes: 1 addition & 1 deletion examples/monorepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Dimitri POSTOLOV",
"private": true,
"scripts": {
"lint": "eslint ."
"lint": "eslint --cache ."
},
"dependencies": {
"graphql": "16.9.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple-projects-graphql-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "Dimitri POSTOLOV",
"private": true,
"scripts": {
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint ."
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint --cache ."
},
"dependencies": {
"graphql": "16.9.0"
Expand Down
10 changes: 5 additions & 5 deletions examples/prettier/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import prettierConfig from 'eslint-config-prettier';
import prettierPlugin from 'eslint-plugin-prettier';
import js from '@eslint/js';
import * as graphqlESLint from '@graphql-eslint/eslint-plugin';
import * as graphql from '@graphql-eslint/eslint-plugin';

export default [
{
plugins: {
prettier: prettierPlugin,
prettier: { rules: prettierPlugin.rules },
},
},
{
files: ['**/*.js'],
processor: graphqlESLint.processors.graphql,
processor: graphql.processors.graphql,
rules: {
...js.configs.recommended.rules,
...prettierConfig.rules,
Expand All @@ -21,10 +21,10 @@ export default [
{
files: ['**/*.graphql'],
languageOptions: {
parser: graphqlESLint,
parser: graphql.parser,
},
plugins: {
'@graphql-eslint': graphqlESLint,
'@graphql-eslint': { rules: graphql.rules },
},
rules: {
'prettier/prettier': 'error',
Expand Down
2 changes: 1 addition & 1 deletion examples/prettier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "JounQin <[email protected]>",
"private": true,
"scripts": {
"lint": "eslint ."
"lint": "eslint --cache ."
},
"dependencies": {
"graphql": "16.9.0"
Expand Down
6 changes: 3 additions & 3 deletions examples/programmatic/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import js from '@eslint/js';
import * as graphqlESLint from '@graphql-eslint/eslint-plugin';
import * as graphql from '@graphql-eslint/eslint-plugin';

export default [
{
Expand All @@ -9,10 +9,10 @@ export default [
{
files: ['**/*.graphql'],
plugins: {
'@graphql-eslint': graphqlESLint,
'@graphql-eslint': { rules: graphql.rules },
},
languageOptions: {
parser: graphqlESLint,
parser: graphql.parser,
parserOptions: {
graphQLConfig: {
schema: 'schema.graphql',
Expand Down
2 changes: 1 addition & 1 deletion examples/programmatic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Dotan Simha <[email protected]>",
"private": true,
"scripts": {
"lint": "eslint ."
"lint": "eslint --cache ."
},
"dependencies": {
"graphql": "16.9.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/svelte-code-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Dimitri POSTOLOV",
"private": true,
"scripts": {
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint ."
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint --cache ."
},
"dependencies": {
"graphql": "16.9.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/vue-code-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Dimitri POSTOLOV",
"private": true,
"scripts": {
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint ."
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint --cache ."
},
"dependencies": {
"graphql": "16.9.0"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@changesets/cli": "2.27.7",
"@graphql-tools/utils": "10.3.2",
"@theguild/eslint-config": "0.11.10",
"@theguild/prettier-config": "2.0.6",
"@theguild/prettier-config": "2.0.7",
"@types/dedent": "0.7.2",
"@types/node": "20.14.13",
"bob-the-bundler": "7.0.1",
Expand Down
13 changes: 12 additions & 1 deletion packages/plugin/__tests__/examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ ${results.map(result => result.messages.map(m => m.message)).join('\n\n')}

function getESLintOutput(cwd: string): ESLint.LintResult[] {
const { stdout, stderr } = spawnSync('eslint', ['.', '--format', 'json'], { cwd });
const errorOutput = stderr.toString();
const errorOutput = stderr
.toString()
.replace(
/\(node:\d{4,5}\) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time/,
'',
)
.replace(
/\(node:\d{4}\) ExperimentalWarning: Import assertions are not a stable feature of the JavaScript language. Avoid relying on their current behavior and syntax as those might change in a future version of Node.js./,
'',
)
.replace('(Use `node --trace-warnings ...` to show where the warning was created)', '')
.trimEnd();
if (errorOutput) {
throw new Error(errorOutput);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/__tests__/rules.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FlatESLint } from 'eslint/use-at-your-own-risk';
import { configs, parseForESLint, rules } from '@graphql-eslint/eslint-plugin';
import { configs, parser, rules } from '@graphql-eslint/eslint-plugin';
import { ParserOptionsForTests } from './test-utils.js';

export function getESLintWithConfig(
Expand All @@ -12,7 +12,7 @@ export function getESLintWithConfig(
{
files: ['*.graphql'],
languageOptions: {
parser: { parseForESLint },
parser,
parserOptions: {
graphQLConfig: {
schema: 'type Query { foo: Int }',
Expand Down
6 changes: 2 additions & 4 deletions packages/plugin/src/flat-configs.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { configs } from './configs/index.js';
import { parseForESLint } from './parser.js';
import { parser } from './parser.js';
import { ConfigName } from './types.js';

const languageOptions = {
parser: { parseForESLint },
};
const languageOptions = { parser };

export const flatConfigs = {
'operations-all': {
Expand Down
4 changes: 1 addition & 3 deletions packages/plugin/src/index.browser.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// rewrite exports because we don't need `processors` export that has fs related dependencies

export { parseForESLint } from './parser.js';
export { parser } from './parser.js';
export { rules } from './rules/index.js';
export * from './types.js';
export { requireGraphQLSchemaFromContext, requireSiblingsOperations } from './utils.js';
export { configs } from './configs/index.js';
export { flatConfigs } from './flat-configs.js';
2 changes: 1 addition & 1 deletion packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { processor } from './processor.js';

export { parseForESLint } from './parser.js';
export { parser, parseForESLint } from './parser.js';
export { rules } from './rules/index.js';
export * from './types.js';
export { requireGraphQLSchemaFromContext, requireSiblingsOperations } from './utils.js';
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin/src/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import packageJson from '../package.json' assert { type: 'json' };

export const { name, version } = packageJson;
9 changes: 9 additions & 0 deletions packages/plugin/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parseGraphQLSDL, Source } from '@graphql-tools/utils';
import { getDocuments } from './documents.js';
import { convertToESTree, extractComments, extractTokens } from './estree-converter/index.js';
import { loadGraphQLConfig } from './graphql-config.js';
import { version } from './meta.js';
import { getSchema } from './schema.js';
import { getSiblings } from './siblings.js';
import { GraphQLESLintParseResult, ParserOptions, Schema } from './types.js';
Expand Down Expand Up @@ -110,3 +111,11 @@ export function parseForESLint(code: string, options: ParserOptions): GraphQLESL
throw error;
}
}

export const parser = {
parseForESLint,
meta: {
name: '@graphql-eslint/parser',
version,
},
};
5 changes: 5 additions & 0 deletions packages/plugin/src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@graphql-tools/graphql-tag-pluck';
import { asArray } from '@graphql-tools/utils';
import { loadOnDiskGraphQLConfig } from './graphql-config.js';
import { version } from './meta.js';
import { CWD, REPORT_ON_FIRST_CHARACTER, truthy } from './utils.js';

export type Block = Linter.ProcessorFile & {
Expand All @@ -22,6 +23,10 @@ let onDiskConfigLoaded = false;
const RELEVANT_KEYWORDS = ['gql', 'graphql', 'GraphQL'] as const;

export const processor = {
meta: {
name: '@graphql-eslint/processor',
version,
},
supportsAutofix: true,
preprocess(code, filePath) {
if (!onDiskConfigLoaded) {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es2022",
"module": "Node16",
"module": "nodenext",
"moduleResolution": "node16",
"declaration": false,
"noEmit": true,
Expand Down
1 change: 1 addition & 0 deletions packages/plugin/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default defineConfig([
{
...opts,
outDir: 'dist/esm',
target: 'esnext',
},
{
...opts,
Expand Down
Loading