Skip to content

Commit

Permalink
fix error report for input-name rule
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitri committed Oct 30, 2021
1 parent f80c4ed commit 7acb1ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
17 changes: 9 additions & 8 deletions packages/plugin/src/rules/input-name.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GraphQLESLintRule } from '../types';
import { isMutationType, isQueryType } from '../utils';
import { getLocation, isMutationType, isQueryType } from '../utils';

type InputNameRuleConfig = {
checkInputType?: boolean;
Expand Down Expand Up @@ -89,10 +89,11 @@ const rule: GraphQLESLintRule<InputNameRuleConfig[]> = {

const listeners = {
'FieldDefinition > InputValueDefinition': node => {
if (node.name.value !== 'input' && shouldCheckType(node.parent.parent)) {
const name = node.name.value;
if (name !== 'input' && shouldCheckType(node.parent.parent)) {
context.report({
node: node.name,
message: `Input "${node.name.value}" should be called "input"`,
loc: getLocation(node.loc, name),
message: `Input "${name}" should be called "input"`,
});
}
},
Expand All @@ -111,14 +112,14 @@ const rule: GraphQLESLintRule<InputNameRuleConfig[]> = {
const inputValueNode = findInputType(node);
if (shouldCheckType(inputValueNode.parent.parent)) {
const mutationName = `${inputValueNode.parent.name.value}Input`;

const name = node.name.value;
if (
(options.caseSensitiveInputType && node.name.value !== mutationName) ||
node.name.value.toLowerCase() !== mutationName.toLowerCase()
name.toLowerCase() !== mutationName.toLowerCase()
) {
context.report({
node,
message: `InputType "${node.name.value}" name should be "${mutationName}"`,
loc: getLocation(node.loc, name),
message: `InputType "${name}" name should be "${mutationName}"`,
});
}
}
Expand Down
42 changes: 21 additions & 21 deletions packages/plugin/tests/__snapshots__/input-name.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,105 +2,105 @@

exports[` 1`] = `
> 1 | type Mutation { SetMessage(message: String): String }
| ^ Input "message" should be called "input"
| ^^^^^^^ Input "message" should be called "input"
`;

exports[` 2`] = `
> 1 | type Mutation { SetMessage(message: String): String }
| ^ InputType "String" name should be "SetMessageInput"
| ^^^^^^ InputType "String" name should be "SetMessageInput"
`;

exports[` 3`] = `
> 1 | type Mutation { SetMessage(input: String): String }
| ^ InputType "String" name should be "SetMessageInput"
| ^^^^^^ InputType "String" name should be "SetMessageInput"
`;

exports[` 4`] = `
> 1 | type Mutation { SetMessage(hello: SetMessageInput): String }
| ^ Input "hello" should be called "input"
| ^^^^^ Input "hello" should be called "input"
`;

exports[` 5`] = `
> 1 | type Mutation { userCreate(record: CreateOneUserInput!): CreateOneUserPayload }
| ^ Input "record" should be called "input"
| ^^^^^^ Input "record" should be called "input"
`;

exports[` 6`] = `
> 1 | type Mutation { userCreate(record: CreateOneUserInput!): CreateOneUserPayload }
| ^ InputType "CreateOneUserInput" name should be "userCreateInput"
| ^^^^^^^^^^^^^^^^^^ InputType "CreateOneUserInput" name should be "userCreateInput"
`;

exports[` 7`] = `
> 1 | type Mutation { userCreate(record: [CreateOneUserInput]!): CreateOneUserPayload }
| ^ Input "record" should be called "input"
| ^^^^^^ Input "record" should be called "input"
`;

exports[` 8`] = `
> 1 | type Mutation { userCreate(record: [CreateOneUserInput]!): CreateOneUserPayload }
| ^ InputType "CreateOneUserInput" name should be "userCreateInput"
| ^^^^^^^^^^^^^^^^^^ InputType "CreateOneUserInput" name should be "userCreateInput"
`;

exports[` 9`] = `
> 1 | type Mutation { userCreate(record: [CreateOneUserInput!]!): CreateOneUserPayload }
| ^ Input "record" should be called "input"
| ^^^^^^ Input "record" should be called "input"
`;

exports[` 10`] = `
> 1 | type Mutation { userCreate(record: [CreateOneUserInput!]!): CreateOneUserPayload }
| ^ InputType "CreateOneUserInput" name should be "userCreateInput"
| ^^^^^^^^^^^^^^^^^^ InputType "CreateOneUserInput" name should be "userCreateInput"
`;

exports[` 11`] = `
> 1 | type Mutation { userCreate(record: [CreateOneUserInput!]): CreateOneUserPayload }
| ^ Input "record" should be called "input"
| ^^^^^^ Input "record" should be called "input"
`;

exports[` 12`] = `
> 1 | type Mutation { userCreate(record: [CreateOneUserInput!]): CreateOneUserPayload }
| ^ InputType "CreateOneUserInput" name should be "userCreateInput"
| ^^^^^^^^^^^^^^^^^^ InputType "CreateOneUserInput" name should be "userCreateInput"
`;

exports[` 13`] = `
> 1 | type Mutation { userCreate(record: String, test: String): String }
| ^ Input "record" should be called "input"
| ^^^^^^ Input "record" should be called "input"
`;

exports[` 14`] = `
> 1 | type Mutation { userCreate(record: String, test: String): String }
| ^ InputType "String" name should be "userCreateInput"
| ^^^^^^ InputType "String" name should be "userCreateInput"
`;

exports[` 15`] = `
> 1 | type Mutation { userCreate(record: String, test: String): String }
| ^ Input "test" should be called "input"
| ^^^^ Input "test" should be called "input"
`;

exports[` 16`] = `
> 1 | type Mutation { userCreate(record: String, test: String): String }
| ^ InputType "String" name should be "userCreateInput"
| ^^^^^^ InputType "String" name should be "userCreateInput"
`;

exports[` 17`] = `
> 1 | type Mutation { userCreate(record: String, test: String): String }
| ^ Input "record" should be called "input"
| ^^^^^^ Input "record" should be called "input"
`;

exports[` 18`] = `
> 1 | type Mutation { userCreate(record: String, test: String): String }
| ^ Input "test" should be called "input"
| ^^^^ Input "test" should be called "input"
`;

exports[` 19`] = `
> 1 | type Mutation { userCreate(input: String): String }
| ^ InputType "String" name should be "userCreateInput"
| ^^^^^^ InputType "String" name should be "userCreateInput"
`;

exports[` 20`] = `
> 1 | type Mutation { userCreate(input: UserCreateInput): String }
| ^ InputType "UserCreateInput" name should be "userCreateInput"
| ^^^^^^^^^^^^^^^ InputType "UserCreateInput" name should be "userCreateInput"
`;

exports[` 21`] = `
> 1 | type Query { getUser(input: GetUserInput): String }
| ^ InputType "GetUserInput" name should be "getUserInput"
| ^^^^^^^^^^^^ InputType "GetUserInput" name should be "getUserInput"
`;

0 comments on commit 7acb1ee

Please sign in to comment.