Skip to content

Commit

Permalink
fix: adjust report location for no-operation-name-suffix rule (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri POSTOLOV committed Oct 27, 2021
1 parent eb4a851 commit 98b6bcb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-chicken-dream.md
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix: adjust report location for `no-operation-name-suffix` rule
19 changes: 15 additions & 4 deletions packages/plugin/src/rules/no-operation-name-suffix.ts
Expand Up @@ -42,12 +42,23 @@ const rule: GraphQLESLintRule = {
'OperationDefinition, FragmentDefinition'(
node: GraphQLESTreeNode<OperationDefinitionNode | FragmentDefinitionNode>
) {
if (node && node.name && node.name.value !== '') {
const invalidSuffix = (node.type === 'OperationDefinition' ? node.operation : 'fragment').toLowerCase();
const name = node.name?.value || '';
if (name.length > 0) {
const invalidSuffix = 'operation' in node ? node.operation : 'fragment';

if (node.name.value.toLowerCase().endsWith(invalidSuffix)) {
if (name.toLowerCase().endsWith(invalidSuffix)) {
const { start, end } = node.name.loc;
context.report({
node: node.name,
loc: {
start: {
column: start.column - 1 + name.length - invalidSuffix.length,
line: start.line,
},
end: {
column: end.column - 1 + name.length,
line: end.line,
},
},
data: {
invalidSuffix,
},
Expand Down

0 comments on commit 98b6bcb

Please sign in to comment.