Skip to content

Commit c42cee5

Browse files
author
Dimitri POSTOLOV
authored
fix: adjust report location for avoid-typename-prefix rule (#718)
1 parent 1bacedd commit c42cee5

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

.changeset/purple-rivers-double.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: adjust report location for `avoid-typename-prefix` rule

packages/plugin/src/rules/alphabetize.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ const rule: GraphQLESLintRule<AlphabetizeConfig> = {
167167
contains: {
168168
enum: selectionsEnum,
169169
},
170-
description:
171-
'Selections of operations (`query`, `mutation` and `subscription`) and `fragment`.',
170+
description: 'Selections of operations (`query`, `mutation` and `subscription`) and `fragment`.',
172171
},
173172
variables: {
174173
type: 'array',
@@ -213,10 +212,7 @@ const rule: GraphQLESLintRule<AlphabetizeConfig> = {
213212
line: start.line,
214213
column: start.column - (isVariableNode ? 2 : 1),
215214
},
216-
end: {
217-
line: end.line,
218-
column: end.column,
219-
},
215+
end,
220216
},
221217
messageId: ALPHABETIZE,
222218
data: isVariableNode

packages/plugin/src/rules/avoid-typename-prefix.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,30 @@ const rule: GraphQLESLintRule = {
4949
>
5050
) {
5151
const typeName = node.name.value;
52-
const lowerTypeName = (typeName || '').toLowerCase();
52+
const lowerTypeName = typeName.toLowerCase();
5353

5454
for (const field of node.fields) {
55-
const fieldName = field.name.value || '';
55+
const fieldName = field.name.value;
56+
57+
if (fieldName.toLowerCase().startsWith(lowerTypeName)) {
58+
const { start } = field.loc;
5659

57-
if (fieldName && lowerTypeName && fieldName.toLowerCase().startsWith(lowerTypeName)) {
5860
context.report({
59-
node: field.name,
6061
data: {
6162
fieldName,
6263
typeName,
6364
},
6465
messageId: AVOID_TYPENAME_PREFIX,
66+
loc: {
67+
start: {
68+
line: start.line,
69+
column: start.column - 1,
70+
},
71+
end: {
72+
line: start.line,
73+
column: start.column - 1 + lowerTypeName.length,
74+
},
75+
},
6576
});
6677
}
6778
}
File renamed without changes.

0 commit comments

Comments
 (0)