@graphql-eslint/eslint-plugin 3.20.1 → 4.0.0-alpha-20230801163310-8bc4340
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/flat-configs.d.ts +1 -1
- package/cjs/graphql-config.d.ts +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +0 -2
- package/cjs/parser.d.ts +1 -1
- package/cjs/rules/alphabetize.d.ts +1 -1
- package/cjs/rules/description-style.d.ts +1 -1
- package/cjs/rules/graphql-js-validation.d.ts +1 -1
- package/cjs/rules/index.d.ts +1 -1
- package/cjs/rules/input-name.d.ts +1 -1
- package/cjs/rules/lone-executable-definition.d.ts +1 -1
- package/cjs/rules/match-document-filename.d.ts +1 -1
- package/cjs/rules/naming-convention.d.ts +1 -1
- package/cjs/rules/no-anonymous-operations.d.ts +1 -1
- package/cjs/rules/no-case-insensitive-enum-values-duplicates.d.ts +1 -1
- package/cjs/rules/no-deprecated.d.ts +1 -1
- package/cjs/rules/no-duplicate-fields.d.ts +1 -1
- package/cjs/rules/no-hashtag-description.d.ts +1 -1
- package/cjs/rules/no-one-place-fragments.d.ts +1 -1
- package/cjs/rules/no-root-type.d.ts +1 -1
- package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +1 -1
- package/cjs/rules/no-typename-prefix.d.ts +1 -1
- package/cjs/rules/no-unreachable-types.d.ts +1 -1
- package/cjs/rules/no-unused-fields.d.ts +1 -1
- package/cjs/rules/relay-arguments.d.ts +1 -1
- package/cjs/rules/relay-connection-types.d.ts +1 -1
- package/cjs/rules/relay-edge-types.d.ts +1 -1
- package/cjs/rules/relay-page-info.d.ts +1 -1
- package/cjs/rules/require-deprecation-date.d.ts +1 -1
- package/cjs/rules/require-deprecation-reason.d.ts +1 -1
- package/cjs/rules/require-description.d.ts +1 -1
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +1 -1
- package/cjs/rules/require-id-when-available.d.ts +1 -1
- package/cjs/rules/require-import-fragment.d.ts +1 -1
- package/cjs/rules/require-nullable-fields-with-oneof.d.ts +1 -1
- package/cjs/rules/require-nullable-result-in-root.d.ts +1 -1
- package/cjs/rules/require-type-pattern-with-oneof.d.ts +1 -1
- package/cjs/rules/selection-set-depth.d.ts +1 -1
- package/cjs/rules/strict-id-in-types.d.ts +1 -1
- package/cjs/rules/unique-fragment-name.d.ts +1 -1
- package/cjs/rules/unique-operation-name.d.ts +1 -1
- package/cjs/schema.d.ts +1 -1
- package/cjs/siblings.d.ts +1 -1
- package/cjs/{types-e3367e3c.d.ts → types-8d5f4ae0.d.ts} +6 -28
- package/cjs/types.d.ts +1 -1
- package/cjs/utils.d.ts +1 -1
- package/esm/flat-configs.d.mts +1 -1
- package/esm/graphql-config.d.mts +1 -1
- package/esm/index.d.mts +1 -1
- package/esm/index.js +0 -1
- package/esm/parser.d.mts +1 -1
- package/esm/rules/alphabetize.d.mts +1 -1
- package/esm/rules/description-style.d.mts +1 -1
- package/esm/rules/graphql-js-validation.d.mts +1 -1
- package/esm/rules/index.d.mts +1 -1
- package/esm/rules/input-name.d.mts +1 -1
- package/esm/rules/lone-executable-definition.d.mts +1 -1
- package/esm/rules/match-document-filename.d.mts +1 -1
- package/esm/rules/naming-convention.d.mts +1 -1
- package/esm/rules/no-anonymous-operations.d.mts +1 -1
- package/esm/rules/no-case-insensitive-enum-values-duplicates.d.mts +1 -1
- package/esm/rules/no-deprecated.d.mts +1 -1
- package/esm/rules/no-duplicate-fields.d.mts +1 -1
- package/esm/rules/no-hashtag-description.d.mts +1 -1
- package/esm/rules/no-one-place-fragments.d.mts +1 -1
- package/esm/rules/no-root-type.d.mts +1 -1
- package/esm/rules/no-scalar-result-type-on-mutation.d.mts +1 -1
- package/esm/rules/no-typename-prefix.d.mts +1 -1
- package/esm/rules/no-unreachable-types.d.mts +1 -1
- package/esm/rules/no-unused-fields.d.mts +1 -1
- package/esm/rules/relay-arguments.d.mts +1 -1
- package/esm/rules/relay-connection-types.d.mts +1 -1
- package/esm/rules/relay-edge-types.d.mts +1 -1
- package/esm/rules/relay-page-info.d.mts +1 -1
- package/esm/rules/require-deprecation-date.d.mts +1 -1
- package/esm/rules/require-deprecation-reason.d.mts +1 -1
- package/esm/rules/require-description.d.mts +1 -1
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +1 -1
- package/esm/rules/require-id-when-available.d.mts +1 -1
- package/esm/rules/require-import-fragment.d.mts +1 -1
- package/esm/rules/require-nullable-fields-with-oneof.d.mts +1 -1
- package/esm/rules/require-nullable-result-in-root.d.mts +1 -1
- package/esm/rules/require-type-pattern-with-oneof.d.mts +1 -1
- package/esm/rules/selection-set-depth.d.mts +1 -1
- package/esm/rules/strict-id-in-types.d.mts +1 -1
- package/esm/rules/unique-fragment-name.d.mts +1 -1
- package/esm/rules/unique-operation-name.d.mts +1 -1
- package/esm/schema.d.mts +1 -1
- package/esm/siblings.d.mts +1 -1
- package/esm/{types-2e1afd7c.d.ts → types-ace77d86.d.ts} +6 -28
- package/esm/types.d.mts +1 -1
- package/esm/utils.d.mts +1 -1
- package/package.json +1 -2
- package/cjs/testkit.d.ts +0 -8
- package/cjs/testkit.js +0 -183
- package/esm/testkit.d.mts +0 -8
- package/esm/testkit.js +0 -152
@@ -1,6 +1,6 @@
|
|
1
1
|
import { ExecutableDefinitionNode } from 'graphql';
|
2
2
|
import { GraphQLESTreeNode } from '../estree-converter/types.mjs';
|
3
|
-
import {
|
3
|
+
import { c as GraphQLESLintRuleContext, f as GraphQLESLintRule } from '../types-ace77d86.js';
|
4
4
|
import 'eslint';
|
5
5
|
import 'estree';
|
6
6
|
import '@graphql-tools/utils';
|
package/esm/schema.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { GraphQLProjectConfig } from 'graphql-config';
|
2
|
-
import { P as ParserOptions, S as Schema } from './types-
|
2
|
+
import { P as ParserOptions, S as Schema } from './types-ace77d86.js';
|
3
3
|
import '@graphql-tools/utils';
|
4
4
|
import 'eslint';
|
5
5
|
import 'estree';
|
package/esm/siblings.d.mts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import 'graphql';
|
2
2
|
import 'graphql-config';
|
3
|
-
export { F as FragmentSource,
|
3
|
+
export { F as FragmentSource, h as OperationSource, g as SiblingOperations, i as getSiblings } from './types-ace77d86.js';
|
4
4
|
import '@graphql-tools/utils';
|
5
5
|
import 'eslint';
|
6
6
|
import 'estree';
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { GraphQLParseOptions } from '@graphql-tools/utils';
|
2
|
-
import {
|
2
|
+
import { Linter, Rule, AST } from 'eslint';
|
3
3
|
import * as ESTree from 'estree';
|
4
|
-
import { FragmentDefinitionNode, OperationDefinitionNode, SelectionSetNode, OperationTypeNode,
|
4
|
+
import { FragmentDefinitionNode, OperationDefinitionNode, SelectionSetNode, OperationTypeNode, GraphQLSchema, ASTKindToNode } from 'graphql';
|
5
5
|
import { GraphQLProjectConfig, IExtensions, IGraphQLProject } from 'graphql-config';
|
6
6
|
import { JSONSchema } from 'json-schema-to-ts';
|
7
7
|
import { GraphQLESTreeNode } from './estree-converter/types.mjs';
|
@@ -26,31 +26,6 @@ type SiblingOperations = {
|
|
26
26
|
};
|
27
27
|
declare function getSiblings(project?: GraphQLProjectConfig, documents?: ParserOptions['documents']): SiblingOperations;
|
28
28
|
|
29
|
-
type GraphQLESLintRuleListener<WithTypeInfo extends boolean = false> = Record<string, any> & {
|
30
|
-
[K in keyof ASTKindToNode]?: (node: GraphQLESTreeNode<ASTKindToNode[K], WithTypeInfo>) => void;
|
31
|
-
};
|
32
|
-
type GraphQLValidTestCase<Options = []> = Omit<RuleTester.ValidTestCase, 'options' | 'parserOptions'> & {
|
33
|
-
options?: Options;
|
34
|
-
parserOptions?: Omit<ParserOptions, 'filePath'>;
|
35
|
-
};
|
36
|
-
type GraphQLInvalidTestCase<T = []> = GraphQLValidTestCase<T> & {
|
37
|
-
errors: (RuleTester.TestCaseError | string)[] | number;
|
38
|
-
output?: string | null;
|
39
|
-
};
|
40
|
-
type RuleTesterConfig = {
|
41
|
-
parser: string;
|
42
|
-
parserOptions: Omit<ParserOptions, 'filePath'>;
|
43
|
-
};
|
44
|
-
declare class GraphQLRuleTester extends RuleTester {
|
45
|
-
config: RuleTesterConfig;
|
46
|
-
constructor(parserOptions?: Omit<ParserOptions, 'filePath'>);
|
47
|
-
fromMockFile(path: string): string;
|
48
|
-
runGraphQLTests<Options, WithTypeInfo extends boolean = false>(ruleId: string, rule: GraphQLESLintRule<Options, WithTypeInfo>, tests: {
|
49
|
-
valid: (GraphQLValidTestCase<Options> | string)[];
|
50
|
-
invalid: GraphQLInvalidTestCase<Options>[];
|
51
|
-
}): void;
|
52
|
-
}
|
53
|
-
|
54
29
|
type Schema = GraphQLSchema | null;
|
55
30
|
type Pointer = string | string[];
|
56
31
|
interface ParserOptions {
|
@@ -110,6 +85,9 @@ type RuleDocsInfo<T> = Omit<RuleMetaDataDocs, 'category' | 'suggestion'> & {
|
|
110
85
|
graphQLJSRuleName?: string;
|
111
86
|
isDisabledForAllConfig?: true;
|
112
87
|
};
|
88
|
+
type GraphQLESLintRuleListener<WithTypeInfo extends boolean = false> = Record<string, any> & {
|
89
|
+
[K in keyof ASTKindToNode]?: (node: GraphQLESTreeNode<ASTKindToNode[K], WithTypeInfo>) => void;
|
90
|
+
};
|
113
91
|
type GraphQLESLintRule<Options = [], WithTypeInfo extends boolean = false> = {
|
114
92
|
meta: Omit<Rule.RuleMetaData, 'docs' | 'schema'> & {
|
115
93
|
docs?: RuleDocsInfo<Options>;
|
@@ -126,4 +104,4 @@ type OmitRecursively<T extends object, K extends PropertyKey> = Omit<{
|
|
126
104
|
[P in keyof T]: OmitDistributive<T[P], K>;
|
127
105
|
}, K>;
|
128
106
|
|
129
|
-
export { CategoryType as C, FragmentSource as F,
|
107
|
+
export { CategoryType as C, FragmentSource as F, GraphQLESLintParseResult as G, OmitRecursively as O, ParserOptions as P, ReportDescriptor as R, Schema as S, ValueOf as V, Pointer as a, ParserServices as b, GraphQLESLintRuleContext as c, RuleDocsInfo as d, GraphQLESLintRuleListener as e, GraphQLESLintRule as f, SiblingOperations as g, OperationSource as h, getSiblings as i };
|
package/esm/types.d.mts
CHANGED
@@ -4,5 +4,5 @@ import 'estree';
|
|
4
4
|
import 'graphql';
|
5
5
|
import 'graphql-config';
|
6
6
|
import 'json-schema-to-ts';
|
7
|
-
export { C as CategoryType,
|
7
|
+
export { C as CategoryType, G as GraphQLESLintParseResult, f as GraphQLESLintRule, c as GraphQLESLintRuleContext, e as GraphQLESLintRuleListener, O as OmitRecursively, P as ParserOptions, b as ParserServices, a as Pointer, R as ReportDescriptor, d as RuleDocsInfo, S as Schema, V as ValueOf } from './types-ace77d86.js';
|
8
8
|
import './estree-converter/types.mjs';
|
package/esm/utils.d.mts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { AST } from 'eslint';
|
2
2
|
import { Position } from 'estree';
|
3
3
|
import { GraphQLSchema, ASTNode, Kind } from 'graphql';
|
4
|
-
import {
|
4
|
+
import { c as GraphQLESLintRuleContext, g as SiblingOperations } from './types-ace77d86.js';
|
5
5
|
import { GraphQLESTreeNode } from './estree-converter/types.mjs';
|
6
6
|
import '@graphql-tools/utils';
|
7
7
|
import 'graphql-config';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@graphql-eslint/eslint-plugin",
|
3
|
-
"version": "
|
3
|
+
"version": "4.0.0-alpha-20230801163310-8bc4340",
|
4
4
|
"description": "GraphQL plugin for ESLint",
|
5
5
|
"repository": "https://github.com/B2o5T/graphql-eslint",
|
6
6
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
@@ -38,7 +38,6 @@
|
|
38
38
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
39
39
|
},
|
40
40
|
"dependencies": {
|
41
|
-
"@babel/code-frame": "^7.18.6",
|
42
41
|
"@graphql-tools/code-file-loader": "^7.3.6",
|
43
42
|
"@graphql-tools/graphql-tag-pluck": "^7.3.6",
|
44
43
|
"@graphql-tools/utils": "^9.0.0",
|
package/cjs/testkit.d.ts
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
import 'eslint';
|
2
|
-
import 'graphql';
|
3
|
-
import './estree-converter/types.js';
|
4
|
-
export { G as GraphQLESLintRuleListener, b as GraphQLInvalidTestCase, c as GraphQLRuleTester, a as GraphQLValidTestCase } from './types-e3367e3c.js';
|
5
|
-
import 'estree';
|
6
|
-
import '@graphql-tools/utils';
|
7
|
-
import 'graphql-config';
|
8
|
-
import 'json-schema-to-ts';
|
package/cjs/testkit.js
DELETED
@@ -1,183 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
var testkit_exports = {};
|
30
|
-
__export(testkit_exports, {
|
31
|
-
GraphQLRuleTester: () => GraphQLRuleTester
|
32
|
-
});
|
33
|
-
module.exports = __toCommonJS(testkit_exports);
|
34
|
-
var import_fs = require("fs");
|
35
|
-
var import_path = require("path");
|
36
|
-
var import_code_frame = require("@babel/code-frame");
|
37
|
-
var import_eslint = require("eslint");
|
38
|
-
function indentCode(code, indent = 4) {
|
39
|
-
return code.replace(/^/gm, " ".repeat(indent));
|
40
|
-
}
|
41
|
-
function applyFix(code, { range, text }) {
|
42
|
-
return [code.slice(0, range[0]), text, code.slice(range[1])].join("");
|
43
|
-
}
|
44
|
-
class GraphQLRuleTester extends import_eslint.RuleTester {
|
45
|
-
constructor(parserOptions = {}) {
|
46
|
-
const config = {
|
47
|
-
parser: require.resolve("@graphql-eslint/eslint-plugin"),
|
48
|
-
parserOptions: {
|
49
|
-
...parserOptions,
|
50
|
-
skipGraphQLConfig: true
|
51
|
-
}
|
52
|
-
};
|
53
|
-
super(config);
|
54
|
-
this.config = config;
|
55
|
-
}
|
56
|
-
fromMockFile(path) {
|
57
|
-
return (0, import_fs.readFileSync)((0, import_path.resolve)(__dirname, `../tests/mocks/${path}`), "utf-8");
|
58
|
-
}
|
59
|
-
runGraphQLTests(ruleId, rule, tests) {
|
60
|
-
super.run(ruleId, rule, tests);
|
61
|
-
const linter = new import_eslint.Linter();
|
62
|
-
linter.defineRule(ruleId, rule);
|
63
|
-
const hasOnlyTest = [...tests.valid, ...tests.invalid].some(
|
64
|
-
(t) => typeof t !== "string" && t.only
|
65
|
-
);
|
66
|
-
for (const [idx, testCase] of tests.invalid.entries()) {
|
67
|
-
const { only, filename, options, name } = testCase;
|
68
|
-
if (hasOnlyTest && !only) {
|
69
|
-
continue;
|
70
|
-
}
|
71
|
-
const code = removeTrailingBlankLines(testCase.code);
|
72
|
-
const verifyConfig = getVerifyConfig(ruleId, this.config, testCase);
|
73
|
-
defineParser(linter, verifyConfig.parser);
|
74
|
-
const messages = linter.verify(code, verifyConfig, filename);
|
75
|
-
if (messages.length === 0) {
|
76
|
-
throw new Error("Invalid case should have at least one error.");
|
77
|
-
}
|
78
|
-
const codeFrame = indentCode(printCode(code, { line: 0, column: 0 }));
|
79
|
-
const messageForSnapshot = ["#### \u2328\uFE0F Code", codeFrame];
|
80
|
-
if (options) {
|
81
|
-
const opts = JSON.stringify(options, null, 2).slice(1, -1);
|
82
|
-
messageForSnapshot.push("#### \u2699\uFE0F Options", indentCode(removeTrailingBlankLines(opts), 2));
|
83
|
-
}
|
84
|
-
for (const [index, message] of messages.entries()) {
|
85
|
-
if (message.fatal) {
|
86
|
-
throw new Error(message.message);
|
87
|
-
}
|
88
|
-
const codeWithMessage = printCode(code, message, 1);
|
89
|
-
messageForSnapshot.push(
|
90
|
-
printWithIndex("#### \u274C Error", index, messages.length),
|
91
|
-
indentCode(codeWithMessage)
|
92
|
-
);
|
93
|
-
if (message.suggestions && (code.match(/\n/g) || "").length < 1e3) {
|
94
|
-
for (const [i, suggestion] of message.suggestions.entries()) {
|
95
|
-
const title = printWithIndex(
|
96
|
-
"#### \u{1F4A1} Suggestion",
|
97
|
-
i,
|
98
|
-
message.suggestions.length,
|
99
|
-
suggestion.desc
|
100
|
-
);
|
101
|
-
const output = applyFix(code, suggestion.fix);
|
102
|
-
const codeFrame2 = printCode(output, { line: 0, column: 0 });
|
103
|
-
messageForSnapshot.push(title, indentCode(codeFrame2, 2));
|
104
|
-
}
|
105
|
-
}
|
106
|
-
}
|
107
|
-
if (rule.meta.fixable) {
|
108
|
-
const { fixed, output } = linter.verifyAndFix(code, verifyConfig, filename);
|
109
|
-
if (fixed) {
|
110
|
-
messageForSnapshot.push("#### \u{1F527} Autofix output", indentCode(printCode(output)));
|
111
|
-
}
|
112
|
-
}
|
113
|
-
it(name || `Invalid #${idx + 1}`, () => {
|
114
|
-
expect(messageForSnapshot.join("\n\n")).toMatchSnapshot();
|
115
|
-
});
|
116
|
-
}
|
117
|
-
}
|
118
|
-
}
|
119
|
-
function removeTrailingBlankLines(text) {
|
120
|
-
return text.replace(/^\s*\n/, "").trimEnd();
|
121
|
-
}
|
122
|
-
function printWithIndex(title, index, total, description) {
|
123
|
-
if (total > 1) {
|
124
|
-
title += ` ${index + 1}/${total}`;
|
125
|
-
}
|
126
|
-
if (description) {
|
127
|
-
title += `: ${description}`;
|
128
|
-
}
|
129
|
-
return title;
|
130
|
-
}
|
131
|
-
function getVerifyConfig(ruleId, testerConfig, testCase) {
|
132
|
-
const { parser = testerConfig.parser, parserOptions, options } = testCase;
|
133
|
-
return {
|
134
|
-
...testerConfig,
|
135
|
-
parser,
|
136
|
-
parserOptions: {
|
137
|
-
...testerConfig.parserOptions,
|
138
|
-
...parserOptions
|
139
|
-
},
|
140
|
-
rules: {
|
141
|
-
[ruleId]: Array.isArray(options) ? ["error", ...options] : "error"
|
142
|
-
}
|
143
|
-
};
|
144
|
-
}
|
145
|
-
const parsers = /* @__PURE__ */ new WeakMap();
|
146
|
-
function defineParser(linter, parser) {
|
147
|
-
if (!parser) {
|
148
|
-
return;
|
149
|
-
}
|
150
|
-
if (!parsers.has(linter)) {
|
151
|
-
parsers.set(linter, /* @__PURE__ */ new Set());
|
152
|
-
}
|
153
|
-
const defined = parsers.get(linter);
|
154
|
-
if (!defined.has(parser)) {
|
155
|
-
defined.add(parser);
|
156
|
-
linter.defineParser(parser, require(parser));
|
157
|
-
}
|
158
|
-
}
|
159
|
-
function printCode(code, result = {}, linesOffset = Number.POSITIVE_INFINITY) {
|
160
|
-
const { line, column, endLine, endColumn, message } = result;
|
161
|
-
const location = {};
|
162
|
-
if (typeof line === "number" && typeof column === "number") {
|
163
|
-
location.start = {
|
164
|
-
line,
|
165
|
-
column
|
166
|
-
};
|
167
|
-
}
|
168
|
-
if (typeof endLine === "number" && typeof endColumn === "number") {
|
169
|
-
location.end = {
|
170
|
-
line: endLine,
|
171
|
-
column: endColumn
|
172
|
-
};
|
173
|
-
}
|
174
|
-
return (0, import_code_frame.codeFrameColumns)(code, location, {
|
175
|
-
linesAbove: linesOffset,
|
176
|
-
linesBelow: linesOffset,
|
177
|
-
message
|
178
|
-
});
|
179
|
-
}
|
180
|
-
// Annotate the CommonJS export names for ESM import in node:
|
181
|
-
0 && (module.exports = {
|
182
|
-
GraphQLRuleTester
|
183
|
-
});
|
package/esm/testkit.d.mts
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
import 'eslint';
|
2
|
-
import 'graphql';
|
3
|
-
import './estree-converter/types.mjs';
|
4
|
-
export { G as GraphQLESLintRuleListener, b as GraphQLInvalidTestCase, c as GraphQLRuleTester, a as GraphQLValidTestCase } from './types-2e1afd7c.js';
|
5
|
-
import 'estree';
|
6
|
-
import '@graphql-tools/utils';
|
7
|
-
import 'graphql-config';
|
8
|
-
import 'json-schema-to-ts';
|
package/esm/testkit.js
DELETED
@@ -1,152 +0,0 @@
|
|
1
|
-
import { createRequire } from 'module';
|
2
|
-
const require = createRequire(import.meta.url);
|
3
|
-
import "./chunk-BMTV3EA2.js";
|
4
|
-
import { readFileSync } from "fs";
|
5
|
-
import { resolve } from "path";
|
6
|
-
import { codeFrameColumns } from "@babel/code-frame";
|
7
|
-
import { Linter, RuleTester } from "eslint";
|
8
|
-
function indentCode(code, indent = 4) {
|
9
|
-
return code.replace(/^/gm, " ".repeat(indent));
|
10
|
-
}
|
11
|
-
function applyFix(code, { range, text }) {
|
12
|
-
return [code.slice(0, range[0]), text, code.slice(range[1])].join("");
|
13
|
-
}
|
14
|
-
class GraphQLRuleTester extends RuleTester {
|
15
|
-
constructor(parserOptions = {}) {
|
16
|
-
const config = {
|
17
|
-
parser: require.resolve("@graphql-eslint/eslint-plugin"),
|
18
|
-
parserOptions: {
|
19
|
-
...parserOptions,
|
20
|
-
skipGraphQLConfig: true
|
21
|
-
}
|
22
|
-
};
|
23
|
-
super(config);
|
24
|
-
this.config = config;
|
25
|
-
}
|
26
|
-
fromMockFile(path) {
|
27
|
-
return readFileSync(resolve(__dirname, `../tests/mocks/${path}`), "utf-8");
|
28
|
-
}
|
29
|
-
runGraphQLTests(ruleId, rule, tests) {
|
30
|
-
super.run(ruleId, rule, tests);
|
31
|
-
const linter = new Linter();
|
32
|
-
linter.defineRule(ruleId, rule);
|
33
|
-
const hasOnlyTest = [...tests.valid, ...tests.invalid].some(
|
34
|
-
(t) => typeof t !== "string" && t.only
|
35
|
-
);
|
36
|
-
for (const [idx, testCase] of tests.invalid.entries()) {
|
37
|
-
const { only, filename, options, name } = testCase;
|
38
|
-
if (hasOnlyTest && !only) {
|
39
|
-
continue;
|
40
|
-
}
|
41
|
-
const code = removeTrailingBlankLines(testCase.code);
|
42
|
-
const verifyConfig = getVerifyConfig(ruleId, this.config, testCase);
|
43
|
-
defineParser(linter, verifyConfig.parser);
|
44
|
-
const messages = linter.verify(code, verifyConfig, filename);
|
45
|
-
if (messages.length === 0) {
|
46
|
-
throw new Error("Invalid case should have at least one error.");
|
47
|
-
}
|
48
|
-
const codeFrame = indentCode(printCode(code, { line: 0, column: 0 }));
|
49
|
-
const messageForSnapshot = ["#### \u2328\uFE0F Code", codeFrame];
|
50
|
-
if (options) {
|
51
|
-
const opts = JSON.stringify(options, null, 2).slice(1, -1);
|
52
|
-
messageForSnapshot.push("#### \u2699\uFE0F Options", indentCode(removeTrailingBlankLines(opts), 2));
|
53
|
-
}
|
54
|
-
for (const [index, message] of messages.entries()) {
|
55
|
-
if (message.fatal) {
|
56
|
-
throw new Error(message.message);
|
57
|
-
}
|
58
|
-
const codeWithMessage = printCode(code, message, 1);
|
59
|
-
messageForSnapshot.push(
|
60
|
-
printWithIndex("#### \u274C Error", index, messages.length),
|
61
|
-
indentCode(codeWithMessage)
|
62
|
-
);
|
63
|
-
if (message.suggestions && (code.match(/\n/g) || "").length < 1e3) {
|
64
|
-
for (const [i, suggestion] of message.suggestions.entries()) {
|
65
|
-
const title = printWithIndex(
|
66
|
-
"#### \u{1F4A1} Suggestion",
|
67
|
-
i,
|
68
|
-
message.suggestions.length,
|
69
|
-
suggestion.desc
|
70
|
-
);
|
71
|
-
const output = applyFix(code, suggestion.fix);
|
72
|
-
const codeFrame2 = printCode(output, { line: 0, column: 0 });
|
73
|
-
messageForSnapshot.push(title, indentCode(codeFrame2, 2));
|
74
|
-
}
|
75
|
-
}
|
76
|
-
}
|
77
|
-
if (rule.meta.fixable) {
|
78
|
-
const { fixed, output } = linter.verifyAndFix(code, verifyConfig, filename);
|
79
|
-
if (fixed) {
|
80
|
-
messageForSnapshot.push("#### \u{1F527} Autofix output", indentCode(printCode(output)));
|
81
|
-
}
|
82
|
-
}
|
83
|
-
it(name || `Invalid #${idx + 1}`, () => {
|
84
|
-
expect(messageForSnapshot.join("\n\n")).toMatchSnapshot();
|
85
|
-
});
|
86
|
-
}
|
87
|
-
}
|
88
|
-
}
|
89
|
-
function removeTrailingBlankLines(text) {
|
90
|
-
return text.replace(/^\s*\n/, "").trimEnd();
|
91
|
-
}
|
92
|
-
function printWithIndex(title, index, total, description) {
|
93
|
-
if (total > 1) {
|
94
|
-
title += ` ${index + 1}/${total}`;
|
95
|
-
}
|
96
|
-
if (description) {
|
97
|
-
title += `: ${description}`;
|
98
|
-
}
|
99
|
-
return title;
|
100
|
-
}
|
101
|
-
function getVerifyConfig(ruleId, testerConfig, testCase) {
|
102
|
-
const { parser = testerConfig.parser, parserOptions, options } = testCase;
|
103
|
-
return {
|
104
|
-
...testerConfig,
|
105
|
-
parser,
|
106
|
-
parserOptions: {
|
107
|
-
...testerConfig.parserOptions,
|
108
|
-
...parserOptions
|
109
|
-
},
|
110
|
-
rules: {
|
111
|
-
[ruleId]: Array.isArray(options) ? ["error", ...options] : "error"
|
112
|
-
}
|
113
|
-
};
|
114
|
-
}
|
115
|
-
const parsers = /* @__PURE__ */ new WeakMap();
|
116
|
-
function defineParser(linter, parser) {
|
117
|
-
if (!parser) {
|
118
|
-
return;
|
119
|
-
}
|
120
|
-
if (!parsers.has(linter)) {
|
121
|
-
parsers.set(linter, /* @__PURE__ */ new Set());
|
122
|
-
}
|
123
|
-
const defined = parsers.get(linter);
|
124
|
-
if (!defined.has(parser)) {
|
125
|
-
defined.add(parser);
|
126
|
-
linter.defineParser(parser, require(parser));
|
127
|
-
}
|
128
|
-
}
|
129
|
-
function printCode(code, result = {}, linesOffset = Number.POSITIVE_INFINITY) {
|
130
|
-
const { line, column, endLine, endColumn, message } = result;
|
131
|
-
const location = {};
|
132
|
-
if (typeof line === "number" && typeof column === "number") {
|
133
|
-
location.start = {
|
134
|
-
line,
|
135
|
-
column
|
136
|
-
};
|
137
|
-
}
|
138
|
-
if (typeof endLine === "number" && typeof endColumn === "number") {
|
139
|
-
location.end = {
|
140
|
-
line: endLine,
|
141
|
-
column: endColumn
|
142
|
-
};
|
143
|
-
}
|
144
|
-
return codeFrameColumns(code, location, {
|
145
|
-
linesAbove: linesOffset,
|
146
|
-
linesBelow: linesOffset,
|
147
|
-
message
|
148
|
-
});
|
149
|
-
}
|
150
|
-
export {
|
151
|
-
GraphQLRuleTester
|
152
|
-
};
|