Skip to content

Commit 98b6bcb

Browse files
author
Dimitri POSTOLOV
authored
fix: adjust report location for no-operation-name-suffix rule (#721)
1 parent eb4a851 commit 98b6bcb

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

.changeset/heavy-chicken-dream.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 `no-operation-name-suffix` rule

packages/plugin/src/rules/no-operation-name-suffix.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,23 @@ const rule: GraphQLESLintRule = {
4242
'OperationDefinition, FragmentDefinition'(
4343
node: GraphQLESTreeNode<OperationDefinitionNode | FragmentDefinitionNode>
4444
) {
45-
if (node && node.name && node.name.value !== '') {
46-
const invalidSuffix = (node.type === 'OperationDefinition' ? node.operation : 'fragment').toLowerCase();
45+
const name = node.name?.value || '';
46+
if (name.length > 0) {
47+
const invalidSuffix = 'operation' in node ? node.operation : 'fragment';
4748

48-
if (node.name.value.toLowerCase().endsWith(invalidSuffix)) {
49+
if (name.toLowerCase().endsWith(invalidSuffix)) {
50+
const { start, end } = node.name.loc;
4951
context.report({
50-
node: node.name,
52+
loc: {
53+
start: {
54+
column: start.column - 1 + name.length - invalidSuffix.length,
55+
line: start.line,
56+
},
57+
end: {
58+
column: end.column - 1 + name.length,
59+
line: end.line,
60+
},
61+
},
5162
data: {
5263
invalidSuffix,
5364
},

0 commit comments

Comments
 (0)