From 4e94259fb877622117ebcdd79c742f78ae86614e Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Sun, 26 Mar 2023 15:42:32 +0200 Subject: [PATCH] improve error messages for some rules (#1534) * description-style.ts * input-name.ts * no-case-insensitive-enum-values-duplicates.ts * require-deprecation-date.ts * no-scalar-result-type-on-mutation.ts * strict-id-in-types.ts * require-type-pattern-with-oneof.ts * require-nullable-fields-with-oneof.ts * no-hashtag-description.ts * no-hashtag-description.ts * alphabetize.ts * alphabetize.ts * fix type issues * update snapshots * set chageset to minor * improve enum/input value name --- .changeset/curly-eagles-attack.md | 5 + .eslintrc.cjs | 2 +- packages/plugin/src/rules/alphabetize.ts | 8 +- .../plugin/src/rules/description-style.ts | 5 +- packages/plugin/src/rules/input-name.ts | 7 +- ...case-insensitive-enum-values-duplicates.ts | 5 +- .../src/rules/no-hashtag-description.ts | 24 +++- .../no-scalar-result-type-on-mutation.ts | 11 +- .../src/rules/require-deprecation-date.ts | 22 +++- .../require-nullable-fields-with-oneof.ts | 5 +- .../rules/require-type-pattern-with-oneof.ts | 6 +- .../plugin/src/rules/strict-id-in-types.ts | 7 +- packages/plugin/src/utils.ts | 52 +++++---- .../tests/__snapshots__/alphabetize.spec.md | 108 +++++++++--------- .../__snapshots__/description-style.spec.md | 12 +- .../tests/__snapshots__/examples.spec.md | 8 +- .../tests/__snapshots__/input-name.spec.md | 20 ++-- ...insensitive-enum-values-duplicates.spec.md | 4 +- .../no-hashtag-description.spec.md | 15 ++- .../no-scalar-result-type-on-mutation.spec.md | 12 +- .../require-deprecation-date.spec.md | 10 +- .../require-deprecation-reason.spec.md | 4 +- .../__snapshots__/require-description.spec.md | 4 +- ...require-nullable-fields-with-oneof.spec.md | 6 +- .../require-type-pattern-with-oneof.spec.md | 4 +- .../__snapshots__/strict-id-in-types.spec.md | 36 ++++-- packages/plugin/tests/alphabetize.spec.ts | 108 +++++++++--------- packages/plugin/tests/input-name.spec.ts | 9 +- ...insensitive-enum-values-duplicates.spec.ts | 8 +- .../tests/no-hashtag-description.spec.ts | 12 +- .../no-scalar-result-type-on-mutation.spec.ts | 13 +-- .../tests/require-deprecation-date.spec.ts | 10 +- ...require-nullable-fields-with-oneof.spec.ts | 7 +- .../require-type-pattern-with-oneof.spec.ts | 4 +- 34 files changed, 321 insertions(+), 252 deletions(-) create mode 100644 .changeset/curly-eagles-attack.md diff --git a/.changeset/curly-eagles-attack.md b/.changeset/curly-eagles-attack.md new file mode 100644 index 00000000000..6ca3e8c0568 --- /dev/null +++ b/.changeset/curly-eagles-attack.md @@ -0,0 +1,5 @@ +--- +'@graphql-eslint/eslint-plugin': minor +--- + +improve error messages for some rules diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 4caeedc6251..7dab5d81a7f 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -9,7 +9,7 @@ module.exports = { rules: { 'unicorn/prefer-array-some': 'error', 'unicorn/better-regex': 'error', - 'prefer-destructuring': ['error', { object: true }], + 'prefer-destructuring': ['error', { VariableDeclarator: { object: true } }], quotes: ['error', 'single', { avoidEscape: true }], // Matches Prettier, but also replaces backticks }, overrides: [ diff --git a/packages/plugin/src/rules/alphabetize.ts b/packages/plugin/src/rules/alphabetize.ts index 3fa6e90c783..f8bfbe03e87 100644 --- a/packages/plugin/src/rules/alphabetize.ts +++ b/packages/plugin/src/rules/alphabetize.ts @@ -23,7 +23,7 @@ import lowerCase from 'lodash.lowercase'; import { GraphQLESTreeNode } from '../estree-converter/index.js'; import { GraphQLESLintRuleListener } from '../testkit.js'; import { GraphQLESLintRule } from '../types.js'; -import { ARRAY_DEFAULT_OPTIONS, truthy } from '../utils.js'; +import { ARRAY_DEFAULT_OPTIONS, displayNodeName, truthy } from '../utils.js'; const RULE_ID = 'alphabetize'; @@ -218,7 +218,7 @@ export const rule: GraphQLESLintRule = { }, }, messages: { - [RULE_ID]: '`{{ currName }}` should be before {{ prevName }}.', + [RULE_ID]: '{{ currNode }} should be before {{ prevNode }}', }, schema, }, @@ -320,8 +320,8 @@ export const rule: GraphQLESLintRule = { node: ('alias' in currNode && currNode.alias) || currNode.name, messageId: RULE_ID, data: { - currName, - prevName: prevName ? `\`${prevName}\`` : lowerCase(prevNode.kind), + currNode: displayNodeName(currNode), + prevNode: prevName ? displayNodeName(prevNode) : lowerCase(prevNode.kind), }, *fix(fixer) { const prevRange = getRangeWithComments(prevNode); diff --git a/packages/plugin/src/rules/description-style.ts b/packages/plugin/src/rules/description-style.ts index 4795105e487..93138fc42e2 100644 --- a/packages/plugin/src/rules/description-style.ts +++ b/packages/plugin/src/rules/description-style.ts @@ -2,6 +2,7 @@ import { StringValueNode } from 'graphql'; import { FromSchema } from 'json-schema-to-ts'; import { GraphQLESTreeNode } from '../estree-converter/index.js'; import { GraphQLESLintRule } from '../types.js'; +import { getNodeName } from '../utils.js'; const schema = { type: 'array', @@ -64,7 +65,9 @@ export const rule: GraphQLESLintRule = { ) { context.report({ loc: isBlock ? node.loc : node.loc.start, - message: `Unexpected ${isBlock ? 'inline' : 'block'} description.`, + message: `Unexpected ${isBlock ? 'inline' : 'block'} description for ${getNodeName( + (node as any).parent, + )}`, suggest: [ { desc: `Change to ${isBlock ? 'block' : 'inline'} style description`, diff --git a/packages/plugin/src/rules/input-name.ts b/packages/plugin/src/rules/input-name.ts index 401f719bf4b..4942215c34c 100644 --- a/packages/plugin/src/rules/input-name.ts +++ b/packages/plugin/src/rules/input-name.ts @@ -114,13 +114,12 @@ export const rule: GraphQLESLintRule = { 'FieldDefinition > InputValueDefinition[name.value!=input] > Name'( node: GraphQLESTreeNode, ) { - if ( - shouldCheckType((node.parent.parent as GraphQLESTreeNode).parent) - ) { + const fieldDef = node.parent.parent as GraphQLESTreeNode; + if (shouldCheckType(fieldDef.parent)) { const inputName = node.value; context.report({ node, - message: `Input \`${inputName}\` should be called \`input\`.`, + message: `Input "${inputName}" should be named "input" for "${fieldDef.parent.name.value}.${fieldDef.name.value}"`, suggest: [ { desc: 'Rename to `input`', diff --git a/packages/plugin/src/rules/no-case-insensitive-enum-values-duplicates.ts b/packages/plugin/src/rules/no-case-insensitive-enum-values-duplicates.ts index f40522475ae..334cccde027 100644 --- a/packages/plugin/src/rules/no-case-insensitive-enum-values-duplicates.ts +++ b/packages/plugin/src/rules/no-case-insensitive-enum-values-duplicates.ts @@ -1,6 +1,7 @@ import { EnumTypeDefinitionNode, EnumTypeExtensionNode, Kind } from 'graphql'; import { GraphQLESTreeNode } from '../estree-converter/index.js'; import { GraphQLESLintRule } from '../types.js'; +import { getNodeName } from '../utils.js'; export const rule: GraphQLESLintRule = { meta: { @@ -49,7 +50,9 @@ export const rule: GraphQLESLintRule = { const enumName = duplicate.name.value; context.report({ node: duplicate.name, - message: `Case-insensitive enum values duplicates are not allowed! Found: \`${enumName}\`.`, + message: `Unexpected case-insensitive enum values duplicates for ${getNodeName( + duplicate, + )}`, suggest: [ { desc: `Remove \`${enumName}\` enum value`, diff --git a/packages/plugin/src/rules/no-hashtag-description.ts b/packages/plugin/src/rules/no-hashtag-description.ts index 5e2ace6dd47..0ad642f7bec 100644 --- a/packages/plugin/src/rules/no-hashtag-description.ts +++ b/packages/plugin/src/rules/no-hashtag-description.ts @@ -1,8 +1,9 @@ import { DocumentNode, Token, TokenKind } from 'graphql'; import { GraphQLESTreeNode } from '../estree-converter/index.js'; import { GraphQLESLintRule } from '../types.js'; +import { getNodeName } from '../utils.js'; -const HASHTAG_COMMENT = 'HASHTAG_COMMENT'; +export const RULE_ID = 'HASHTAG_COMMENT'; export const rule: GraphQLESLintRule = { meta: { @@ -10,8 +11,8 @@ export const rule: GraphQLESLintRule = { hasSuggestions: true, schema: [], messages: { - [HASHTAG_COMMENT]: - 'Using hashtag `#` for adding GraphQL descriptions is not allowed. Prefer using `"""` for multiline, or `"` for a single line description.', + [RULE_ID]: + 'Unexpected GraphQL descriptions as hashtag `#` for {{ nodeName }}.\nPrefer using `"""` for multiline, or `"` for a single line description.', }, docs: { description: @@ -69,15 +70,28 @@ export const rule: GraphQLESLintRule = { // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- TODO: remove `!` when drop support of graphql@15 const isEslintComment = value!.trimStart().startsWith('eslint'); const linesAfter = next.line - line; - if ( !isEslintComment && line !== prev.line && next.kind === TokenKind.NAME && linesAfter < 2 ) { + const sourceCode = context.getSourceCode(); + const { tokens } = sourceCode.ast; + + const t = tokens.find( + token => + token.loc.start.line === next.line && token.loc.start.column === next.column - 1, + )!; + const nextNode = sourceCode.getNodeByRangeIndex(t.range[1] + 1)!; + context.report({ - messageId: HASHTAG_COMMENT, + messageId: RULE_ID, + data: { + nodeName: getNodeName( + 'name' in nextNode ? (nextNode as any) : (nextNode as any).parent, + ), + }, loc: { line, column: column - 1, diff --git a/packages/plugin/src/rules/no-scalar-result-type-on-mutation.ts b/packages/plugin/src/rules/no-scalar-result-type-on-mutation.ts index 665ec8f954f..4f0b5c699e1 100644 --- a/packages/plugin/src/rules/no-scalar-result-type-on-mutation.ts +++ b/packages/plugin/src/rules/no-scalar-result-type-on-mutation.ts @@ -1,7 +1,7 @@ -import { isScalarType, NameNode } from 'graphql'; +import { isScalarType, Kind, NameNode } from 'graphql'; import { GraphQLESTreeNode } from '../estree-converter/index.js'; import { GraphQLESLintRule } from '../types.js'; -import { requireGraphQLSchemaFromContext } from '../utils.js'; +import { getNodeName, requireGraphQLSchemaFromContext } from '../utils.js'; const RULE_ID = 'no-scalar-result-type-on-mutation'; @@ -52,9 +52,14 @@ export const rule: GraphQLESLintRule = { const typeName = node.value; const graphQLType = schema.getType(typeName); if (isScalarType(graphQLType)) { + let fieldDef = node.parent as any; + while (fieldDef.kind !== Kind.FIELD_DEFINITION) { + fieldDef = fieldDef.parent; + } + context.report({ node, - message: `Unexpected scalar result type \`${typeName}\`.`, + message: `Unexpected scalar result type \`${typeName}\` for ${getNodeName(fieldDef)}`, suggest: [ { desc: `Remove \`${typeName}\``, diff --git a/packages/plugin/src/rules/require-deprecation-date.ts b/packages/plugin/src/rules/require-deprecation-date.ts index 6b92122bc10..2f1a49b3e8f 100644 --- a/packages/plugin/src/rules/require-deprecation-date.ts +++ b/packages/plugin/src/rules/require-deprecation-date.ts @@ -2,6 +2,7 @@ import { DirectiveNode } from 'graphql'; import { FromSchema } from 'json-schema-to-ts'; import { GraphQLESTreeNode, valueFromNode } from '../estree-converter/index.js'; import { GraphQLESLintRule } from '../types.js'; +import { getNodeName } from '../utils.js'; // eslint-disable-next-line unicorn/better-regex const DATE_REGEX = /^\d{2}\/\d{2}\/\d{4}$/; @@ -68,10 +69,11 @@ export const rule: GraphQLESLintRule = { ], }, messages: { - [MESSAGE_REQUIRE_DATE]: 'Directive "@deprecated" must have a deletion date', - [MESSAGE_INVALID_FORMAT]: 'Deletion date must be in format "DD/MM/YYYY"', - [MESSAGE_INVALID_DATE]: 'Invalid "{{ deletionDate }}" deletion date', - [MESSAGE_CAN_BE_REMOVED]: '"{{ nodeName }}" сan be removed', + [MESSAGE_REQUIRE_DATE]: + 'Directive "@deprecated" must have a deletion date for {{ nodeName }}', + [MESSAGE_INVALID_FORMAT]: 'Deletion date must be in format "DD/MM/YYYY" for {{ nodeName }}', + [MESSAGE_INVALID_DATE]: 'Invalid "{{ deletionDate }}" deletion date for {{ nodeName }}', + [MESSAGE_CAN_BE_REMOVED]: '{{ nodeName }} сan be removed', }, schema, }, @@ -85,6 +87,9 @@ export const rule: GraphQLESLintRule = { context.report({ node: node.name, messageId: MESSAGE_REQUIRE_DATE, + data: { + nodeName: getNodeName(node.parent), + }, }); return; } @@ -92,7 +97,11 @@ export const rule: GraphQLESLintRule = { const isValidDate = DATE_REGEX.test(deletionDate); if (!isValidDate) { - context.report({ node: deletionDateNode.value, messageId: MESSAGE_INVALID_FORMAT }); + context.report({ + node: deletionDateNode.value, + messageId: MESSAGE_INVALID_FORMAT, + data: { nodeName: getNodeName(node.parent) }, + }); return; } let [day, month, year] = deletionDate.split('/'); @@ -106,6 +115,7 @@ export const rule: GraphQLESLintRule = { messageId: MESSAGE_INVALID_DATE, data: { deletionDate, + nodeName: getNodeName(node.parent), }, }); return; @@ -119,7 +129,7 @@ export const rule: GraphQLESLintRule = { context.report({ node: parent.name, messageId: MESSAGE_CAN_BE_REMOVED, - data: { nodeName }, + data: { nodeName: getNodeName(parent) }, suggest: [ { desc: `Remove \`${nodeName}\``, diff --git a/packages/plugin/src/rules/require-nullable-fields-with-oneof.ts b/packages/plugin/src/rules/require-nullable-fields-with-oneof.ts index 4b0b0d04b3e..3c578f1bcf6 100644 --- a/packages/plugin/src/rules/require-nullable-fields-with-oneof.ts +++ b/packages/plugin/src/rules/require-nullable-fields-with-oneof.ts @@ -1,6 +1,7 @@ import { DirectiveNode, Kind } from 'graphql'; import { GraphQLESTreeNode } from '../estree-converter/index.js'; import { GraphQLESLintRule } from '../types.js'; +import { getNodeName } from '../utils.js'; const RULE_ID = 'require-nullable-fields-with-oneof'; @@ -33,7 +34,7 @@ export const rule: GraphQLESLintRule = { ], }, messages: { - [RULE_ID]: 'Field `{{fieldName}}` must be nullable.', + [RULE_ID]: '{{ nodeName }} must be nullable when "@oneOf" is in use', }, schema: [], }, @@ -53,7 +54,7 @@ export const rule: GraphQLESLintRule = { context.report({ node: field.name, messageId: RULE_ID, - data: { fieldName: field.name.value }, + data: { nodeName: getNodeName(field) }, }); } } diff --git a/packages/plugin/src/rules/require-type-pattern-with-oneof.ts b/packages/plugin/src/rules/require-type-pattern-with-oneof.ts index e2994cabdec..4cca46dabb4 100644 --- a/packages/plugin/src/rules/require-type-pattern-with-oneof.ts +++ b/packages/plugin/src/rules/require-type-pattern-with-oneof.ts @@ -1,6 +1,7 @@ import { ObjectTypeDefinitionNode } from 'graphql'; import { GraphQLESTreeNode } from '../estree-converter/index.js'; import { GraphQLESLintRule } from '../types.js'; +import { displayNodeName } from '../utils.js'; const RULE_ID = 'require-type-pattern-with-oneof'; @@ -36,7 +37,8 @@ export const rule: GraphQLESLintRule = { ], }, messages: { - [RULE_ID]: 'Type `{{typeName}}` should have `{{fieldName}}` field.', + [RULE_ID]: + '{{ nodeName }} is defined as output with "@oneOf" and must be defined with "{{ fieldName }}" field', }, schema: [], }, @@ -54,7 +56,7 @@ export const rule: GraphQLESLintRule = { node: parent.name, messageId: RULE_ID, data: { - typeName: parent.name.value, + nodeName: displayNodeName(parent), fieldName, }, }); diff --git a/packages/plugin/src/rules/strict-id-in-types.ts b/packages/plugin/src/rules/strict-id-in-types.ts index de79b3a2191..635b75b25e2 100644 --- a/packages/plugin/src/rules/strict-id-in-types.ts +++ b/packages/plugin/src/rules/strict-id-in-types.ts @@ -4,6 +4,7 @@ import { GraphQLESTreeNode } from '../estree-converter/index.js'; import { GraphQLESLintRule } from '../types.js'; import { ARRAY_DEFAULT_OPTIONS, + displayNodeName, englishJoinWords, requireGraphQLSchemaFromContext, truthy, @@ -176,9 +177,9 @@ export const rule: GraphQLESLintRule = { const pluralTypesSuffix = options.acceptedIdTypes.length > 1 ? 's' : ''; context.report({ node: node.name, - message: `${typeName} must have exactly one non-nullable unique identifier. Accepted name${pluralNamesSuffix}: ${englishJoinWords( - options.acceptedIdNames, - )}. Accepted type${pluralTypesSuffix}: ${englishJoinWords(options.acceptedIdTypes)}.`, + message: `${displayNodeName(node)} must have exactly one non-nullable unique identifier. +Accepted name${pluralNamesSuffix}: ${englishJoinWords(options.acceptedIdNames)}. +Accepted type${pluralTypesSuffix}: ${englishJoinWords(options.acceptedIdTypes)}.`, }); } }, diff --git a/packages/plugin/src/utils.ts b/packages/plugin/src/utils.ts index e9f2340d69a..902039272a0 100644 --- a/packages/plugin/src/utils.ts +++ b/packages/plugin/src/utils.ts @@ -48,8 +48,6 @@ export const VIRTUAL_DOCUMENT_REGEX = /\/\d+_document.graphql$/; export const CWD = process.cwd(); -export const IS_BROWSER = typeof window !== 'undefined'; - export const getTypeName = (node: ASTNode): string => 'type' in node ? getTypeName(node.type) : 'name' in node && node.name ? node.name.value : ''; @@ -124,20 +122,36 @@ export function truthy(value: T): value is Truthy { return !!value; } -export function getNodeName(node: GraphQLESTreeNode): string { - const DisplayNodeNameMap: Record = { - [Kind.OBJECT_TYPE_DEFINITION]: 'type', - [Kind.INTERFACE_TYPE_DEFINITION]: 'interface', - [Kind.ENUM_TYPE_DEFINITION]: 'enum', - [Kind.SCALAR_TYPE_DEFINITION]: 'scalar', - [Kind.INPUT_OBJECT_TYPE_DEFINITION]: 'input', - [Kind.UNION_TYPE_DEFINITION]: 'union', - [Kind.DIRECTIVE_DEFINITION]: 'directive', - [Kind.FIELD_DEFINITION]: 'field', - [Kind.ENUM_VALUE_DEFINITION]: 'value', - [Kind.INPUT_VALUE_DEFINITION]: 'value', - } as const; +const DisplayNodeNameMap: Record = { + [Kind.OBJECT_TYPE_DEFINITION]: 'type', + [Kind.OBJECT_TYPE_EXTENSION]: 'type', + [Kind.INTERFACE_TYPE_DEFINITION]: 'interface', + [Kind.INTERFACE_TYPE_EXTENSION]: 'interface', + [Kind.ENUM_TYPE_DEFINITION]: 'enum', + [Kind.ENUM_TYPE_EXTENSION]: 'enum', + [Kind.SCALAR_TYPE_DEFINITION]: 'scalar', + [Kind.INPUT_OBJECT_TYPE_DEFINITION]: 'input', + [Kind.INPUT_OBJECT_TYPE_EXTENSION]: 'input', + [Kind.UNION_TYPE_DEFINITION]: 'union', + [Kind.UNION_TYPE_EXTENSION]: 'union', + [Kind.DIRECTIVE_DEFINITION]: 'directive', + [Kind.FIELD_DEFINITION]: 'field', + [Kind.ENUM_VALUE_DEFINITION]: 'enum value', + [Kind.INPUT_VALUE_DEFINITION]: 'input value', + [Kind.ARGUMENT]: 'argument', + [Kind.VARIABLE]: 'variable', + [Kind.FRAGMENT_DEFINITION]: 'fragment', + [Kind.OPERATION_DEFINITION]: 'operation', + [Kind.FIELD]: 'field', +} as const; +export function displayNodeName(node: GraphQLESTreeNode): string { + return `${ + node.kind === Kind.OPERATION_DEFINITION ? node.operation : DisplayNodeNameMap[node.kind] + } "${('alias' in node && node.alias?.value) || ('name' in node && node.name?.value)}"`; +} + +export function getNodeName(node: GraphQLESTreeNode): string { switch (node.kind) { case Kind.OBJECT_TYPE_DEFINITION: case Kind.INTERFACE_TYPE_DEFINITION: @@ -146,15 +160,13 @@ export function getNodeName(node: GraphQLESTreeNode): string { case Kind.INPUT_OBJECT_TYPE_DEFINITION: case Kind.UNION_TYPE_DEFINITION: case Kind.DIRECTIVE_DEFINITION: - return `${DisplayNodeNameMap[node.kind]} "${node.name.value}"`; + return displayNodeName(node); case Kind.FIELD_DEFINITION: case Kind.INPUT_VALUE_DEFINITION: case Kind.ENUM_VALUE_DEFINITION: - return `${DisplayNodeNameMap[node.kind]} "${node.name.value}" in ${ - DisplayNodeNameMap[node.parent.kind] - } "${node.parent.name.value}"`; + return `${displayNodeName(node)} in ${displayNodeName(node.parent)}`; case Kind.OPERATION_DEFINITION: - return node.name ? `${node.operation} "${node.name.value}"` : node.operation; + return node.name ? displayNodeName(node) : node.operation; } return ''; } diff --git a/packages/plugin/tests/__snapshots__/alphabetize.spec.md b/packages/plugin/tests/__snapshots__/alphabetize.spec.md index 8af5517fc5d..3c5e5813eab 100644 --- a/packages/plugin/tests/__snapshots__/alphabetize.spec.md +++ b/packages/plugin/tests/__snapshots__/alphabetize.spec.md @@ -22,14 +22,14 @@ exports[`Invalid #1 1`] = ` 2 | password: String > 3 | firstName: String! - | ^^^^^^^^^ \`firstName\` should be before \`password\`. + | ^^^^^^^^^ field "firstName" should be before field "password" 4 | age: Int #### ❌ Error 2/2 3 | firstName: String! > 4 | age: Int - | ^^^ \`age\` should be before \`firstName\`. + | ^^^ field "age" should be before field "firstName" 5 | lastName: String! #### πŸ”§ Autofix output @@ -64,7 +64,7 @@ exports[`Invalid #2 1`] = ` 4 | password: String > 5 | lastName: String! - | ^^^^^^^^ \`lastName\` should be before \`password\`. + | ^^^^^^^^ field "lastName" should be before field "password" 6 | } #### πŸ”§ Autofix output @@ -98,14 +98,14 @@ exports[`Invalid #3 1`] = ` 2 | cc: Int > 3 | bb: Int - | ^^ \`bb\` should be before \`cc\`. + | ^^ field "bb" should be before field "cc" 4 | aa: Int #### ❌ Error 2/2 3 | bb: Int > 4 | aa: Int - | ^^ \`aa\` should be before \`bb\`. + | ^^ field "aa" should be before field "bb" 5 | } #### πŸ”§ Autofix output @@ -139,14 +139,14 @@ exports[`Invalid #4 1`] = ` 2 | password: String > 3 | firstName: String! - | ^^^^^^^^^ \`firstName\` should be before \`password\`. + | ^^^^^^^^^ input value "firstName" should be before input value "password" 4 | age: Int #### ❌ Error 2/2 3 | firstName: String! > 4 | age: Int - | ^^^ \`age\` should be before \`firstName\`. + | ^^^ input value "age" should be before input value "firstName" 5 | lastName: String! #### πŸ”§ Autofix output @@ -181,7 +181,7 @@ exports[`Invalid #5 1`] = ` 4 | password: String > 5 | lastName: String! - | ^^^^^^^^ \`lastName\` should be before \`password\`. + | ^^^^^^^^ input value "lastName" should be before input value "password" 6 | } #### πŸ”§ Autofix output @@ -216,14 +216,14 @@ exports[`Invalid #6 1`] = ` 2 | SUPER_ADMIN > 3 | ADMIN - | ^^^^^ \`ADMIN\` should be before \`SUPER_ADMIN\`. + | ^^^^^ enum value "ADMIN" should be before enum value "SUPER_ADMIN" 4 | USER #### ❌ Error 2/2 4 | USER > 5 | GOD - | ^^^ \`GOD\` should be before \`USER\`. + | ^^^ enum value "GOD" should be before enum value "USER" 6 | } #### πŸ”§ Autofix output @@ -258,7 +258,7 @@ exports[`Invalid #7 1`] = ` 3 | SUPER_ADMIN > 4 | GOD - | ^^^ \`GOD\` should be before \`SUPER_ADMIN\`. + | ^^^ enum value "GOD" should be before enum value "SUPER_ADMIN" 5 | USER #### πŸ”§ Autofix output @@ -287,12 +287,12 @@ exports[`Invalid #8 1`] = ` #### ❌ Error 1/2 > 1 | directive @test(cc: [Cc!]!, bb: [Bb!], aa: Aa!) on FIELD_DEFINITION - | ^^ \`bb\` should be before \`cc\`. + | ^^ input value "bb" should be before input value "cc" #### ❌ Error 2/2 > 1 | directive @test(cc: [Cc!]!, bb: [Bb!], aa: Aa!) on FIELD_DEFINITION - | ^^ \`aa\` should be before \`bb\`. + | ^^ input value "aa" should be before input value "bb" #### πŸ”§ Autofix output @@ -318,14 +318,14 @@ exports[`Invalid #9 1`] = ` 1 | type Query { > 2 | test(cc: [Cc!]!, bb: [Bb!], aa: Aa!): Int - | ^^ \`bb\` should be before \`cc\`. + | ^^ input value "bb" should be before input value "cc" 3 | } #### ❌ Error 2/2 1 | type Query { > 2 | test(cc: [Cc!]!, bb: [Bb!], aa: Aa!): Int - | ^^ \`aa\` should be before \`bb\`. + | ^^ input value "aa" should be before input value "bb" 3 | } #### πŸ”§ Autofix output @@ -356,14 +356,14 @@ exports[`Invalid #10 1`] = ` 2 | cc > 3 | bb - | ^^ \`bb\` should be before \`cc\`. + | ^^ field "bb" should be before field "cc" 4 | aa #### ❌ Error 2/2 3 | bb > 4 | aa - | ^^ \`aa\` should be before \`bb\`. + | ^^ field "aa" should be before field "bb" 5 | } #### πŸ”§ Autofix output @@ -403,28 +403,28 @@ exports[`Invalid #11 1`] = ` 5 | ccc > 6 | bbb - | ^^^ \`bbb\` should be before \`ccc\`. + | ^^^ field "bbb" should be before field "ccc" 7 | aaa #### ❌ Error 2/4 6 | bbb > 7 | aaa - | ^^^ \`aaa\` should be before \`bbb\`. + | ^^^ field "aaa" should be before field "bbb" 8 | } #### ❌ Error 3/4 8 | } > 9 | bb - | ^^ \`bb\` should be before inline fragment. + | ^^ field "bb" should be before inline fragment 10 | aa #### ❌ Error 4/4 9 | bb > 10 | aa - | ^^ \`aa\` should be before \`bb\`. + | ^^ field "aa" should be before field "bb" 11 | } #### πŸ”§ Autofix output @@ -466,27 +466,27 @@ exports[`Invalid #12 1`] = ` #### ❌ Error 1/4 > 1 | mutation ($cc: [Cc!]!, $bb: [Bb!], $aa: Aa!) { - | ^^ \`bb\` should be before \`cc\`. + | ^^ variable "bb" should be before variable "cc" 2 | test(ccc: $cc, bbb: $bb, aaa: $aa) { #### ❌ Error 2/4 > 1 | mutation ($cc: [Cc!]!, $bb: [Bb!], $aa: Aa!) { - | ^^ \`aa\` should be before \`bb\`. + | ^^ variable "aa" should be before variable "bb" 2 | test(ccc: $cc, bbb: $bb, aaa: $aa) { #### ❌ Error 3/4 1 | mutation ($cc: [Cc!]!, $bb: [Bb!], $aa: Aa!) { > 2 | test(ccc: $cc, bbb: $bb, aaa: $aa) { - | ^^^ \`bbb\` should be before \`ccc\`. + | ^^^ argument "bbb" should be before argument "ccc" 3 | something #### ❌ Error 4/4 1 | mutation ($cc: [Cc!]!, $bb: [Bb!], $aa: Aa!) { > 2 | test(ccc: $cc, bbb: $bb, aaa: $aa) { - | ^^^ \`aaa\` should be before \`bbb\`. + | ^^^ argument "aaa" should be before argument "bbb" 3 | something #### πŸ”§ Autofix output @@ -525,21 +525,21 @@ exports[`should compare with lexicographic order 1`] = ` 3 | qux > 4 | foo - | ^^^ \`foo\` should be before \`qux\`. + | ^^^ enum value "foo" should be before enum value "qux" 5 | "Bar" #### ❌ Error 2/3 5 | "Bar" > 6 | Bar - | ^^^ \`Bar\` should be before \`foo\`. + | ^^^ enum value "Bar" should be before enum value "foo" 7 | """ #### ❌ Error 3/3 9 | """ > 10 | bar - | ^^^ \`bar\` should be before \`Bar\`. + | ^^^ enum value "bar" should be before enum value "Bar" 11 | } #### πŸ”§ Autofix output @@ -587,21 +587,21 @@ exports[`should move comment 1`] = ` 6 | # before c > 7 | c: Float! - | ^ \`c\` should be before \`d\`. + | ^ field "c" should be before field "d" 8 | # before b 1 #### ❌ Error 2/3 9 | # before b 2 > 10 | b: [String] # same b - | ^ \`b\` should be before \`c\`. + | ^ field "b" should be before field "c" 11 | # before a #### ❌ Error 3/3 11 | # before a > 12 | a: [Int!]! # same a - | ^ \`a\` should be before \`b\`. + | ^ field "a" should be before field "b" 13 | # end #### πŸ”§ Autofix output @@ -656,28 +656,28 @@ exports[`should sort by group when \`*\` at the start 1`] = ` 3 | createdAt: DateTime > 4 | author: Int - | ^^^^^^ \`author\` should be before \`createdAt\`. + | ^^^^^^ field "author" should be before field "createdAt" 5 | wagon: Int #### ❌ Error 2/4 6 | id: ID > 7 | foo: Int - | ^^^ \`foo\` should be before \`id\`. + | ^^^ field "foo" should be before field "id" 8 | updatedAt: DateTime #### ❌ Error 3/4 8 | updatedAt: DateTime > 9 | bar: Int - | ^^^ \`bar\` should be before \`updatedAt\`. + | ^^^ field "bar" should be before field "updatedAt" 10 | nachos: Int #### ❌ Error 4/4 10 | nachos: Int > 11 | guild: Int - | ^^^^^ \`guild\` should be before \`nachos\`. + | ^^^^^ field "guild" should be before field "nachos" 12 | } #### πŸ”§ Autofix output @@ -730,28 +730,28 @@ exports[`should sort by group when \`*\` is at the end 1`] = ` 2 | firstName: Int > 3 | createdAt: DateTime - | ^^^^^^^^^ \`createdAt\` should be before \`firstName\`. + | ^^^^^^^^^ field "createdAt" should be before field "firstName" 4 | author: Int #### ❌ Error 2/4 5 | wagon: Int > 6 | id: ID - | ^^ \`id\` should be before \`wagon\`. + | ^^ field "id" should be before field "wagon" 7 | foo: Int #### ❌ Error 3/4 7 | foo: Int > 8 | updatedAt: DateTime - | ^^^^^^^^^ \`updatedAt\` should be before \`foo\`. + | ^^^^^^^^^ field "updatedAt" should be before field "foo" 9 | bar: Int #### ❌ Error 4/4 10 | nachos: Int > 11 | guild: Int - | ^^^^^ \`guild\` should be before \`nachos\`. + | ^^^^^ field "guild" should be before field "nachos" 12 | } #### πŸ”§ Autofix output @@ -804,28 +804,28 @@ exports[`should sort by group when \`*\` is between 1`] = ` 3 | createdAt: DateTime > 4 | author: Int - | ^^^^^^ \`author\` should be before \`createdAt\`. + | ^^^^^^ field "author" should be before field "createdAt" 5 | wagon: Int #### ❌ Error 2/4 5 | wagon: Int > 6 | id: ID - | ^^ \`id\` should be before \`wagon\`. + | ^^ field "id" should be before field "wagon" 7 | foo: Int #### ❌ Error 3/4 8 | updatedAt: DateTime > 9 | bar: Int - | ^^^ \`bar\` should be before \`updatedAt\`. + | ^^^ field "bar" should be before field "updatedAt" 10 | nachos: Int #### ❌ Error 4/4 10 | nachos: Int > 11 | guild: Int - | ^^^^^ \`guild\` should be before \`nachos\`. + | ^^^^^ field "guild" should be before field "nachos" 12 | } #### πŸ”§ Autofix output @@ -917,63 +917,63 @@ exports[`should sort definitions 1`] = ` 10 | # before fragment UserFields > 11 | fragment UserFields on User { - | ^^^^^^^^^^ \`UserFields\` should be before \`UserInput\`. + | ^^^^^^^^^^ fragment "UserFields" should be before input "UserInput" 12 | id #### ❌ Error 2/9 14 | # before type User > 15 | type User # same type User - | ^^^^ \`User\` should be before \`UserFields\`. + | ^^^^ type "User" should be before fragment "UserFields" 16 | # before extend enum Role #### ❌ Error 3/9 16 | # before extend enum Role > 17 | extend enum Role { - | ^^^^ \`Role\` should be before \`User\`. + | ^^^^ enum "Role" should be before type "User" 18 | SUPERMAN #### ❌ Error 4/9 24 | # before mutation CreateUser > 25 | mutation CreateUser { - | ^^^^^^^^^^ \`CreateUser\` should be before operation definition. + | ^^^^^^^^^^ mutation "CreateUser" should be before operation definition 26 | createUser #### ❌ Error 5/9 38 | # before interface Node > 39 | interface Node # same interface Node - | ^^^^ \`Node\` should be before \`RootQuery\`. + | ^^^^ interface "Node" should be before type "RootQuery" 40 | # before enum Role #### ❌ Error 6/9 42 | # before scalar Email > 43 | scalar Email # same scalar Email - | ^^^^^ \`Email\` should be before \`Role\`. + | ^^^^^ scalar "Email" should be before enum "Role" 44 | # before input UserInput #### ❌ Error 7/9 46 | # before extend type User > 47 | extend type User { - | ^^^^ \`User\` should be before \`UserInput\`. + | ^^^^ type "User" should be before input "UserInput" 48 | firstName: String! #### ❌ Error 8/9 54 | # before union Data > 55 | union Data = User | Node # same union Data - | ^^^^ \`Data\` should be before schema definition. + | ^^^^ union "Data" should be before schema definition 56 | # before directive @auth #### ❌ Error 9/9 56 | # before directive @auth > 57 | directive @auth(role: [Role!]!) on FIELD_DEFINITION # same directive @auth - | ^^^^ \`auth\` should be before \`Data\`. + | ^^^^ directive "auth" should be before union "Data" 58 | #### πŸ”§ Autofix output @@ -1062,14 +1062,14 @@ exports[`should sort when selection is aliased 1`] = ` 3 | lastName: lastname # lastName comment > 4 | fullName: fullname # fullName comment - | ^^^^^^^^ \`fullName\` should be before \`lastName\`. + | ^^^^^^^^ field "fullName" should be before field "lastName" 5 | firsName: firstname # firsName comment #### ❌ Error 2/2 4 | fullName: fullname # fullName comment > 5 | firsName: firstname # firsName comment - | ^^^^^^^^ \`firsName\` should be before \`fullName\`. + | ^^^^^^^^ field "firsName" should be before field "fullName" 6 | # end #### πŸ”§ Autofix output diff --git a/packages/plugin/tests/__snapshots__/description-style.spec.md b/packages/plugin/tests/__snapshots__/description-style.spec.md index f63246ed401..d46cf142c4b 100644 --- a/packages/plugin/tests/__snapshots__/description-style.spec.md +++ b/packages/plugin/tests/__snapshots__/description-style.spec.md @@ -28,7 +28,7 @@ exports[`Invalid #1 1`] = ` 1 | enum EnumUserLanguagesSkill { > 2 | """ - | ^ Unexpected block description. + | ^ Unexpected block description for enum value "basic" in enum "EnumUserLanguagesSkill" 3 | basic #### πŸ’‘ Suggestion: Change to inline style description @@ -50,7 +50,7 @@ exports[`Invalid #1 1`] = ` 5 | basic > 6 | """ - | ^ Unexpected block description. + | ^ Unexpected block description for enum value "fluent" in enum "EnumUserLanguagesSkill" 7 | fluent #### πŸ’‘ Suggestion: Change to inline style description @@ -72,7 +72,7 @@ exports[`Invalid #1 1`] = ` 9 | fluent > 10 | """ - | ^ Unexpected block description. + | ^ Unexpected block description for enum value "native" in enum "EnumUserLanguagesSkill" 11 | native #### πŸ’‘ Suggestion: Change to inline style description @@ -106,7 +106,7 @@ exports[`Invalid #2 1`] = ` #### ❌ Error 1/3 > 1 | " Test " - | ^^^^^^^^ Unexpected inline description. + | ^^^^^^^^ Unexpected inline description for type "CreateOneUserPayload" 2 | type CreateOneUserPayload { #### πŸ’‘ Suggestion: Change to block style description @@ -124,7 +124,7 @@ exports[`Invalid #2 1`] = ` 2 | type CreateOneUserPayload { > 3 | "Created document ID" - | ^^^^^^^^^^^^^^^^^^^^^ Unexpected inline description. + | ^^^^^^^^^^^^^^^^^^^^^ Unexpected inline description for field "recordId" in type "CreateOneUserPayload" 4 | recordId: MongoID #### πŸ’‘ Suggestion: Change to block style description @@ -142,7 +142,7 @@ exports[`Invalid #2 1`] = ` 5 | > 6 | "Created document" - | ^^^^^^^^^^^^^^^^^^ Unexpected inline description. + | ^^^^^^^^^^^^^^^^^^ Unexpected inline description for field "record" in type "CreateOneUserPayload" 7 | record: User #### πŸ’‘ Suggestion: Change to block style description diff --git a/packages/plugin/tests/__snapshots__/examples.spec.md b/packages/plugin/tests/__snapshots__/examples.spec.md index 14f06efd925..1574659785c 100644 --- a/packages/plugin/tests/__snapshots__/examples.spec.md +++ b/packages/plugin/tests/__snapshots__/examples.spec.md @@ -210,7 +210,9 @@ exports[`Examples > should work in multiple projects 1`] = ` endColumn: 10, endLine: 1, line: 1, - message: User must have exactly one non-nullable unique identifier. Accepted name: id. Accepted type: ID., + message: type "User" must have exactly one non-nullable unique identifier. +Accepted name: id. +Accepted type: ID., nodeType: Name, ruleId: @graphql-eslint/strict-id-in-types, severity: 2, @@ -225,7 +227,9 @@ exports[`Examples > should work in multiple projects 1`] = ` endColumn: 10, endLine: 1, line: 1, - message: User must have exactly one non-nullable unique identifier. Accepted name: id. Accepted type: ID., + message: type "User" must have exactly one non-nullable unique identifier. +Accepted name: id. +Accepted type: ID., nodeType: Name, ruleId: @graphql-eslint/strict-id-in-types, severity: 2, diff --git a/packages/plugin/tests/__snapshots__/input-name.spec.md b/packages/plugin/tests/__snapshots__/input-name.spec.md index 9387a7b7bb0..35290a274a7 100644 --- a/packages/plugin/tests/__snapshots__/input-name.spec.md +++ b/packages/plugin/tests/__snapshots__/input-name.spec.md @@ -14,7 +14,7 @@ exports[`Invalid #1 1`] = ` #### ❌ Error 1/2 > 1 | type Mutation { SetMessage(message: String): String } - | ^^^^^^^ Input \`message\` should be called \`input\`. + | ^^^^^^^ Input "message" should be named "input" for "Mutation.SetMessage" #### πŸ’‘ Suggestion: Rename to \`input\` @@ -65,7 +65,7 @@ exports[`Invalid #3 1`] = ` #### ❌ Error > 1 | type Mutation { SetMessage(hello: SetMessageInput): String } - | ^^^^^ Input \`hello\` should be called \`input\`. + | ^^^^^ Input "hello" should be named "input" for "Mutation.SetMessage" #### πŸ’‘ Suggestion: Rename to \`input\` @@ -86,7 +86,7 @@ exports[`Invalid #4 1`] = ` #### ❌ Error 1/2 > 1 | type Mutation { userCreate(record: CreateOneUserInput!): CreateOneUserPayload } - | ^^^^^^ Input \`record\` should be called \`input\`. + | ^^^^^^ Input "record" should be named "input" for "Mutation.userCreate" #### πŸ’‘ Suggestion: Rename to \`input\` @@ -116,7 +116,7 @@ exports[`Invalid #5 1`] = ` #### ❌ Error 1/2 > 1 | type Mutation { userCreate(record: [CreateOneUserInput]!): CreateOneUserPayload } - | ^^^^^^ Input \`record\` should be called \`input\`. + | ^^^^^^ Input "record" should be named "input" for "Mutation.userCreate" #### πŸ’‘ Suggestion: Rename to \`input\` @@ -146,7 +146,7 @@ exports[`Invalid #6 1`] = ` #### ❌ Error 1/2 > 1 | type Mutation { userCreate(record: [CreateOneUserInput!]!): CreateOneUserPayload } - | ^^^^^^ Input \`record\` should be called \`input\`. + | ^^^^^^ Input "record" should be named "input" for "Mutation.userCreate" #### πŸ’‘ Suggestion: Rename to \`input\` @@ -176,7 +176,7 @@ exports[`Invalid #7 1`] = ` #### ❌ Error 1/2 > 1 | type Mutation { userCreate(record: [CreateOneUserInput!]): CreateOneUserPayload } - | ^^^^^^ Input \`record\` should be called \`input\`. + | ^^^^^^ Input "record" should be named "input" for "Mutation.userCreate" #### πŸ’‘ Suggestion: Rename to \`input\` @@ -206,7 +206,7 @@ exports[`Invalid #8 1`] = ` #### ❌ Error 1/4 > 1 | type Mutation { userCreate(record: String, test: String): String } - | ^^^^^^ Input \`record\` should be called \`input\`. + | ^^^^^^ Input "record" should be named "input" for "Mutation.userCreate" #### πŸ’‘ Suggestion: Rename to \`input\` @@ -224,7 +224,7 @@ exports[`Invalid #8 1`] = ` #### ❌ Error 3/4 > 1 | type Mutation { userCreate(record: String, test: String): String } - | ^^^^ Input \`test\` should be called \`input\`. + | ^^^^ Input "test" should be named "input" for "Mutation.userCreate" #### πŸ’‘ Suggestion: Rename to \`input\` @@ -254,7 +254,7 @@ exports[`Invalid #9 1`] = ` #### ❌ Error 1/2 > 1 | type Mutation { userCreate(record: String, test: String): String } - | ^^^^^^ Input \`record\` should be called \`input\`. + | ^^^^^^ Input "record" should be named "input" for "Mutation.userCreate" #### πŸ’‘ Suggestion: Rename to \`input\` @@ -263,7 +263,7 @@ exports[`Invalid #9 1`] = ` #### ❌ Error 2/2 > 1 | type Mutation { userCreate(record: String, test: String): String } - | ^^^^ Input \`test\` should be called \`input\`. + | ^^^^ Input "test" should be named "input" for "Mutation.userCreate" #### πŸ’‘ Suggestion: Rename to \`input\` diff --git a/packages/plugin/tests/__snapshots__/no-case-insensitive-enum-values-duplicates.spec.md b/packages/plugin/tests/__snapshots__/no-case-insensitive-enum-values-duplicates.spec.md index 01509236287..e00d7f30621 100644 --- a/packages/plugin/tests/__snapshots__/no-case-insensitive-enum-values-duplicates.spec.md +++ b/packages/plugin/tests/__snapshots__/no-case-insensitive-enum-values-duplicates.spec.md @@ -8,7 +8,7 @@ exports[`Invalid #1 1`] = ` #### ❌ Error > 1 | enum A { TEST TesT } - | ^^^^ Case-insensitive enum values duplicates are not allowed! Found: \`TesT\`. + | ^^^^ Unexpected case-insensitive enum values duplicates for enum value "TesT" in enum "A" #### πŸ’‘ Suggestion: Remove \`TesT\` enum value @@ -23,7 +23,7 @@ exports[`Invalid #2 1`] = ` #### ❌ Error > 1 | extend enum A { TEST TesT } - | ^^^^ Case-insensitive enum values duplicates are not allowed! Found: \`TesT\`. + | ^^^^ Unexpected case-insensitive enum values duplicates for enum value "TesT" in enum "A" #### πŸ’‘ Suggestion: Remove \`TesT\` enum value diff --git a/packages/plugin/tests/__snapshots__/no-hashtag-description.spec.md b/packages/plugin/tests/__snapshots__/no-hashtag-description.spec.md index b13002be752..d4fb34a2274 100644 --- a/packages/plugin/tests/__snapshots__/no-hashtag-description.spec.md +++ b/packages/plugin/tests/__snapshots__/no-hashtag-description.spec.md @@ -11,7 +11,8 @@ exports[`Invalid #1 1`] = ` #### ❌ Error > 1 | # Bad - | ^ Using hashtag \`#\` for adding GraphQL descriptions is not allowed. Prefer using \`"""\` for multiline, or \`"\` for a single line description. + | ^ Unexpected GraphQL descriptions as hashtag \`#\` for type "Query". + Prefer using \`"""\` for multiline, or \`"\` for a single line description. 2 | type Query { #### πŸ’‘ Suggestion 1/2: Replace with \`"""\` description syntax @@ -42,7 +43,8 @@ exports[`Invalid #2 1`] = ` 1 | # multiline > 2 | # multiline - | ^ Using hashtag \`#\` for adding GraphQL descriptions is not allowed. Prefer using \`"""\` for multiline, or \`"\` for a single line description. + | ^ Unexpected GraphQL descriptions as hashtag \`#\` for type "Query". + Prefer using \`"""\` for multiline, or \`"\` for a single line description. 3 | type Query { #### πŸ’‘ Suggestion 1/2: Replace with \`"""\` description syntax @@ -74,7 +76,8 @@ exports[`Invalid #3 1`] = ` 1 | type Query { > 2 | # Bad - | ^ Using hashtag \`#\` for adding GraphQL descriptions is not allowed. Prefer using \`"""\` for multiline, or \`"\` for a single line description. + | ^ Unexpected GraphQL descriptions as hashtag \`#\` for field "foo" in type "Query". + Prefer using \`"""\` for multiline, or \`"\` for a single line description. 3 | foo: String #### πŸ’‘ Suggestion 1/2: Replace with \`"""\` description syntax @@ -106,7 +109,8 @@ exports[`Invalid #4 1`] = ` 2 | bar: ID > 3 | # Bad - | ^ Using hashtag \`#\` for adding GraphQL descriptions is not allowed. Prefer using \`"""\` for multiline, or \`"\` for a single line description. + | ^ Unexpected GraphQL descriptions as hashtag \`#\` for field "foo" in type "Query". + Prefer using \`"""\` for multiline, or \`"\` for a single line description. 4 | foo: ID #### πŸ’‘ Suggestion 1/2: Replace with \`"""\` description syntax @@ -142,7 +146,8 @@ exports[`Invalid #5 1`] = ` 2 | user( > 3 | # Bad - | ^ Using hashtag \`#\` for adding GraphQL descriptions is not allowed. Prefer using \`"""\` for multiline, or \`"\` for a single line description. + | ^ Unexpected GraphQL descriptions as hashtag \`#\` for input value "id" in field "user". + Prefer using \`"""\` for multiline, or \`"\` for a single line description. 4 | id: Int! #### πŸ’‘ Suggestion 1/2: Replace with \`"""\` description syntax diff --git a/packages/plugin/tests/__snapshots__/no-scalar-result-type-on-mutation.spec.md b/packages/plugin/tests/__snapshots__/no-scalar-result-type-on-mutation.spec.md index 503f1c74730..32c7667a1a5 100644 --- a/packages/plugin/tests/__snapshots__/no-scalar-result-type-on-mutation.spec.md +++ b/packages/plugin/tests/__snapshots__/no-scalar-result-type-on-mutation.spec.md @@ -13,7 +13,7 @@ exports[`Invalid #2 1`] = ` 3 | extend type Mutation { > 4 | createUser: Boolean! - | ^^^^^^^ Unexpected scalar result type \`Boolean\`. + | ^^^^^^^ Unexpected scalar result type \`Boolean\` for field "createUser" in type "Mutation" 5 | } #### πŸ’‘ Suggestion: Remove \`Boolean\` @@ -40,7 +40,7 @@ exports[`Invalid #3 1`] = ` 1 | type RootMutation { > 2 | createUser: [Boolean] - | ^^^^^^^ Unexpected scalar result type \`Boolean\`. + | ^^^^^^^ Unexpected scalar result type \`Boolean\` for field "createUser" in type "RootMutation" 3 | } #### πŸ’‘ Suggestion: Remove \`Boolean\` @@ -70,7 +70,7 @@ exports[`Invalid #4 1`] = ` 2 | extend type RootMutation { > 3 | createUser: [Boolean]! - | ^^^^^^^ Unexpected scalar result type \`Boolean\`. + | ^^^^^^^ Unexpected scalar result type \`Boolean\` for field "createUser" in type "RootMutation" 4 | } #### πŸ’‘ Suggestion: Remove \`Boolean\` @@ -98,7 +98,7 @@ exports[`Invalid #5 1`] = ` 2 | createUser: User! > 3 | updateUser: Int - | ^^^ Unexpected scalar result type \`Int\`. + | ^^^ Unexpected scalar result type \`Int\` for field "updateUser" in type "Mutation" 4 | deleteUser: [Boolean!]! #### πŸ’‘ Suggestion: Remove \`Int\` @@ -113,7 +113,7 @@ exports[`Invalid #5 1`] = ` 3 | updateUser: Int > 4 | deleteUser: [Boolean!]! - | ^^^^^^^ Unexpected scalar result type \`Boolean\`. + | ^^^^^^^ Unexpected scalar result type \`Boolean\` for field "deleteUser" in type "Mutation" 5 | } #### πŸ’‘ Suggestion: Remove \`Boolean\` @@ -136,7 +136,7 @@ exports[`should ignore arguments 1`] = ` 1 | type Mutation { > 2 | createUser(a: ID, b: ID!, c: [ID]!, d: [ID!]!): Boolean - | ^^^^^^^ Unexpected scalar result type \`Boolean\`. + | ^^^^^^^ Unexpected scalar result type \`Boolean\` for field "createUser" in type "Mutation" 3 | } #### πŸ’‘ Suggestion: Remove \`Boolean\` diff --git a/packages/plugin/tests/__snapshots__/require-deprecation-date.spec.md b/packages/plugin/tests/__snapshots__/require-deprecation-date.spec.md index a1bace95299..b7923f54861 100644 --- a/packages/plugin/tests/__snapshots__/require-deprecation-date.spec.md +++ b/packages/plugin/tests/__snapshots__/require-deprecation-date.spec.md @@ -8,7 +8,7 @@ exports[`Invalid #1 1`] = ` #### ❌ Error > 1 | scalar Old @deprecated(deletionDate: "22/08/2021") - | ^^^ "Old" сan be removed + | ^^^ scalar "Old" сan be removed #### πŸ’‘ Suggestion: Remove \`Old\` @@ -29,7 +29,7 @@ exports[`Invalid #2 1`] = ` #### ❌ Error > 1 | scalar Old @deprecated(untilDate: "22/08/2021") - | ^^^ "Old" сan be removed + | ^^^ scalar "Old" сan be removed #### πŸ’‘ Suggestion: Remove \`Old\` @@ -44,7 +44,7 @@ exports[`Invalid #3 1`] = ` #### ❌ Error > 1 | scalar Old @deprecated(deletionDate: "bad") - | ^^^^^ Deletion date must be in format "DD/MM/YYYY" + | ^^^^^ Deletion date must be in format "DD/MM/YYYY" for scalar "Old" `; exports[`Invalid #4 1`] = ` @@ -55,7 +55,7 @@ exports[`Invalid #4 1`] = ` #### ❌ Error > 1 | scalar Old @deprecated(deletionDate: "32/08/2021") - | ^^^^^^^^^^^^ Invalid "32/08/2021" deletion date + | ^^^^^^^^^^^^ Invalid "32/08/2021" deletion date for scalar "Old" `; exports[`Invalid #5 1`] = ` @@ -66,5 +66,5 @@ exports[`Invalid #5 1`] = ` #### ❌ Error > 1 | type Old { oldField: ID @deprecated } - | ^^^^^^^^^^ Directive "@deprecated" must have a deletion date + | ^^^^^^^^^^ Directive "@deprecated" must have a deletion date for field "oldField" in type "Old" `; diff --git a/packages/plugin/tests/__snapshots__/require-deprecation-reason.spec.md b/packages/plugin/tests/__snapshots__/require-deprecation-reason.spec.md index 74b1c001957..6eaf90e70ff 100644 --- a/packages/plugin/tests/__snapshots__/require-deprecation-reason.spec.md +++ b/packages/plugin/tests/__snapshots__/require-deprecation-reason.spec.md @@ -39,7 +39,7 @@ exports[`Invalid #1 1`] = ` 7 | enum TestEnum { > 8 | item1 @deprecated - | ^^^^^^^^^^ Deprecation reason is required for value "item1" in enum "TestEnum". + | ^^^^^^^^^^ Deprecation reason is required for enum value "item1" in enum "TestEnum". 9 | item2 @deprecated(reason: "Reason") #### ❌ Error 3/7 @@ -74,6 +74,6 @@ exports[`Invalid #1 1`] = ` 22 | input MyInput { > 23 | foo: String! @deprecated - | ^^^^^^^^^^ Deprecation reason is required for value "foo" in input "MyInput". + | ^^^^^^^^^^ Deprecation reason is required for input value "foo" in input "MyInput". 24 | } `; diff --git a/packages/plugin/tests/__snapshots__/require-description.spec.md b/packages/plugin/tests/__snapshots__/require-description.spec.md index 77e5b61bf2c..c55d6c1df5f 100644 --- a/packages/plugin/tests/__snapshots__/require-description.spec.md +++ b/packages/plugin/tests/__snapshots__/require-description.spec.md @@ -150,7 +150,7 @@ exports[`Invalid #9 1`] = ` #### ❌ Error > 1 | input CreateUserInput { email: Email! } - | ^^^^^ Description is required for value "email" in input "CreateUserInput" + | ^^^^^ Description is required for input value "email" in input "CreateUserInput" `; exports[`Invalid #10 1`] = ` @@ -167,7 +167,7 @@ exports[`Invalid #10 1`] = ` #### ❌ Error > 1 | enum Role { ADMIN } - | ^^^^^ Description is required for value "ADMIN" in enum "Role" + | ^^^^^ Description is required for enum value "ADMIN" in enum "Role" `; exports[`Invalid #17 1`] = ` diff --git a/packages/plugin/tests/__snapshots__/require-nullable-fields-with-oneof.spec.md b/packages/plugin/tests/__snapshots__/require-nullable-fields-with-oneof.spec.md index adf7272677f..ba7950d4d42 100644 --- a/packages/plugin/tests/__snapshots__/require-nullable-fields-with-oneof.spec.md +++ b/packages/plugin/tests/__snapshots__/require-nullable-fields-with-oneof.spec.md @@ -12,14 +12,14 @@ exports[`should validate \`input\` 1`] = ` 1 | input Input @oneOf { > 2 | foo: String! - | ^^^ Field \`foo\` must be nullable. + | ^^^ input value "foo" in input "Input" must be nullable when "@oneOf" is in use 3 | bar: [Int]! #### ❌ Error 2/2 2 | foo: String! > 3 | bar: [Int]! - | ^^^ Field \`bar\` must be nullable. + | ^^^ input value "bar" in input "Input" must be nullable when "@oneOf" is in use 4 | } `; @@ -35,6 +35,6 @@ exports[`should validate \`type\` 1`] = ` 1 | type Type @oneOf { > 2 | foo: String! - | ^^^ Field \`foo\` must be nullable. + | ^^^ field "foo" in type "Type" must be nullable when "@oneOf" is in use 3 | bar: Int `; diff --git a/packages/plugin/tests/__snapshots__/require-type-pattern-with-oneof.spec.md b/packages/plugin/tests/__snapshots__/require-type-pattern-with-oneof.spec.md index 87f05186b22..f7bee157a34 100644 --- a/packages/plugin/tests/__snapshots__/require-type-pattern-with-oneof.spec.md +++ b/packages/plugin/tests/__snapshots__/require-type-pattern-with-oneof.spec.md @@ -11,7 +11,7 @@ exports[`should validate \`error\` field 1`] = ` #### ❌ Error > 1 | type T @oneOf { - | ^ Type \`T\` should have \`error\` field. + | ^ type "T" is defined as output with "@oneOf" and must be defined with "error" field 2 | ok: Ok `; @@ -26,6 +26,6 @@ exports[`should validate \`ok\` field 1`] = ` #### ❌ Error > 1 | type T @oneOf { - | ^ Type \`T\` should have \`ok\` field. + | ^ type "T" is defined as output with "@oneOf" and must be defined with "ok" field 2 | notok: Ok `; diff --git a/packages/plugin/tests/__snapshots__/strict-id-in-types.spec.md b/packages/plugin/tests/__snapshots__/strict-id-in-types.spec.md index dca3e9d35d0..2be2ddc54fc 100644 --- a/packages/plugin/tests/__snapshots__/strict-id-in-types.spec.md +++ b/packages/plugin/tests/__snapshots__/strict-id-in-types.spec.md @@ -8,7 +8,9 @@ exports[`Invalid #1 1`] = ` #### ❌ Error > 1 | type B { name: String! } - | ^ B must have exactly one non-nullable unique identifier. Accepted name: id. Accepted type: ID. + | ^ type "B" must have exactly one non-nullable unique identifier. + Accepted name: id. + Accepted type: ID. `; exports[`Invalid #2 1`] = ` @@ -32,7 +34,9 @@ exports[`Invalid #2 1`] = ` #### ❌ Error > 1 | type B { id: ID! _id: String! } - | ^ B must have exactly one non-nullable unique identifier. Accepted names: id or _id. Accepted types: ID or String. + | ^ type "B" must have exactly one non-nullable unique identifier. + Accepted names: id or _id. + Accepted types: ID or String. `; exports[`Invalid #3 1`] = ` @@ -54,22 +58,30 @@ exports[`Invalid #3 1`] = ` #### ❌ Error 1/4 > 1 | type B { id: String! } type B1 { id: [String] } type B2 { id: [String!] } type B3 { id: [String]! } type B4 { id: [String!]! } - | ^^ B1 must have exactly one non-nullable unique identifier. Accepted name: id. Accepted type: String. + | ^^ type "B1" must have exactly one non-nullable unique identifier. + Accepted name: id. + Accepted type: String. #### ❌ Error 2/4 > 1 | type B { id: String! } type B1 { id: [String] } type B2 { id: [String!] } type B3 { id: [String]! } type B4 { id: [String!]! } - | ^^ B2 must have exactly one non-nullable unique identifier. Accepted name: id. Accepted type: String. + | ^^ type "B2" must have exactly one non-nullable unique identifier. + Accepted name: id. + Accepted type: String. #### ❌ Error 3/4 > 1 | type B { id: String! } type B1 { id: [String] } type B2 { id: [String!] } type B3 { id: [String]! } type B4 { id: [String!]! } - | ^^ B3 must have exactly one non-nullable unique identifier. Accepted name: id. Accepted type: String. + | ^^ type "B3" must have exactly one non-nullable unique identifier. + Accepted name: id. + Accepted type: String. #### ❌ Error 4/4 > 1 | type B { id: String! } type B1 { id: [String] } type B2 { id: [String!] } type B3 { id: [String]! } type B4 { id: [String!]! } - | ^^ B4 must have exactly one non-nullable unique identifier. Accepted name: id. Accepted type: String. + | ^^ type "B4" must have exactly one non-nullable unique identifier. + Accepted name: id. + Accepted type: String. `; exports[`Invalid #4 1`] = ` @@ -97,12 +109,16 @@ exports[`Invalid #4 1`] = ` #### ❌ Error 1/2 > 1 | type B { id: ID! } type Bresult { key: String! } type BPayload { bool: Boolean! } type BPagination { num: Int! } - | ^^^^^^^ Bresult must have exactly one non-nullable unique identifier. Accepted name: id. Accepted type: ID. + | ^^^^^^^ type "Bresult" must have exactly one non-nullable unique identifier. + Accepted name: id. + Accepted type: ID. #### ❌ Error 2/2 > 1 | type B { id: ID! } type Bresult { key: String! } type BPayload { bool: Boolean! } type BPagination { num: Int! } - | ^^^^^^^^^^^ BPagination must have exactly one non-nullable unique identifier. Accepted name: id. Accepted type: ID. + | ^^^^^^^^^^^ type "BPagination" must have exactly one non-nullable unique identifier. + Accepted name: id. + Accepted type: ID. `; exports[`Invalid #5 1`] = ` @@ -129,5 +145,7 @@ exports[`Invalid #5 1`] = ` #### ❌ Error > 1 | type B { id: ID! } type BError { message: String! } - | ^^^^^^ BError must have exactly one non-nullable unique identifier. Accepted name: id. Accepted type: ID. + | ^^^^^^ type "BError" must have exactly one non-nullable unique identifier. + Accepted name: id. + Accepted type: ID. `; diff --git a/packages/plugin/tests/alphabetize.spec.ts b/packages/plugin/tests/alphabetize.spec.ts index 4ff6376c735..c3f623b7e4e 100644 --- a/packages/plugin/tests/alphabetize.spec.ts +++ b/packages/plugin/tests/alphabetize.spec.ts @@ -80,8 +80,8 @@ ruleTester.runGraphQLTests('alphabetize', rule, { } `, errors: [ - { message: '`firstName` should be before `password`.' }, - { message: '`age` should be before `firstName`.' }, + { message: 'field "firstName" should be before field "password"' }, + { message: 'field "age" should be before field "firstName"' }, ], }, { @@ -94,7 +94,7 @@ ruleTester.runGraphQLTests('alphabetize', rule, { lastName: String! } `, - errors: [{ message: '`lastName` should be before `password`.' }], + errors: [{ message: 'field "lastName" should be before field "password"' }], }, { options: [{ fields: ['InterfaceTypeDefinition'] }], @@ -106,8 +106,8 @@ ruleTester.runGraphQLTests('alphabetize', rule, { } `, errors: [ - { message: '`bb` should be before `cc`.' }, - { message: '`aa` should be before `bb`.' }, + { message: 'field "bb" should be before field "cc"' }, + { message: 'field "aa" should be before field "bb"' }, ], }, { @@ -121,8 +121,8 @@ ruleTester.runGraphQLTests('alphabetize', rule, { } `, errors: [ - { message: '`firstName` should be before `password`.' }, - { message: '`age` should be before `firstName`.' }, + { message: 'input value "firstName" should be before input value "password"' }, + { message: 'input value "age" should be before input value "firstName"' }, ], }, { @@ -135,7 +135,7 @@ ruleTester.runGraphQLTests('alphabetize', rule, { lastName: String! } `, - errors: [{ message: '`lastName` should be before `password`.' }], + errors: [{ message: 'input value "lastName" should be before input value "password"' }], }, { options: [{ values: ['EnumTypeDefinition'] }], @@ -148,8 +148,8 @@ ruleTester.runGraphQLTests('alphabetize', rule, { } `, errors: [ - { message: '`ADMIN` should be before `SUPER_ADMIN`.' }, - { message: '`GOD` should be before `USER`.' }, + { message: 'enum value "ADMIN" should be before enum value "SUPER_ADMIN"' }, + { message: 'enum value "GOD" should be before enum value "USER"' }, ], }, { @@ -162,7 +162,7 @@ ruleTester.runGraphQLTests('alphabetize', rule, { USER } `, - errors: [{ message: '`GOD` should be before `SUPER_ADMIN`.' }], + errors: [{ message: 'enum value "GOD" should be before enum value "SUPER_ADMIN"' }], }, { options: [{ arguments: ['DirectiveDefinition'] }], @@ -170,8 +170,8 @@ ruleTester.runGraphQLTests('alphabetize', rule, { directive @test(cc: [Cc!]!, bb: [Bb!], aa: Aa!) on FIELD_DEFINITION `, errors: [ - { message: '`bb` should be before `cc`.' }, - { message: '`aa` should be before `bb`.' }, + { message: 'input value "bb" should be before input value "cc"' }, + { message: 'input value "aa" should be before input value "bb"' }, ], }, { @@ -182,8 +182,8 @@ ruleTester.runGraphQLTests('alphabetize', rule, { } `, errors: [ - { message: '`bb` should be before `cc`.' }, - { message: '`aa` should be before `bb`.' }, + { message: 'input value "bb" should be before input value "cc"' }, + { message: 'input value "aa" should be before input value "bb"' }, ], }, { @@ -196,8 +196,8 @@ ruleTester.runGraphQLTests('alphabetize', rule, { } `, errors: [ - { message: '`bb` should be before `cc`.' }, - { message: '`aa` should be before `bb`.' }, + { message: 'field "bb" should be before field "cc"' }, + { message: 'field "aa" should be before field "bb"' }, ], }, { @@ -217,10 +217,10 @@ ruleTester.runGraphQLTests('alphabetize', rule, { } `, errors: [ - { message: '`bbb` should be before `ccc`.' }, - { message: '`aaa` should be before `bbb`.' }, - { message: '`bb` should be before inline fragment.' }, - { message: '`aa` should be before `bb`.' }, + { message: 'field "bbb" should be before field "ccc"' }, + { message: 'field "aaa" should be before field "bbb"' }, + { message: 'field "bb" should be before inline fragment' }, + { message: 'field "aa" should be before field "bb"' }, ], }, { @@ -233,10 +233,10 @@ ruleTester.runGraphQLTests('alphabetize', rule, { } `, errors: [ - { message: '`bb` should be before `cc`.' }, - { message: '`aa` should be before `bb`.' }, - { message: '`bbb` should be before `ccc`.' }, - { message: '`aaa` should be before `bbb`.' }, + { message: 'variable "bb" should be before variable "cc"' }, + { message: 'variable "aa" should be before variable "bb"' }, + { message: 'argument "bbb" should be before argument "ccc"' }, + { message: 'argument "aaa" should be before argument "bbb"' }, ], }, { @@ -259,9 +259,9 @@ ruleTester.runGraphQLTests('alphabetize', rule, { } # } character `, errors: [ - { message: '`c` should be before `d`.' }, - { message: '`b` should be before `c`.' }, - { message: '`a` should be before `b`.' }, + { message: 'field "c" should be before field "d"' }, + { message: 'field "b" should be before field "c"' }, + { message: 'field "a" should be before field "b"' }, ], }, { @@ -281,9 +281,9 @@ ruleTester.runGraphQLTests('alphabetize', rule, { } `, errors: [ - { message: '`foo` should be before `qux`.' }, - { message: '`Bar` should be before `foo`.' }, - { message: '`bar` should be before `Bar`.' }, + { message: 'enum value "foo" should be before enum value "qux"' }, + { message: 'enum value "Bar" should be before enum value "foo"' }, + { message: 'enum value "bar" should be before enum value "Bar"' }, ], }, { @@ -351,15 +351,15 @@ ruleTester.runGraphQLTests('alphabetize', rule, { # END `, errors: [ - { message: '`UserFields` should be before `UserInput`.' }, - { message: '`User` should be before `UserFields`.' }, - { message: '`Role` should be before `User`.' }, - { message: '`CreateUser` should be before operation definition.' }, - { message: '`Node` should be before `RootQuery`.' }, - { message: '`Email` should be before `Role`.' }, - { message: '`User` should be before `UserInput`.' }, - { message: '`Data` should be before schema definition.' }, - { message: '`auth` should be before `Data`.' }, + { message: 'fragment "UserFields" should be before input "UserInput"' }, + { message: 'type "User" should be before fragment "UserFields"' }, + { message: 'enum "Role" should be before type "User"' }, + { message: 'mutation "CreateUser" should be before operation definition' }, + { message: 'interface "Node" should be before type "RootQuery"' }, + { message: 'scalar "Email" should be before enum "Role"' }, + { message: 'type "User" should be before input "UserInput"' }, + { message: 'union "Data" should be before schema definition' }, + { message: 'directive "auth" should be before union "Data"' }, ], }, { @@ -375,8 +375,8 @@ ruleTester.runGraphQLTests('alphabetize', rule, { } `, errors: [ - { message: '`fullName` should be before `lastName`.' }, - { message: '`firsName` should be before `fullName`.' }, + { message: 'field "fullName" should be before field "lastName"' }, + { message: 'field "firsName" should be before field "fullName"' }, ], }, { @@ -389,10 +389,10 @@ ruleTester.runGraphQLTests('alphabetize', rule, { ], code: GROUP_ORDER_TEST, errors: [ - { message: '`author` should be before `createdAt`.' }, - { message: '`id` should be before `wagon`.' }, - { message: '`bar` should be before `updatedAt`.' }, - { message: '`guild` should be before `nachos`.' }, + { message: 'field "author" should be before field "createdAt"' }, + { message: 'field "id" should be before field "wagon"' }, + { message: 'field "bar" should be before field "updatedAt"' }, + { message: 'field "guild" should be before field "nachos"' }, ], }, { @@ -405,10 +405,10 @@ ruleTester.runGraphQLTests('alphabetize', rule, { ], code: GROUP_ORDER_TEST, errors: [ - { message: '`createdAt` should be before `firstName`.' }, - { message: '`id` should be before `wagon`.' }, - { message: '`updatedAt` should be before `foo`.' }, - { message: '`guild` should be before `nachos`.' }, + { message: 'field "createdAt" should be before field "firstName"' }, + { message: 'field "id" should be before field "wagon"' }, + { message: 'field "updatedAt" should be before field "foo"' }, + { message: 'field "guild" should be before field "nachos"' }, ], }, { @@ -421,10 +421,10 @@ ruleTester.runGraphQLTests('alphabetize', rule, { ], code: GROUP_ORDER_TEST, errors: [ - { message: '`author` should be before `createdAt`.' }, - { message: '`foo` should be before `id`.' }, - { message: '`bar` should be before `updatedAt`.' }, - { message: '`guild` should be before `nachos`.' }, + { message: 'field "author" should be before field "createdAt"' }, + { message: 'field "foo" should be before field "id"' }, + { message: 'field "bar" should be before field "updatedAt"' }, + { message: 'field "guild" should be before field "nachos"' }, ], }, ], diff --git a/packages/plugin/tests/input-name.spec.ts b/packages/plugin/tests/input-name.spec.ts index c64de7b04e8..7bd2285b46a 100644 --- a/packages/plugin/tests/input-name.spec.ts +++ b/packages/plugin/tests/input-name.spec.ts @@ -54,20 +54,17 @@ ruleTester.runGraphQLTests('input-name', rule, { { code: 'type Mutation { SetMessage(message: String): String }', options: [{ checkInputType: true }], - errors: [ - { message: 'Input `message` should be called `input`.' }, - { message: 'Input type `String` name should be `SetMessageInput`.' }, - ], + errors: 2, }, { code: 'type Mutation { SetMessage(input: String): String }', options: [{ checkInputType: true }], - errors: [{ message: 'Input type `String` name should be `SetMessageInput`.' }], + errors: 1, }, { code: 'type Mutation { SetMessage(hello: SetMessageInput): String }', options: [{ checkInputType: true }], - errors: [{ message: 'Input `hello` should be called `input`.' }], + errors: 1, }, { code: 'type Mutation { userCreate(record: CreateOneUserInput!): CreateOneUserPayload }', diff --git a/packages/plugin/tests/no-case-insensitive-enum-values-duplicates.spec.ts b/packages/plugin/tests/no-case-insensitive-enum-values-duplicates.spec.ts index 73cb3d39b26..31ad7a96ecf 100644 --- a/packages/plugin/tests/no-case-insensitive-enum-values-duplicates.spec.ts +++ b/packages/plugin/tests/no-case-insensitive-enum-values-duplicates.spec.ts @@ -8,15 +8,11 @@ ruleTester.runGraphQLTests('no-case-insensitive-enum-values-duplicates', rule, { invalid: [ { code: 'enum A { TEST TesT }', - errors: [ - { message: 'Case-insensitive enum values duplicates are not allowed! Found: `TesT`.' }, - ], + errors: 1, }, { code: 'extend enum A { TEST TesT }', - errors: [ - { message: 'Case-insensitive enum values duplicates are not allowed! Found: `TesT`.' }, - ], + errors: 1, }, ], }); diff --git a/packages/plugin/tests/no-hashtag-description.spec.ts b/packages/plugin/tests/no-hashtag-description.spec.ts index 7584771f4e0..a740f485084 100644 --- a/packages/plugin/tests/no-hashtag-description.spec.ts +++ b/packages/plugin/tests/no-hashtag-description.spec.ts @@ -1,5 +1,5 @@ import { GraphQLRuleTester } from '../src'; -import { rule } from '../src/rules/no-hashtag-description'; +import { rule, RULE_ID } from '../src/rules/no-hashtag-description'; const ruleTester = new GraphQLRuleTester(); @@ -103,7 +103,7 @@ ruleTester.runGraphQLTests('no-hashtag-description', rule, { foo: String } `, - errors: [{ messageId: 'HASHTAG_COMMENT' }], + errors: [{ messageId: RULE_ID }], }, { code: /* GraphQL */ ` @@ -113,7 +113,7 @@ ruleTester.runGraphQLTests('no-hashtag-description', rule, { foo: String } `, - errors: [{ messageId: 'HASHTAG_COMMENT' }], + errors: [{ messageId: RULE_ID }], }, { code: /* GraphQL */ ` @@ -122,7 +122,7 @@ ruleTester.runGraphQLTests('no-hashtag-description', rule, { foo: String } `, - errors: [{ messageId: 'HASHTAG_COMMENT' }], + errors: [{ messageId: RULE_ID }], }, { code: /* GraphQL */ ` @@ -133,7 +133,7 @@ ruleTester.runGraphQLTests('no-hashtag-description', rule, { # Good } `, - errors: [{ messageId: 'HASHTAG_COMMENT' }], + errors: [{ messageId: RULE_ID }], }, { code: /* GraphQL */ ` @@ -144,7 +144,7 @@ ruleTester.runGraphQLTests('no-hashtag-description', rule, { ): User } `, - errors: [{ messageId: 'HASHTAG_COMMENT' }], + errors: [{ messageId: RULE_ID }], }, ], }); diff --git a/packages/plugin/tests/no-scalar-result-type-on-mutation.spec.ts b/packages/plugin/tests/no-scalar-result-type-on-mutation.spec.ts index 204c9ddd5a3..bda124ed6b3 100644 --- a/packages/plugin/tests/no-scalar-result-type-on-mutation.spec.ts +++ b/packages/plugin/tests/no-scalar-result-type-on-mutation.spec.ts @@ -48,7 +48,7 @@ ruleTester.runGraphQLTests('no-scalar-result-type-on-mutation', rule, { createUser(a: ID, b: ID!, c: [ID]!, d: [ID!]!): Boolean } `), - errors: [{ message: 'Unexpected scalar result type `Boolean`.' }], + errors: 1, }, { ...useSchema(/* GraphQL */ ` @@ -58,7 +58,7 @@ ruleTester.runGraphQLTests('no-scalar-result-type-on-mutation', rule, { createUser: Boolean! } `), - errors: [{ message: 'Unexpected scalar result type `Boolean`.' }], + errors: 1, }, { ...useSchema(/* GraphQL */ ` @@ -70,7 +70,7 @@ ruleTester.runGraphQLTests('no-scalar-result-type-on-mutation', rule, { mutation: RootMutation } `), - errors: [{ message: 'Unexpected scalar result type `Boolean`.' }], + errors: 1, }, { ...useSchema(/* GraphQL */ ` @@ -83,7 +83,7 @@ ruleTester.runGraphQLTests('no-scalar-result-type-on-mutation', rule, { mutation: RootMutation } `), - errors: [{ message: 'Unexpected scalar result type `Boolean`.' }], + errors: 1, }, { ...useSchema(/* GraphQL */ ` @@ -93,10 +93,7 @@ ruleTester.runGraphQLTests('no-scalar-result-type-on-mutation', rule, { deleteUser: [Boolean!]! } `), - errors: [ - { message: 'Unexpected scalar result type `Int`.' }, - { message: 'Unexpected scalar result type `Boolean`.' }, - ], + errors: 2, }, ], }); diff --git a/packages/plugin/tests/require-deprecation-date.spec.ts b/packages/plugin/tests/require-deprecation-date.spec.ts index 21427bc0d8a..c7048257ac1 100644 --- a/packages/plugin/tests/require-deprecation-date.spec.ts +++ b/packages/plugin/tests/require-deprecation-date.spec.ts @@ -30,24 +30,24 @@ ruleTester.runGraphQLTests('require-deprecation-date', rule, { invalid: [ { code: 'scalar Old @deprecated(deletionDate: "22/08/2021")', - errors: [{ message: '"Old" сan be removed' }], + errors: 1, }, { code: 'scalar Old @deprecated(untilDate: "22/08/2021")', options: [{ argumentName: 'untilDate' }], - errors: [{ message: '"Old" сan be removed' }], + errors: 1, }, { code: 'scalar Old @deprecated(deletionDate: "bad")', - errors: [{ message: 'Deletion date must be in format "DD/MM/YYYY"' }], + errors: 1, }, { code: 'scalar Old @deprecated(deletionDate: "32/08/2021")', - errors: [{ message: 'Invalid "32/08/2021" deletion date' }], + errors: 1, }, { code: 'type Old { oldField: ID @deprecated }', - errors: [{ message: 'Directive "@deprecated" must have a deletion date' }], + errors: 1, }, ], }); diff --git a/packages/plugin/tests/require-nullable-fields-with-oneof.spec.ts b/packages/plugin/tests/require-nullable-fields-with-oneof.spec.ts index 9b009ff694a..fbc77d33774 100644 --- a/packages/plugin/tests/require-nullable-fields-with-oneof.spec.ts +++ b/packages/plugin/tests/require-nullable-fields-with-oneof.spec.ts @@ -27,10 +27,7 @@ ruleTester.runGraphQLTests('require-nullable-fields-with-oneof', rule, { bar: [Int]! } `, - errors: [ - { message: 'Field `foo` must be nullable.' }, - { message: 'Field `bar` must be nullable.' }, - ], + errors: 2, }, { name: 'should validate `type`', @@ -40,7 +37,7 @@ ruleTester.runGraphQLTests('require-nullable-fields-with-oneof', rule, { bar: Int } `, - errors: [{ message: 'Field `foo` must be nullable.' }], + errors: 1, }, ], }); diff --git a/packages/plugin/tests/require-type-pattern-with-oneof.spec.ts b/packages/plugin/tests/require-type-pattern-with-oneof.spec.ts index eccf1261a3a..8a08a7d5f16 100644 --- a/packages/plugin/tests/require-type-pattern-with-oneof.spec.ts +++ b/packages/plugin/tests/require-type-pattern-with-oneof.spec.ts @@ -39,7 +39,7 @@ ruleTester.runGraphQLTests('require-type-pattern-with-oneof', rule, { error: Error } `, - errors: [{ message: 'Type `T` should have `ok` field.' }], + errors: 1, }, { name: 'should validate `error` field', @@ -49,7 +49,7 @@ ruleTester.runGraphQLTests('require-type-pattern-with-oneof', rule, { err: Error } `, - errors: [{ message: 'Type `T` should have `error` field.' }], + errors: 1, }, ], });