Skip to content

Commit

Permalink
fix: adjust report location for avoid-typename-prefix rule (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri POSTOLOV committed Oct 27, 2021
1 parent 1bacedd commit c42cee5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-rivers-double.md
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix: adjust report location for `avoid-typename-prefix` rule
8 changes: 2 additions & 6 deletions packages/plugin/src/rules/alphabetize.ts
Expand Up @@ -167,8 +167,7 @@ const rule: GraphQLESLintRule<AlphabetizeConfig> = {
contains: {
enum: selectionsEnum,
},
description:
'Selections of operations (`query`, `mutation` and `subscription`) and `fragment`.',
description: 'Selections of operations (`query`, `mutation` and `subscription`) and `fragment`.',
},
variables: {
type: 'array',
Expand Down Expand Up @@ -213,10 +212,7 @@ const rule: GraphQLESLintRule<AlphabetizeConfig> = {
line: start.line,
column: start.column - (isVariableNode ? 2 : 1),
},
end: {
line: end.line,
column: end.column,
},
end,
},
messageId: ALPHABETIZE,
data: isVariableNode
Expand Down
19 changes: 15 additions & 4 deletions packages/plugin/src/rules/avoid-typename-prefix.ts
Expand Up @@ -49,19 +49,30 @@ const rule: GraphQLESLintRule = {
>
) {
const typeName = node.name.value;
const lowerTypeName = (typeName || '').toLowerCase();
const lowerTypeName = typeName.toLowerCase();

for (const field of node.fields) {
const fieldName = field.name.value || '';
const fieldName = field.name.value;

if (fieldName.toLowerCase().startsWith(lowerTypeName)) {
const { start } = field.loc;

if (fieldName && lowerTypeName && fieldName.toLowerCase().startsWith(lowerTypeName)) {
context.report({
node: field.name,
data: {
fieldName,
typeName,
},
messageId: AVOID_TYPENAME_PREFIX,
loc: {
start: {
line: start.line,
column: start.column - 1,
},
end: {
line: start.line,
column: start.column - 1 + lowerTypeName.length,
},
},
});
}
}
Expand Down
File renamed without changes.

0 comments on commit c42cee5

Please sign in to comment.