diff --git a/.changeset/young-cups-shout.md b/.changeset/young-cups-shout.md new file mode 100644 index 00000000000..4fe2514e93e --- /dev/null +++ b/.changeset/young-cups-shout.md @@ -0,0 +1,5 @@ +--- +'@graphql-eslint/eslint-plugin': patch +--- + +fix error report for `no-deprecated` rule diff --git a/packages/plugin/src/rules/no-deprecated.ts b/packages/plugin/src/rules/no-deprecated.ts index 82235a35fcc..047472331f4 100644 --- a/packages/plugin/src/rules/no-deprecated.ts +++ b/packages/plugin/src/rules/no-deprecated.ts @@ -1,4 +1,4 @@ -import { requireGraphQLSchemaFromContext } from '../utils'; +import { getLocation, requireGraphQLSchemaFromContext } from '../utils'; import { GraphQLESLintRule } from '../types'; const NO_DEPRECATED = 'NO_DEPRECATED'; @@ -47,8 +47,8 @@ const rule: GraphQLESLintRule<[], true> = { mutation { changeSomething( type: OLD # This is deprecated, so you'll get an error - ) { - ... + ) { + ... } } `, @@ -87,8 +87,9 @@ const rule: GraphQLESLintRule<[], true> = { if (typeInfo && typeInfo.enumValue) { if (typeInfo.enumValue.isDeprecated) { + const enumValueName = node.value; context.report({ - loc: node.loc, + loc: getLocation(node.loc, enumValueName), messageId: NO_DEPRECATED, data: { type: 'enum value', @@ -104,8 +105,9 @@ const rule: GraphQLESLintRule<[], true> = { if (typeInfo && typeInfo.fieldDef) { if (typeInfo.fieldDef.isDeprecated) { + const fieldName = node.name.value; context.report({ - loc: node.loc, + loc: getLocation(node.loc, fieldName), messageId: NO_DEPRECATED, data: { type: 'field', diff --git a/packages/plugin/tests/__snapshots__/no-deprecated.spec.ts.snap b/packages/plugin/tests/__snapshots__/no-deprecated.spec.ts.snap index 1b32ecd9517..67977d7f26c 100644 --- a/packages/plugin/tests/__snapshots__/no-deprecated.spec.ts.snap +++ b/packages/plugin/tests/__snapshots__/no-deprecated.spec.ts.snap @@ -2,20 +2,20 @@ exports[` 1`] = ` > 1 | mutation { something(t: OLD) } - | ^ This enum value is marked as deprecated in your GraphQL schema (reason: No longer supported) + | ^^^ This enum value is marked as deprecated in your GraphQL schema (reason: No longer supported) `; exports[` 2`] = ` > 1 | mutation { something(t: OLD_WITH_REASON) } - | ^ This enum value is marked as deprecated in your GraphQL schema (reason: test) + | ^^^^^^^^^^^^^^^ This enum value is marked as deprecated in your GraphQL schema (reason: test) `; exports[` 3`] = ` > 1 | query { oldField } - | ^ This field is marked as deprecated in your GraphQL schema (reason: No longer supported) + | ^^^^^^^^ This field is marked as deprecated in your GraphQL schema (reason: No longer supported) `; exports[` 4`] = ` > 1 | query { oldFieldWithReason } - | ^ This field is marked as deprecated in your GraphQL schema (reason: test) + | ^^^^^^^^^^^^^^^^^^ This field is marked as deprecated in your GraphQL schema (reason: test) `;