Skip to content

Commit b36a32c

Browse files
author
Dimitri POSTOLOV
authored
fix error report for strict-id-in-types and naming-convention rule (#744)
1 parent 86b3709 commit b36a32c

File tree

5 files changed

+80
-69
lines changed

5 files changed

+80
-69
lines changed

.changeset/silent-files-build.md

+5
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 `strict-id-in-types` and `naming-convention` rule

packages/plugin/src/rules/naming-convention.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Kind } from 'graphql';
22
import { GraphQLESLintRule } from '../types';
3-
import { isQueryType } from '../utils';
3+
import { getLocation, isQueryType } from '../utils';
44

55
const formats = {
66
camelCase: /^[a-z][^_]*$/g,
@@ -246,7 +246,7 @@ const rule: GraphQLESLintRule<NamingConventionRuleConfig> = {
246246
});
247247
if (result.ok === false) {
248248
context.report({
249-
node,
249+
loc: getLocation(node.loc, node.value),
250250
message: result.errorMessage,
251251
data: {
252252
prefix,
@@ -275,10 +275,16 @@ const rule: GraphQLESLintRule<NamingConventionRuleConfig> = {
275275
return {
276276
Name: node => {
277277
if (node.value.startsWith('_') && options.leadingUnderscore === 'forbid') {
278-
context.report({ node, message: 'Leading underscores are not allowed' });
278+
context.report({
279+
loc: getLocation(node.loc, node.value),
280+
message: 'Leading underscores are not allowed',
281+
});
279282
}
280283
if (node.value.endsWith('_') && options.trailingUnderscore === 'forbid') {
281-
context.report({ node, message: 'Trailing underscores are not allowed' });
284+
context.report({
285+
loc: getLocation(node.loc, node.value),
286+
message: 'Trailing underscores are not allowed',
287+
});
282288
}
283289
},
284290
ObjectTypeDefinition: node => {

packages/plugin/src/rules/strict-id-in-types.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Kind, ObjectTypeDefinitionNode } from 'graphql';
22
import { GraphQLESTreeNode } from '../estree-parser';
33
import { GraphQLESLintRule } from '../types';
4+
import { getLocation } from '../utils';
45

56
export interface ExceptionRule {
67
types?: string[];
@@ -171,17 +172,16 @@ const rule: GraphQLESLintRule<StrictIdInTypesRuleConfig> = {
171172

172173
return isValidIdName && isValidIdType;
173174
});
174-
175+
const typeName = node.name.value;
175176
// Usually, there should be only one unique identifier field per type.
176177
// Some clients allow multiple fields to be used. If more people need this,
177178
// we can extend this rule later.
178179
if (validIds.length !== 1) {
179180
context.report({
180-
node,
181-
message:
182-
'{{nodeName}} must have exactly one non-nullable unique identifier. Accepted name(s): {{acceptedNamesString}} ; Accepted type(s): {{acceptedTypesString}}',
181+
loc: getLocation(node.name.loc, typeName),
182+
message: `{{ typeName }} must have exactly one non-nullable unique identifier. Accepted name(s): {{ acceptedNamesString }} ; Accepted type(s): {{ acceptedTypesString }}`,
183183
data: {
184-
nodeName: node.name.value,
184+
typeName,
185185
acceptedNamesString: options.acceptedIdNames.join(','),
186186
acceptedTypesString: options.acceptedIdTypes.join(','),
187187
},

0 commit comments

Comments
 (0)