Skip to content

Commit 7aa8157

Browse files
author
Dimitri POSTOLOV
authored
fix error report for input-name rule (#738)
1 parent 7dacfe5 commit 7aa8157

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

.changeset/strong-boxes-kiss.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 `input-name` rule

packages/plugin/src/rules/input-name.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GraphQLESLintRule } from '../types';
2-
import { isMutationType, isQueryType } from '../utils';
2+
import { getLocation, isMutationType, isQueryType } from '../utils';
33

44
type InputNameRuleConfig = {
55
checkInputType?: boolean;
@@ -89,10 +89,11 @@ const rule: GraphQLESLintRule<InputNameRuleConfig[]> = {
8989

9090
const listeners = {
9191
'FieldDefinition > InputValueDefinition': node => {
92-
if (node.name.value !== 'input' && shouldCheckType(node.parent.parent)) {
92+
const name = node.name.value;
93+
if (name !== 'input' && shouldCheckType(node.parent.parent)) {
9394
context.report({
94-
node: node.name,
95-
message: `Input "${node.name.value}" should be called "input"`,
95+
loc: getLocation(node.loc, name),
96+
message: `Input "${name}" should be called "input"`,
9697
});
9798
}
9899
},
@@ -111,14 +112,14 @@ const rule: GraphQLESLintRule<InputNameRuleConfig[]> = {
111112
const inputValueNode = findInputType(node);
112113
if (shouldCheckType(inputValueNode.parent.parent)) {
113114
const mutationName = `${inputValueNode.parent.name.value}Input`;
114-
115+
const name = node.name.value;
115116
if (
116117
(options.caseSensitiveInputType && node.name.value !== mutationName) ||
117-
node.name.value.toLowerCase() !== mutationName.toLowerCase()
118+
name.toLowerCase() !== mutationName.toLowerCase()
118119
) {
119120
context.report({
120-
node,
121-
message: `InputType "${node.name.value}" name should be "${mutationName}"`,
121+
loc: getLocation(node.loc, name),
122+
message: `InputType "${name}" name should be "${mutationName}"`,
122123
});
123124
}
124125
}

packages/plugin/tests/__snapshots__/input-name.spec.ts.snap

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

33
exports[` 1`] = `
44
> 1 | type Mutation { SetMessage(message: String): String }
5-
| ^ Input "message" should be called "input"
5+
| ^^^^^^^ Input "message" should be called "input"
66
`;
77

88
exports[` 2`] = `
99
> 1 | type Mutation { SetMessage(message: String): String }
10-
| ^ InputType "String" name should be "SetMessageInput"
10+
| ^^^^^^ InputType "String" name should be "SetMessageInput"
1111
`;
1212

1313
exports[` 3`] = `
1414
> 1 | type Mutation { SetMessage(input: String): String }
15-
| ^ InputType "String" name should be "SetMessageInput"
15+
| ^^^^^^ InputType "String" name should be "SetMessageInput"
1616
`;
1717

1818
exports[` 4`] = `
1919
> 1 | type Mutation { SetMessage(hello: SetMessageInput): String }
20-
| ^ Input "hello" should be called "input"
20+
| ^^^^^ Input "hello" should be called "input"
2121
`;
2222

2323
exports[` 5`] = `
2424
> 1 | type Mutation { userCreate(record: CreateOneUserInput!): CreateOneUserPayload }
25-
| ^ Input "record" should be called "input"
25+
| ^^^^^^ Input "record" should be called "input"
2626
`;
2727

2828
exports[` 6`] = `
2929
> 1 | type Mutation { userCreate(record: CreateOneUserInput!): CreateOneUserPayload }
30-
| ^ InputType "CreateOneUserInput" name should be "userCreateInput"
30+
| ^^^^^^^^^^^^^^^^^^ InputType "CreateOneUserInput" name should be "userCreateInput"
3131
`;
3232

3333
exports[` 7`] = `
3434
> 1 | type Mutation { userCreate(record: [CreateOneUserInput]!): CreateOneUserPayload }
35-
| ^ Input "record" should be called "input"
35+
| ^^^^^^ Input "record" should be called "input"
3636
`;
3737

3838
exports[` 8`] = `
3939
> 1 | type Mutation { userCreate(record: [CreateOneUserInput]!): CreateOneUserPayload }
40-
| ^ InputType "CreateOneUserInput" name should be "userCreateInput"
40+
| ^^^^^^^^^^^^^^^^^^ InputType "CreateOneUserInput" name should be "userCreateInput"
4141
`;
4242

4343
exports[` 9`] = `
4444
> 1 | type Mutation { userCreate(record: [CreateOneUserInput!]!): CreateOneUserPayload }
45-
| ^ Input "record" should be called "input"
45+
| ^^^^^^ Input "record" should be called "input"
4646
`;
4747

4848
exports[` 10`] = `
4949
> 1 | type Mutation { userCreate(record: [CreateOneUserInput!]!): CreateOneUserPayload }
50-
| ^ InputType "CreateOneUserInput" name should be "userCreateInput"
50+
| ^^^^^^^^^^^^^^^^^^ InputType "CreateOneUserInput" name should be "userCreateInput"
5151
`;
5252

5353
exports[` 11`] = `
5454
> 1 | type Mutation { userCreate(record: [CreateOneUserInput!]): CreateOneUserPayload }
55-
| ^ Input "record" should be called "input"
55+
| ^^^^^^ Input "record" should be called "input"
5656
`;
5757

5858
exports[` 12`] = `
5959
> 1 | type Mutation { userCreate(record: [CreateOneUserInput!]): CreateOneUserPayload }
60-
| ^ InputType "CreateOneUserInput" name should be "userCreateInput"
60+
| ^^^^^^^^^^^^^^^^^^ InputType "CreateOneUserInput" name should be "userCreateInput"
6161
`;
6262

6363
exports[` 13`] = `
6464
> 1 | type Mutation { userCreate(record: String, test: String): String }
65-
| ^ Input "record" should be called "input"
65+
| ^^^^^^ Input "record" should be called "input"
6666
`;
6767

6868
exports[` 14`] = `
6969
> 1 | type Mutation { userCreate(record: String, test: String): String }
70-
| ^ InputType "String" name should be "userCreateInput"
70+
| ^^^^^^ InputType "String" name should be "userCreateInput"
7171
`;
7272

7373
exports[` 15`] = `
7474
> 1 | type Mutation { userCreate(record: String, test: String): String }
75-
| ^ Input "test" should be called "input"
75+
| ^^^^ Input "test" should be called "input"
7676
`;
7777

7878
exports[` 16`] = `
7979
> 1 | type Mutation { userCreate(record: String, test: String): String }
80-
| ^ InputType "String" name should be "userCreateInput"
80+
| ^^^^^^ InputType "String" name should be "userCreateInput"
8181
`;
8282

8383
exports[` 17`] = `
8484
> 1 | type Mutation { userCreate(record: String, test: String): String }
85-
| ^ Input "record" should be called "input"
85+
| ^^^^^^ Input "record" should be called "input"
8686
`;
8787

8888
exports[` 18`] = `
8989
> 1 | type Mutation { userCreate(record: String, test: String): String }
90-
| ^ Input "test" should be called "input"
90+
| ^^^^ Input "test" should be called "input"
9191
`;
9292

9393
exports[` 19`] = `
9494
> 1 | type Mutation { userCreate(input: String): String }
95-
| ^ InputType "String" name should be "userCreateInput"
95+
| ^^^^^^ InputType "String" name should be "userCreateInput"
9696
`;
9797

9898
exports[` 20`] = `
9999
> 1 | type Mutation { userCreate(input: UserCreateInput): String }
100-
| ^ InputType "UserCreateInput" name should be "userCreateInput"
100+
| ^^^^^^^^^^^^^^^ InputType "UserCreateInput" name should be "userCreateInput"
101101
`;
102102

103103
exports[` 21`] = `
104104
> 1 | type Query { getUser(input: GetUserInput): String }
105-
| ^ InputType "GetUserInput" name should be "getUserInput"
105+
| ^^^^^^^^^^^^ InputType "GetUserInput" name should be "getUserInput"
106106
`;

0 commit comments

Comments
 (0)