Skip to content

Commit

Permalink
fix error report for strict-id-in-types and naming-convention rule (
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri POSTOLOV committed Oct 31, 2021
1 parent 86b3709 commit b36a32c
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 69 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-files-build.md
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix error report for `strict-id-in-types` and `naming-convention` rule
14 changes: 10 additions & 4 deletions packages/plugin/src/rules/naming-convention.ts
@@ -1,6 +1,6 @@
import { Kind } from 'graphql';
import { GraphQLESLintRule } from '../types';
import { isQueryType } from '../utils';
import { getLocation, isQueryType } from '../utils';

const formats = {
camelCase: /^[a-z][^_]*$/g,
Expand Down Expand Up @@ -246,7 +246,7 @@ const rule: GraphQLESLintRule<NamingConventionRuleConfig> = {
});
if (result.ok === false) {
context.report({
node,
loc: getLocation(node.loc, node.value),
message: result.errorMessage,
data: {
prefix,
Expand Down Expand Up @@ -275,10 +275,16 @@ const rule: GraphQLESLintRule<NamingConventionRuleConfig> = {
return {
Name: node => {
if (node.value.startsWith('_') && options.leadingUnderscore === 'forbid') {
context.report({ node, message: 'Leading underscores are not allowed' });
context.report({
loc: getLocation(node.loc, node.value),
message: 'Leading underscores are not allowed',
});
}
if (node.value.endsWith('_') && options.trailingUnderscore === 'forbid') {
context.report({ node, message: 'Trailing underscores are not allowed' });
context.report({
loc: getLocation(node.loc, node.value),
message: 'Trailing underscores are not allowed',
});
}
},
ObjectTypeDefinition: node => {
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin/src/rules/strict-id-in-types.ts
@@ -1,6 +1,7 @@
import { Kind, ObjectTypeDefinitionNode } from 'graphql';
import { GraphQLESTreeNode } from '../estree-parser';
import { GraphQLESLintRule } from '../types';
import { getLocation } from '../utils';

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

return isValidIdName && isValidIdType;
});

const typeName = node.name.value;
// Usually, there should be only one unique identifier field per type.
// Some clients allow multiple fields to be used. If more people need this,
// we can extend this rule later.
if (validIds.length !== 1) {
context.report({
node,
message:
'{{nodeName}} must have exactly one non-nullable unique identifier. Accepted name(s): {{acceptedNamesString}} ; Accepted type(s): {{acceptedTypesString}}',
loc: getLocation(node.name.loc, typeName),
message: `{{ typeName }} must have exactly one non-nullable unique identifier. Accepted name(s): {{ acceptedNamesString }} ; Accepted type(s): {{ acceptedTypesString }}`,
data: {
nodeName: node.name.value,
typeName,
acceptedNamesString: options.acceptedIdNames.join(','),
acceptedTypesString: options.acceptedIdTypes.join(','),
},
Expand Down

0 comments on commit b36a32c

Please sign in to comment.