@graphql-eslint/eslint-plugin 3.16.2-alpha-20230318045109-091842b → 3.16.2-alpha-20230322111953-e83f784

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rule = void 0;
4
4
  const index_js_1 = require("../estree-converter/index.js");
5
+ const utils_js_1 = require("../utils.js");
5
6
  exports.rule = {
6
7
  meta: {
7
8
  docs: {
@@ -48,10 +49,7 @@ exports.rule = {
48
49
  if (!value) {
49
50
  context.report({
50
51
  node: node.name,
51
- data: {
52
- test: 'test',
53
- },
54
- message: 'Directive "@deprecated" must have a reason!',
52
+ message: `Deprecation reason is required for ${(0, utils_js_1.getNodeName)(node.parent)}.`,
55
53
  });
56
54
  }
57
55
  },
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rule = void 0;
3
+ exports.rule = exports.RULE_ID = void 0;
4
4
  const utils_1 = require("@graphql-tools/utils");
5
5
  const graphql_1 = require("graphql");
6
6
  const utils_js_1 = require("../utils.js");
7
- const RULE_ID = 'require-description';
7
+ exports.RULE_ID = 'require-description';
8
8
  const ALLOWED_KINDS = [
9
9
  ...utils_js_1.TYPES_KINDS,
10
10
  graphql_1.Kind.DIRECTIVE_DEFINITION,
@@ -13,34 +13,6 @@ const ALLOWED_KINDS = [
13
13
  graphql_1.Kind.ENUM_VALUE_DEFINITION,
14
14
  graphql_1.Kind.OPERATION_DEFINITION,
15
15
  ];
16
- function getNodeName(node) {
17
- const DisplayNodeNameMap = {
18
- [graphql_1.Kind.OBJECT_TYPE_DEFINITION]: 'type',
19
- [graphql_1.Kind.INTERFACE_TYPE_DEFINITION]: 'interface',
20
- [graphql_1.Kind.ENUM_TYPE_DEFINITION]: 'enum',
21
- [graphql_1.Kind.SCALAR_TYPE_DEFINITION]: 'scalar',
22
- [graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION]: 'input',
23
- [graphql_1.Kind.UNION_TYPE_DEFINITION]: 'union',
24
- [graphql_1.Kind.DIRECTIVE_DEFINITION]: 'directive',
25
- };
26
- switch (node.kind) {
27
- case graphql_1.Kind.OBJECT_TYPE_DEFINITION:
28
- case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
29
- case graphql_1.Kind.ENUM_TYPE_DEFINITION:
30
- case graphql_1.Kind.SCALAR_TYPE_DEFINITION:
31
- case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION:
32
- case graphql_1.Kind.UNION_TYPE_DEFINITION:
33
- return `${DisplayNodeNameMap[node.kind]} ${node.name.value}`;
34
- case graphql_1.Kind.DIRECTIVE_DEFINITION:
35
- return `${DisplayNodeNameMap[node.kind]} @${node.name.value}`;
36
- case graphql_1.Kind.FIELD_DEFINITION:
37
- case graphql_1.Kind.INPUT_VALUE_DEFINITION:
38
- case graphql_1.Kind.ENUM_VALUE_DEFINITION:
39
- return `${node.parent.name.value}.${node.name.value}`;
40
- case graphql_1.Kind.OPERATION_DEFINITION:
41
- return node.name ? `${node.operation} ${node.name.value}` : node.operation;
42
- }
43
- }
44
16
  const schema = {
45
17
  type: 'array',
46
18
  minItems: 1,
@@ -74,7 +46,7 @@ exports.rule = {
74
46
  docs: {
75
47
  category: 'Schema',
76
48
  description: 'Enforce descriptions in type definitions and operations.',
77
- url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
49
+ url: `https://the-guild.dev/graphql/eslint/rules/${exports.RULE_ID}`,
78
50
  examples: [
79
51
  {
80
52
  title: 'Incorrect',
@@ -136,7 +108,7 @@ exports.rule = {
136
108
  },
137
109
  type: 'suggestion',
138
110
  messages: {
139
- [RULE_ID]: 'Description is required for `{{ nodeName }}`.',
111
+ [exports.RULE_ID]: 'Description is required for {{ nodeName }}',
140
112
  },
141
113
  schema,
142
114
  },
@@ -152,7 +124,7 @@ exports.rule = {
152
124
  }
153
125
  }
154
126
  if (rootField) {
155
- const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
127
+ const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(exports.RULE_ID, context);
156
128
  const rootTypeNames = (0, utils_1.getRootTypeNames)(schema);
157
129
  kinds.add(`:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/^(${[
158
130
  ...rootTypeNames,
@@ -182,9 +154,9 @@ exports.rule = {
182
154
  if (description.length === 0) {
183
155
  context.report({
184
156
  loc: isOperation ? (0, utils_js_1.getLocation)(node.loc.start, node.operation) : node.name.loc,
185
- messageId: RULE_ID,
157
+ messageId: exports.RULE_ID,
186
158
  data: {
187
- nodeName: getNodeName(node),
159
+ nodeName: (0, utils_js_1.getNodeName)(node),
188
160
  },
189
161
  });
190
162
  }
package/cjs/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.truthy = exports.englishJoinWords = exports.ARRAY_DEFAULT_OPTIONS = exports.REPORT_ON_FIRST_CHARACTER = exports.getLocation = exports.convertCase = exports.camelCase = exports.pascalCase = exports.TYPES_KINDS = exports.getTypeName = exports.IS_BROWSER = exports.CWD = exports.VIRTUAL_DOCUMENT_REGEX = exports.normalizePath = exports.logger = exports.requireGraphQLSchemaFromContext = exports.requireSiblingsOperations = void 0;
3
+ exports.getNodeName = exports.truthy = exports.englishJoinWords = exports.ARRAY_DEFAULT_OPTIONS = exports.REPORT_ON_FIRST_CHARACTER = exports.getLocation = exports.convertCase = exports.camelCase = exports.pascalCase = exports.TYPES_KINDS = exports.getTypeName = exports.IS_BROWSER = exports.CWD = exports.VIRTUAL_DOCUMENT_REGEX = exports.normalizePath = exports.logger = exports.requireGraphQLSchemaFromContext = exports.requireSiblingsOperations = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
6
  const graphql_1 = require("graphql");
@@ -98,3 +98,34 @@ function truthy(value) {
98
98
  return !!value;
99
99
  }
100
100
  exports.truthy = truthy;
101
+ function getNodeName(node) {
102
+ const DisplayNodeNameMap = {
103
+ [graphql_1.Kind.OBJECT_TYPE_DEFINITION]: 'type',
104
+ [graphql_1.Kind.INTERFACE_TYPE_DEFINITION]: 'interface',
105
+ [graphql_1.Kind.ENUM_TYPE_DEFINITION]: 'enum',
106
+ [graphql_1.Kind.SCALAR_TYPE_DEFINITION]: 'scalar',
107
+ [graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION]: 'input',
108
+ [graphql_1.Kind.UNION_TYPE_DEFINITION]: 'union',
109
+ [graphql_1.Kind.DIRECTIVE_DEFINITION]: 'directive',
110
+ [graphql_1.Kind.FIELD_DEFINITION]: 'field',
111
+ [graphql_1.Kind.ENUM_VALUE_DEFINITION]: 'value',
112
+ [graphql_1.Kind.INPUT_VALUE_DEFINITION]: 'value',
113
+ };
114
+ switch (node.kind) {
115
+ case graphql_1.Kind.OBJECT_TYPE_DEFINITION:
116
+ case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
117
+ case graphql_1.Kind.ENUM_TYPE_DEFINITION:
118
+ case graphql_1.Kind.SCALAR_TYPE_DEFINITION:
119
+ case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION:
120
+ case graphql_1.Kind.UNION_TYPE_DEFINITION:
121
+ case graphql_1.Kind.DIRECTIVE_DEFINITION:
122
+ return `${DisplayNodeNameMap[node.kind]} "${node.name.value}"`;
123
+ case graphql_1.Kind.FIELD_DEFINITION:
124
+ case graphql_1.Kind.INPUT_VALUE_DEFINITION:
125
+ case graphql_1.Kind.ENUM_VALUE_DEFINITION:
126
+ return `${DisplayNodeNameMap[node.kind]} "${node.name.value}" in ${DisplayNodeNameMap[node.parent.kind]} "${node.parent.name.value}"`;
127
+ case graphql_1.Kind.OPERATION_DEFINITION:
128
+ return node.name ? `${node.operation} "${node.name.value}"` : node.operation;
129
+ }
130
+ }
131
+ exports.getNodeName = getNodeName;
@@ -1,4 +1,5 @@
1
1
  import { valueFromNode } from '../estree-converter/index.js';
2
+ import { getNodeName } from '../utils.js';
2
3
  export const rule = {
3
4
  meta: {
4
5
  docs: {
@@ -45,10 +46,7 @@ export const rule = {
45
46
  if (!value) {
46
47
  context.report({
47
48
  node: node.name,
48
- data: {
49
- test: 'test',
50
- },
51
- message: 'Directive "@deprecated" must have a reason!',
49
+ message: `Deprecation reason is required for ${getNodeName(node.parent)}.`,
52
50
  });
53
51
  }
54
52
  },
@@ -1,7 +1,7 @@
1
1
  import { getRootTypeNames } from '@graphql-tools/utils';
2
2
  import { Kind, TokenKind } from 'graphql';
3
- import { getLocation, requireGraphQLSchemaFromContext, TYPES_KINDS } from '../utils.js';
4
- const RULE_ID = 'require-description';
3
+ import { getLocation, getNodeName, requireGraphQLSchemaFromContext, TYPES_KINDS, } from '../utils.js';
4
+ export const RULE_ID = 'require-description';
5
5
  const ALLOWED_KINDS = [
6
6
  ...TYPES_KINDS,
7
7
  Kind.DIRECTIVE_DEFINITION,
@@ -10,34 +10,6 @@ const ALLOWED_KINDS = [
10
10
  Kind.ENUM_VALUE_DEFINITION,
11
11
  Kind.OPERATION_DEFINITION,
12
12
  ];
13
- function getNodeName(node) {
14
- const DisplayNodeNameMap = {
15
- [Kind.OBJECT_TYPE_DEFINITION]: 'type',
16
- [Kind.INTERFACE_TYPE_DEFINITION]: 'interface',
17
- [Kind.ENUM_TYPE_DEFINITION]: 'enum',
18
- [Kind.SCALAR_TYPE_DEFINITION]: 'scalar',
19
- [Kind.INPUT_OBJECT_TYPE_DEFINITION]: 'input',
20
- [Kind.UNION_TYPE_DEFINITION]: 'union',
21
- [Kind.DIRECTIVE_DEFINITION]: 'directive',
22
- };
23
- switch (node.kind) {
24
- case Kind.OBJECT_TYPE_DEFINITION:
25
- case Kind.INTERFACE_TYPE_DEFINITION:
26
- case Kind.ENUM_TYPE_DEFINITION:
27
- case Kind.SCALAR_TYPE_DEFINITION:
28
- case Kind.INPUT_OBJECT_TYPE_DEFINITION:
29
- case Kind.UNION_TYPE_DEFINITION:
30
- return `${DisplayNodeNameMap[node.kind]} ${node.name.value}`;
31
- case Kind.DIRECTIVE_DEFINITION:
32
- return `${DisplayNodeNameMap[node.kind]} @${node.name.value}`;
33
- case Kind.FIELD_DEFINITION:
34
- case Kind.INPUT_VALUE_DEFINITION:
35
- case Kind.ENUM_VALUE_DEFINITION:
36
- return `${node.parent.name.value}.${node.name.value}`;
37
- case Kind.OPERATION_DEFINITION:
38
- return node.name ? `${node.operation} ${node.name.value}` : node.operation;
39
- }
40
- }
41
13
  const schema = {
42
14
  type: 'array',
43
15
  minItems: 1,
@@ -133,7 +105,7 @@ export const rule = {
133
105
  },
134
106
  type: 'suggestion',
135
107
  messages: {
136
- [RULE_ID]: 'Description is required for `{{ nodeName }}`.',
108
+ [RULE_ID]: 'Description is required for {{ nodeName }}',
137
109
  },
138
110
  schema,
139
111
  },
package/esm/utils.js CHANGED
@@ -84,3 +84,33 @@ export const englishJoinWords = (words) => new Intl.ListFormat('en-US', { type:
84
84
  export function truthy(value) {
85
85
  return !!value;
86
86
  }
87
+ export function getNodeName(node) {
88
+ const DisplayNodeNameMap = {
89
+ [Kind.OBJECT_TYPE_DEFINITION]: 'type',
90
+ [Kind.INTERFACE_TYPE_DEFINITION]: 'interface',
91
+ [Kind.ENUM_TYPE_DEFINITION]: 'enum',
92
+ [Kind.SCALAR_TYPE_DEFINITION]: 'scalar',
93
+ [Kind.INPUT_OBJECT_TYPE_DEFINITION]: 'input',
94
+ [Kind.UNION_TYPE_DEFINITION]: 'union',
95
+ [Kind.DIRECTIVE_DEFINITION]: 'directive',
96
+ [Kind.FIELD_DEFINITION]: 'field',
97
+ [Kind.ENUM_VALUE_DEFINITION]: 'value',
98
+ [Kind.INPUT_VALUE_DEFINITION]: 'value',
99
+ };
100
+ switch (node.kind) {
101
+ case Kind.OBJECT_TYPE_DEFINITION:
102
+ case Kind.INTERFACE_TYPE_DEFINITION:
103
+ case Kind.ENUM_TYPE_DEFINITION:
104
+ case Kind.SCALAR_TYPE_DEFINITION:
105
+ case Kind.INPUT_OBJECT_TYPE_DEFINITION:
106
+ case Kind.UNION_TYPE_DEFINITION:
107
+ case Kind.DIRECTIVE_DEFINITION:
108
+ return `${DisplayNodeNameMap[node.kind]} "${node.name.value}"`;
109
+ case Kind.FIELD_DEFINITION:
110
+ case Kind.INPUT_VALUE_DEFINITION:
111
+ case Kind.ENUM_VALUE_DEFINITION:
112
+ return `${DisplayNodeNameMap[node.kind]} "${node.name.value}" in ${DisplayNodeNameMap[node.parent.kind]} "${node.parent.name.value}"`;
113
+ case Kind.OPERATION_DEFINITION:
114
+ return node.name ? `${node.operation} "${node.name.value}"` : node.operation;
115
+ }
116
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "3.16.2-alpha-20230318045109-091842b",
3
+ "version": "3.16.2-alpha-20230322111953-e83f784",
4
4
  "description": "GraphQL plugin for ESLint",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -1,5 +1,6 @@
1
1
  import { Kind } from 'graphql';
2
2
  import { GraphQLESLintRule } from '../types.cjs';
3
+ export declare const RULE_ID = "require-description";
3
4
  declare const ALLOWED_KINDS: readonly [Kind.OBJECT_TYPE_DEFINITION, Kind.INTERFACE_TYPE_DEFINITION, Kind.ENUM_TYPE_DEFINITION, Kind.SCALAR_TYPE_DEFINITION, Kind.INPUT_OBJECT_TYPE_DEFINITION, Kind.UNION_TYPE_DEFINITION, Kind.DIRECTIVE_DEFINITION, Kind.FIELD_DEFINITION, Kind.INPUT_VALUE_DEFINITION, Kind.ENUM_VALUE_DEFINITION, Kind.OPERATION_DEFINITION];
4
5
  type AllowedKind = (typeof ALLOWED_KINDS)[number];
5
6
  export type RuleOptions = [
@@ -1,5 +1,6 @@
1
1
  import { Kind } from 'graphql';
2
2
  import { GraphQLESLintRule } from '../types.js';
3
+ export declare const RULE_ID = "require-description";
3
4
  declare const ALLOWED_KINDS: readonly [Kind.OBJECT_TYPE_DEFINITION, Kind.INTERFACE_TYPE_DEFINITION, Kind.ENUM_TYPE_DEFINITION, Kind.SCALAR_TYPE_DEFINITION, Kind.INPUT_OBJECT_TYPE_DEFINITION, Kind.UNION_TYPE_DEFINITION, Kind.DIRECTIVE_DEFINITION, Kind.FIELD_DEFINITION, Kind.INPUT_VALUE_DEFINITION, Kind.ENUM_VALUE_DEFINITION, Kind.OPERATION_DEFINITION];
4
5
  type AllowedKind = (typeof ALLOWED_KINDS)[number];
5
6
  export type RuleOptions = [
@@ -35,4 +35,5 @@ export declare const ARRAY_DEFAULT_OPTIONS: {
35
35
  export declare const englishJoinWords: (words: string[]) => string;
36
36
  type Truthy<T> = T extends '' | 0 | false | null | undefined ? never : T;
37
37
  export declare function truthy<T>(value: T): value is Truthy<T>;
38
+ export declare function getNodeName(node: any): any;
38
39
  export {};
@@ -35,4 +35,5 @@ export declare const ARRAY_DEFAULT_OPTIONS: {
35
35
  export declare const englishJoinWords: (words: string[]) => string;
36
36
  type Truthy<T> = T extends '' | 0 | false | null | undefined ? never : T;
37
37
  export declare function truthy<T>(value: T): value is Truthy<T>;
38
+ export declare function getNodeName(node: any): any;
38
39
  export {};