Skip to content

Commit ced6789

Browse files
author
Dimitri POSTOLOV
authored
fix error report for no-deprecated rule (#739)
1 parent 7aa8157 commit ced6789

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

.changeset/young-cups-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
fix error report for `no-deprecated` rule

packages/plugin/src/rules/no-deprecated.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { requireGraphQLSchemaFromContext } from '../utils';
1+
import { getLocation, requireGraphQLSchemaFromContext } from '../utils';
22
import { GraphQLESLintRule } from '../types';
33

44
const NO_DEPRECATED = 'NO_DEPRECATED';
@@ -47,8 +47,8 @@ const rule: GraphQLESLintRule<[], true> = {
4747
mutation {
4848
changeSomething(
4949
type: OLD # This is deprecated, so you'll get an error
50-
) {
51-
...
50+
) {
51+
...
5252
}
5353
}
5454
`,
@@ -87,8 +87,9 @@ const rule: GraphQLESLintRule<[], true> = {
8787

8888
if (typeInfo && typeInfo.enumValue) {
8989
if (typeInfo.enumValue.isDeprecated) {
90+
const enumValueName = node.value;
9091
context.report({
91-
loc: node.loc,
92+
loc: getLocation(node.loc, enumValueName),
9293
messageId: NO_DEPRECATED,
9394
data: {
9495
type: 'enum value',
@@ -104,8 +105,9 @@ const rule: GraphQLESLintRule<[], true> = {
104105

105106
if (typeInfo && typeInfo.fieldDef) {
106107
if (typeInfo.fieldDef.isDeprecated) {
108+
const fieldName = node.name.value;
107109
context.report({
108-
loc: node.loc,
110+
loc: getLocation(node.loc, fieldName),
109111
messageId: NO_DEPRECATED,
110112
data: {
111113
type: 'field',

packages/plugin/tests/__snapshots__/no-deprecated.spec.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
exports[` 1`] = `
44
> 1 | mutation { something(t: OLD) }
5-
| ^ This enum value is marked as deprecated in your GraphQL schema (reason: No longer supported)
5+
| ^^^ This enum value is marked as deprecated in your GraphQL schema (reason: No longer supported)
66
`;
77

88
exports[` 2`] = `
99
> 1 | mutation { something(t: OLD_WITH_REASON) }
10-
| ^ This enum value is marked as deprecated in your GraphQL schema (reason: test)
10+
| ^^^^^^^^^^^^^^^ This enum value is marked as deprecated in your GraphQL schema (reason: test)
1111
`;
1212

1313
exports[` 3`] = `
1414
> 1 | query { oldField }
15-
| ^ This field is marked as deprecated in your GraphQL schema (reason: No longer supported)
15+
| ^^^^^^^^ This field is marked as deprecated in your GraphQL schema (reason: No longer supported)
1616
`;
1717

1818
exports[` 4`] = `
1919
> 1 | query { oldFieldWithReason }
20-
| ^ This field is marked as deprecated in your GraphQL schema (reason: test)
20+
| ^^^^^^^^^^^^^^^^^^ This field is marked as deprecated in your GraphQL schema (reason: test)
2121
`;

0 commit comments

Comments
 (0)