@graphql-eslint/eslint-plugin 4.0.0-alpha-20230801163310-8bc4340 → 4.0.0-alpha-20230810160036-304c2c0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -0
- package/cjs/cache.js +10 -19
- package/cjs/configs/index.d.ts +42 -16
- package/cjs/configs/index.js +10 -19
- package/cjs/configs/operations-all.d.ts +4 -3
- package/cjs/configs/operations-all.js +5 -4
- package/cjs/configs/operations-recommended.d.ts +3 -1
- package/cjs/configs/operations-recommended.js +3 -1
- package/cjs/configs/schema-all.d.ts +6 -1
- package/cjs/configs/schema-all.js +5 -2
- package/cjs/configs/schema-recommended.d.ts +19 -1
- package/cjs/configs/schema-recommended.js +22 -2
- package/cjs/documents.js +17 -32
- package/cjs/estree-converter/converter.js +14 -27
- package/cjs/estree-converter/index.js +4 -7
- package/cjs/estree-converter/types.js +3 -5
- package/cjs/estree-converter/utils.d.ts +2 -3
- package/cjs/estree-converter/utils.js +15 -45
- package/cjs/flat-configs.d.ts +59 -12
- package/cjs/flat-configs.js +9 -14
- package/cjs/graphql-config.d.ts +4 -3
- package/cjs/graphql-config.js +23 -44
- package/cjs/index.d.ts +10 -4
- package/cjs/index.js +8 -16
- package/cjs/parser.d.ts +4 -3
- package/cjs/parser.js +38 -45
- package/cjs/processor.d.ts +5 -1
- package/cjs/processor.js +25 -57
- package/cjs/rules/alphabetize.d.ts +6 -16
- package/cjs/rules/alphabetize.js +60 -132
- package/cjs/rules/description-style.d.ts +4 -3
- package/cjs/rules/description-style.js +11 -18
- package/cjs/rules/graphql-js-validation.d.ts +4 -3
- package/cjs/rules/graphql-js-validation.js +151 -225
- package/cjs/rules/index.d.ts +15 -13
- package/cjs/rules/index.js +8 -45
- package/cjs/rules/input-name.d.ts +4 -3
- package/cjs/rules/input-name.js +43 -59
- package/cjs/rules/lone-executable-definition.d.ts +6 -5
- package/cjs/rules/lone-executable-definition.js +14 -28
- package/cjs/rules/match-document-filename.d.ts +4 -3
- package/cjs/rules/match-document-filename.js +39 -70
- package/cjs/rules/naming-convention.d.ts +4 -3
- package/cjs/rules/naming-convention.js +56 -74
- package/cjs/rules/no-anonymous-operations.d.ts +4 -3
- package/cjs/rules/no-anonymous-operations.js +11 -18
- package/cjs/rules/no-deprecated.d.ts +4 -3
- package/cjs/rules/no-deprecated.js +15 -29
- package/cjs/rules/no-duplicate-fields.d.ts +4 -3
- package/cjs/rules/no-duplicate-fields.js +13 -23
- package/cjs/rules/no-hashtag-description.d.ts +4 -3
- package/cjs/rules/no-hashtag-description.js +16 -29
- package/cjs/rules/no-one-place-fragments.d.ts +4 -3
- package/cjs/rules/no-one-place-fragments.js +17 -29
- package/cjs/rules/no-root-type.d.ts +4 -3
- package/cjs/rules/no-root-type.js +15 -25
- package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +4 -3
- package/cjs/rules/no-scalar-result-type-on-mutation.js +18 -30
- package/cjs/rules/no-typename-prefix.d.ts +4 -3
- package/cjs/rules/no-typename-prefix.js +26 -33
- package/cjs/rules/no-unreachable-types.d.ts +4 -3
- package/cjs/rules/no-unreachable-types.js +25 -47
- package/cjs/rules/no-unused-fields.d.ts +4 -3
- package/cjs/rules/no-unused-fields.js +24 -49
- package/cjs/rules/relay-arguments.d.ts +4 -3
- package/cjs/rules/relay-arguments.js +20 -43
- package/cjs/rules/relay-connection-types.d.ts +4 -3
- package/cjs/rules/relay-connection-types.js +14 -45
- package/cjs/rules/relay-edge-types.d.ts +4 -3
- package/cjs/rules/relay-edge-types.js +48 -99
- package/cjs/rules/relay-page-info.d.ts +4 -3
- package/cjs/rules/relay-page-info.js +21 -44
- package/cjs/rules/require-deprecation-date.d.ts +4 -3
- package/cjs/rules/require-deprecation-date.js +15 -31
- package/cjs/rules/require-deprecation-reason.d.ts +4 -3
- package/cjs/rules/require-deprecation-reason.js +12 -20
- package/cjs/rules/require-description.d.ts +4 -3
- package/cjs/rules/require-description.js +39 -65
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +4 -3
- package/cjs/rules/require-field-of-type-query-in-mutation-result.js +16 -31
- package/cjs/rules/require-import-fragment.d.ts +4 -3
- package/cjs/rules/require-import-fragment.js +22 -40
- package/cjs/rules/require-nullable-fields-with-oneof.d.ts +4 -3
- package/cjs/rules/require-nullable-fields-with-oneof.js +11 -22
- package/cjs/rules/require-nullable-result-in-root.d.ts +4 -3
- package/cjs/rules/require-nullable-result-in-root.js +34 -44
- package/cjs/rules/{require-id-when-available.d.ts → require-selections.d.ts} +4 -3
- package/cjs/rules/require-selections.js +198 -0
- package/cjs/rules/require-type-pattern-with-oneof.d.ts +4 -3
- package/cjs/rules/require-type-pattern-with-oneof.js +15 -23
- package/cjs/rules/selection-set-depth.d.ts +4 -3
- package/cjs/rules/selection-set-depth.js +18 -34
- package/cjs/rules/strict-id-in-types.d.ts +4 -3
- package/cjs/rules/strict-id-in-types.js +25 -43
- package/cjs/rules/{no-case-insensitive-enum-values-duplicates.d.ts → unique-enum-value-names.d.ts} +4 -3
- package/cjs/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +16 -21
- package/cjs/rules/unique-fragment-name.d.ts +3 -2
- package/cjs/rules/unique-fragment-name.js +24 -36
- package/cjs/rules/unique-operation-name.d.ts +4 -3
- package/cjs/rules/unique-operation-name.js +10 -12
- package/cjs/schema.d.ts +4 -3
- package/cjs/schema.js +14 -27
- package/cjs/siblings.d.ts +24 -8
- package/cjs/siblings.js +42 -82
- package/cjs/types.d.ts +74 -7
- package/cjs/types.js +3 -5
- package/cjs/utils.d.ts +3 -2
- package/cjs/utils.js +27 -44
- package/esm/cache.js +4 -8
- package/esm/{chunk-BMTV3EA2.js → chunk-U3TKCM4X.js} +1 -1
- package/esm/configs/index.d.mts +42 -16
- package/esm/configs/index.js +4 -4
- package/esm/configs/operations-all.d.mts +4 -3
- package/esm/configs/operations-all.js +6 -5
- package/esm/configs/operations-recommended.d.mts +3 -1
- package/esm/configs/operations-recommended.js +4 -2
- package/esm/configs/schema-all.d.mts +6 -1
- package/esm/configs/schema-all.js +6 -3
- package/esm/configs/schema-recommended.d.mts +19 -1
- package/esm/configs/schema-recommended.js +23 -3
- package/esm/configs/{relay.js → schema-relay.js} +4 -4
- package/esm/documents.js +10 -17
- package/esm/estree-converter/converter.js +9 -18
- package/esm/estree-converter/utils.d.mts +2 -3
- package/esm/estree-converter/utils.js +11 -38
- package/esm/flat-configs.d.mts +59 -12
- package/esm/flat-configs.js +4 -5
- package/esm/graphql-config.d.mts +4 -3
- package/esm/graphql-config.js +18 -34
- package/esm/index.d.mts +10 -4
- package/esm/index.js +1 -1
- package/esm/parser.d.mts +4 -3
- package/esm/parser.js +33 -27
- package/esm/processor.d.mts +5 -1
- package/esm/processor.js +21 -46
- package/esm/rules/alphabetize.d.mts +6 -16
- package/esm/rules/alphabetize.js +53 -118
- package/esm/rules/description-style.d.mts +4 -3
- package/esm/rules/description-style.js +7 -11
- package/esm/rules/graphql-js-validation.d.mts +4 -3
- package/esm/rules/graphql-js-validation.js +178 -218
- package/esm/rules/index.d.mts +15 -13
- package/esm/rules/index.js +5 -5
- package/esm/rules/input-name.d.mts +4 -3
- package/esm/rules/input-name.js +39 -52
- package/esm/rules/lone-executable-definition.d.mts +6 -5
- package/esm/rules/lone-executable-definition.js +10 -20
- package/esm/rules/match-document-filename.d.mts +4 -3
- package/esm/rules/match-document-filename.js +35 -61
- package/esm/rules/naming-convention.d.mts +4 -3
- package/esm/rules/naming-convention.js +51 -65
- package/esm/rules/no-anonymous-operations.d.mts +4 -3
- package/esm/rules/no-anonymous-operations.js +6 -9
- package/esm/rules/no-deprecated.d.mts +4 -3
- package/esm/rules/no-deprecated.js +10 -20
- package/esm/rules/no-duplicate-fields.d.mts +4 -3
- package/esm/rules/no-duplicate-fields.js +9 -16
- package/esm/rules/no-hashtag-description.d.mts +4 -3
- package/esm/rules/no-hashtag-description.js +11 -20
- package/esm/rules/no-one-place-fragments.d.mts +4 -3
- package/esm/rules/no-one-place-fragments.js +12 -19
- package/esm/rules/no-root-type.d.mts +4 -3
- package/esm/rules/no-root-type.js +11 -18
- package/esm/rules/no-scalar-result-type-on-mutation.d.mts +4 -3
- package/esm/rules/no-scalar-result-type-on-mutation.js +13 -21
- package/esm/rules/no-typename-prefix.d.mts +4 -3
- package/esm/rules/no-typename-prefix.js +22 -26
- package/esm/rules/no-unreachable-types.d.mts +4 -3
- package/esm/rules/no-unreachable-types.js +18 -33
- package/esm/rules/no-unused-fields.d.mts +4 -3
- package/esm/rules/no-unused-fields.js +19 -40
- package/esm/rules/relay-arguments.d.mts +4 -3
- package/esm/rules/relay-arguments.js +15 -34
- package/esm/rules/relay-connection-types.d.mts +4 -3
- package/esm/rules/relay-connection-types.js +10 -38
- package/esm/rules/relay-edge-types.d.mts +4 -3
- package/esm/rules/relay-edge-types.js +43 -89
- package/esm/rules/relay-page-info.d.mts +4 -3
- package/esm/rules/relay-page-info.js +16 -34
- package/esm/rules/require-deprecation-date.d.mts +4 -3
- package/esm/rules/require-deprecation-date.js +10 -22
- package/esm/rules/require-deprecation-reason.d.mts +4 -3
- package/esm/rules/require-deprecation-reason.js +7 -11
- package/esm/rules/require-description.d.mts +4 -3
- package/esm/rules/require-description.js +34 -55
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +4 -3
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +11 -22
- package/esm/rules/require-import-fragment.d.mts +4 -3
- package/esm/rules/require-import-fragment.js +14 -26
- package/esm/rules/require-nullable-fields-with-oneof.d.mts +4 -3
- package/esm/rules/require-nullable-fields-with-oneof.js +6 -13
- package/esm/rules/require-nullable-result-in-root.d.mts +4 -3
- package/esm/rules/require-nullable-result-in-root.js +29 -35
- package/esm/rules/{require-id-when-available.d.mts → require-selections.d.mts} +4 -3
- package/esm/rules/{require-id-when-available.js → require-selections.js} +43 -80
- package/esm/rules/require-type-pattern-with-oneof.d.mts +4 -3
- package/esm/rules/require-type-pattern-with-oneof.js +11 -16
- package/esm/rules/selection-set-depth.d.mts +4 -3
- package/esm/rules/selection-set-depth.js +11 -20
- package/esm/rules/strict-id-in-types.d.mts +4 -3
- package/esm/rules/strict-id-in-types.js +20 -34
- package/esm/rules/{no-case-insensitive-enum-values-duplicates.d.mts → unique-enum-value-names.d.mts} +4 -3
- package/esm/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +8 -9
- package/esm/rules/unique-fragment-name.d.mts +3 -2
- package/esm/rules/unique-fragment-name.js +20 -27
- package/esm/rules/unique-operation-name.d.mts +4 -3
- package/esm/rules/unique-operation-name.js +6 -5
- package/esm/schema.d.mts +4 -3
- package/esm/schema.js +7 -12
- package/esm/siblings.d.mts +24 -8
- package/esm/siblings.js +37 -73
- package/esm/types.d.mts +74 -7
- package/esm/utils.d.mts +3 -2
- package/esm/utils.js +20 -31
- package/index.browser.mjs +5323 -0
- package/package.json +8 -13
- package/cjs/rules/require-id-when-available.js +0 -241
- package/cjs/types-8d5f4ae0.d.ts +0 -107
- package/esm/types-ace77d86.d.ts +0 -107
- /package/cjs/configs/{relay.d.ts → schema-relay.d.ts} +0 -0
- /package/cjs/configs/{relay.js → schema-relay.js} +0 -0
- /package/esm/configs/{relay.d.mts → schema-relay.d.mts} +0 -0
package/cjs/parser.js
CHANGED
@@ -3,18 +3,14 @@ var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
7
|
var __export = (target, all) => {
|
9
8
|
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable:
|
11
|
-
}
|
12
|
-
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
10
|
+
}, __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from == "object" || typeof from == "function")
|
14
12
|
for (let key of __getOwnPropNames(from))
|
15
|
-
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
13
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
18
14
|
return to;
|
19
15
|
};
|
20
16
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
@@ -22,51 +18,52 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
22
18
|
// file that has been converted to a CommonJS file using a Babel-
|
23
19
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
20
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable:
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
26
22
|
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
23
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
29
24
|
var parser_exports = {};
|
30
25
|
__export(parser_exports, {
|
31
26
|
parseForESLint: () => parseForESLint
|
32
27
|
});
|
33
28
|
module.exports = __toCommonJS(parser_exports);
|
34
|
-
var import_utils = require("@graphql-tools/utils");
|
35
|
-
var import_debug = __toESM(require("debug"));
|
36
|
-
var import_graphql = require("graphql");
|
37
|
-
var import_estree_converter = require("./estree-converter/index.js");
|
38
|
-
var import_graphql_config = require("./graphql-config.js");
|
39
|
-
var import_schema = require("./schema.js");
|
40
|
-
var import_siblings = require("./siblings.js");
|
41
|
-
var import_utils2 = require("./utils.js");
|
29
|
+
var import_utils = require("@graphql-tools/utils"), import_debug = __toESM(require("debug")), import_graphql = require("graphql"), import_estree_converter = require("./estree-converter/index.js"), import_graphql_config = require("./graphql-config.js"), import_schema = require("./schema.js"), import_siblings = require("./siblings.js"), import_utils2 = require("./utils.js"), import_documents = require("./documents.js");
|
42
30
|
const debug = (0, import_debug.default)("graphql-eslint:parser");
|
43
31
|
debug("cwd %o", import_utils2.CWD);
|
32
|
+
const LEGACY_PARSER_OPTIONS_KEYS = [
|
33
|
+
"schema",
|
34
|
+
"documents",
|
35
|
+
"extensions",
|
36
|
+
"include",
|
37
|
+
"exclude",
|
38
|
+
"projects",
|
39
|
+
"schemaOptions",
|
40
|
+
"graphQLParserOptions",
|
41
|
+
"skipGraphQLConfig",
|
42
|
+
"operations"
|
43
|
+
];
|
44
44
|
function parseForESLint(code, options) {
|
45
|
-
|
45
|
+
for (const key of LEGACY_PARSER_OPTIONS_KEYS)
|
46
|
+
if (key in options)
|
47
|
+
throw new Error(
|
48
|
+
`\`parserOptions.${key}\` was removed in graphql-eslint@4. Use physical graphql-config for setting schema and documents or \`parserOptions.graphQLConfig\` for programmatic usage.`
|
49
|
+
);
|
46
50
|
try {
|
47
|
-
const { filePath } = options;
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
53
|
-
const gqlConfig = (0, import_graphql_config.loadGraphQLConfig)(options);
|
54
|
-
const realFilepath = filePath.replace(import_utils2.VIRTUAL_DOCUMENT_REGEX, "");
|
55
|
-
const project = gqlConfig.getProjectForFile(realFilepath);
|
56
|
-
let schema = null;
|
51
|
+
const { filePath } = options, { document } = (0, import_utils.parseGraphQLSDL)(filePath, code, { noLocation: !1 });
|
52
|
+
let project, schema, documents;
|
53
|
+
{
|
54
|
+
const gqlConfig = (0, import_graphql_config.loadGraphQLConfig)(options), realFilepath = filePath.replace(import_utils2.VIRTUAL_DOCUMENT_REGEX, "");
|
55
|
+
project = gqlConfig.getProjectForFile(realFilepath), documents = (0, import_documents.getDocuments)(project);
|
56
|
+
}
|
57
57
|
try {
|
58
|
-
schema =
|
58
|
+
schema = (0, import_schema.getSchema)(project);
|
59
59
|
} catch (error) {
|
60
|
-
|
61
|
-
error.message = `Error while loading schema: ${error.message}`;
|
62
|
-
}
|
63
|
-
throw error;
|
60
|
+
throw error instanceof Error && (error.message = `Error while loading schema: ${error.message}`), error;
|
64
61
|
}
|
65
62
|
const rootTree = (0, import_estree_converter.convertToESTree)(document, schema);
|
66
63
|
return {
|
67
64
|
services: {
|
68
65
|
schema,
|
69
|
-
siblingOperations: (0, import_siblings.getSiblings)(
|
66
|
+
siblingOperations: (0, import_siblings.getSiblings)(documents)
|
70
67
|
},
|
71
68
|
ast: {
|
72
69
|
comments: (0, import_estree_converter.extractComments)(document.loc),
|
@@ -79,20 +76,16 @@ function parseForESLint(code, options) {
|
|
79
76
|
}
|
80
77
|
};
|
81
78
|
} catch (error) {
|
82
|
-
if (error instanceof Error) {
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
const location = (_a = error.locations) == null ? void 0 : _a[0];
|
87
|
-
const eslintError = {
|
88
|
-
index: (_b = error.positions) == null ? void 0 : _b[0],
|
79
|
+
if (error instanceof Error && (error.message = `[graphql-eslint] ${error.message}`), error instanceof import_graphql.GraphQLError) {
|
80
|
+
const location = error.locations?.[0];
|
81
|
+
throw {
|
82
|
+
index: error.positions?.[0],
|
89
83
|
...location && {
|
90
84
|
lineNumber: location.line,
|
91
85
|
column: location.column - 1
|
92
86
|
},
|
93
87
|
message: error.message
|
94
88
|
};
|
95
|
-
throw eslintError;
|
96
89
|
}
|
97
90
|
throw error;
|
98
91
|
}
|
package/cjs/processor.d.ts
CHANGED
@@ -4,6 +4,10 @@ type Block = Linter.ProcessorFile & {
|
|
4
4
|
lineOffset: number;
|
5
5
|
offset: number;
|
6
6
|
};
|
7
|
-
declare const processor:
|
7
|
+
declare const processor: {
|
8
|
+
supportsAutofix: true;
|
9
|
+
preprocess(code: string, filePath: string): (string | Block)[];
|
10
|
+
postprocess(messages: Linter.LintMessage[][], filePath: string): Linter.LintMessage[];
|
11
|
+
};
|
8
12
|
|
9
13
|
export { Block, processor };
|
package/cjs/processor.js
CHANGED
@@ -5,40 +5,28 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
6
|
var __export = (target, all) => {
|
7
7
|
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable:
|
9
|
-
}
|
10
|
-
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
12
11
|
for (let key of __getOwnPropNames(from))
|
13
|
-
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
13
|
return to;
|
17
14
|
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value:
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
19
16
|
var processor_exports = {};
|
20
17
|
__export(processor_exports, {
|
21
18
|
processor: () => processor
|
22
19
|
});
|
23
20
|
module.exports = __toCommonJS(processor_exports);
|
24
|
-
var
|
25
|
-
var import_graphql_tag_pluck = require("@graphql-tools/graphql-tag-pluck");
|
26
|
-
var import_utils = require("@graphql-tools/utils");
|
27
|
-
var import_graphql_config2 = require("./graphql-config.js");
|
28
|
-
var import_utils2 = require("./utils.js");
|
21
|
+
var import_node_path = require("node:path"), import_graphql_tag_pluck = require("@graphql-tools/graphql-tag-pluck"), import_utils = require("@graphql-tools/utils"), import_graphql_config2 = require("./graphql-config.js"), import_utils2 = require("./utils.js");
|
29
22
|
const blocksMap = /* @__PURE__ */ new Map();
|
30
|
-
let onDiskConfig;
|
31
|
-
|
32
|
-
|
33
|
-
const processor = {
|
34
|
-
supportsAutofix: true,
|
23
|
+
let onDiskConfig, onDiskConfigLoaded = !1;
|
24
|
+
const RELEVANT_KEYWORDS = ["gql", "graphql", "GraphQL"], processor = {
|
25
|
+
supportsAutofix: !0,
|
35
26
|
preprocess(code, filePath) {
|
36
|
-
|
37
|
-
onDiskConfig = (0, import_graphql_config2.loadOnDiskGraphQLConfig)(filePath);
|
38
|
-
onDiskConfigLoaded = true;
|
39
|
-
}
|
27
|
+
onDiskConfigLoaded || (onDiskConfig = (0, import_graphql_config2.loadOnDiskGraphQLConfig)(filePath), onDiskConfigLoaded = !0);
|
40
28
|
let keywords = RELEVANT_KEYWORDS;
|
41
|
-
const pluckConfig = onDiskConfig
|
29
|
+
const pluckConfig = onDiskConfig?.getProjectForFile(filePath).extensions.pluckConfig;
|
42
30
|
if (pluckConfig) {
|
43
31
|
const {
|
44
32
|
modules = [],
|
@@ -55,38 +43,31 @@ const processor = {
|
|
55
43
|
)
|
56
44
|
];
|
57
45
|
}
|
58
|
-
if (keywords.every((keyword) => !code.includes(keyword)))
|
46
|
+
if (keywords.every((keyword) => !code.includes(keyword)))
|
59
47
|
return [code];
|
60
|
-
}
|
61
48
|
try {
|
62
|
-
const
|
63
|
-
skipIndent:
|
49
|
+
const blocks = (0, import_graphql_tag_pluck.gqlPluckFromCodeStringSync)(filePath, code, {
|
50
|
+
skipIndent: !0,
|
64
51
|
...pluckConfig
|
65
|
-
})
|
66
|
-
const blocks = sources.map((item) => ({
|
52
|
+
}).map((item) => ({
|
67
53
|
filename: "document.graphql",
|
68
54
|
text: item.body,
|
69
55
|
lineOffset: item.locationOffset.line - 1,
|
70
56
|
// @ts-expect-error -- `index` field exist but show ts error
|
71
57
|
offset: item.locationOffset.index + 1
|
72
58
|
}));
|
73
|
-
blocksMap.set(filePath, blocks)
|
74
|
-
return [
|
59
|
+
return blocksMap.set(filePath, blocks), [
|
75
60
|
...blocks,
|
76
61
|
code
|
77
62
|
/* source code must be provided and be last */
|
78
63
|
];
|
79
64
|
} catch (error) {
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
)}" file
|
65
|
+
return error instanceof Error && (error.message = `[graphql-eslint] Error while preprocessing "${(0, import_node_path.relative)(
|
66
|
+
import_utils2.CWD,
|
67
|
+
filePath
|
68
|
+
)}" file
|
85
69
|
|
86
|
-
${error.message}
|
87
|
-
}
|
88
|
-
console.error(error);
|
89
|
-
return [code];
|
70
|
+
${error.message}`), console.error(error), [code];
|
90
71
|
}
|
91
72
|
},
|
92
73
|
postprocess(messages, filePath) {
|
@@ -94,31 +75,18 @@ ${error.message}`;
|
|
94
75
|
for (let i = 0; i < blocks.length; i += 1) {
|
95
76
|
const { lineOffset, offset } = blocks[i];
|
96
77
|
for (const message of messages[i] || []) {
|
97
|
-
|
98
|
-
|
99
|
-
delete message.endLine;
|
100
|
-
delete message.endColumn;
|
101
|
-
delete message.fix;
|
102
|
-
delete message.suggestions;
|
103
|
-
Object.assign(message, import_utils2.REPORT_ON_FIRST_CHARACTER);
|
78
|
+
if (/\.(vue|svelte)$/.test(filePath)) {
|
79
|
+
delete message.endLine, delete message.endColumn, delete message.fix, delete message.suggestions, Object.assign(message, import_utils2.REPORT_ON_FIRST_CHARACTER);
|
104
80
|
continue;
|
105
81
|
}
|
106
|
-
message.line += lineOffset;
|
107
|
-
if (typeof message.endLine === "number") {
|
108
|
-
message.endLine += lineOffset;
|
109
|
-
}
|
110
|
-
if (message.fix) {
|
111
|
-
message.fix.range[0] += offset;
|
112
|
-
message.fix.range[1] += offset;
|
113
|
-
}
|
82
|
+
message.line += lineOffset, typeof message.endLine == "number" && (message.endLine += lineOffset), message.fix && (message.fix.range[0] += offset, message.fix.range[1] += offset);
|
114
83
|
for (const suggestion of message.suggestions || []) {
|
115
84
|
const [start, end] = suggestion.fix.range;
|
116
85
|
suggestion.fix.range = [start + offset, end + offset];
|
117
86
|
}
|
118
87
|
}
|
119
88
|
}
|
120
|
-
|
121
|
-
return result.sort((a, b) => a.line - b.line || a.column - b.column);
|
89
|
+
return messages.flat().sort((a, b) => a.line - b.line || a.column - b.column);
|
122
90
|
}
|
123
91
|
};
|
124
92
|
// Annotate the CommonJS export names for ESM import in node:
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { FromSchema } from 'json-schema-to-ts';
|
2
|
-
import {
|
3
|
-
import '@graphql-tools/utils';
|
2
|
+
import { GraphQLESLintRule } from '../types.js';
|
4
3
|
import 'eslint';
|
5
4
|
import 'estree';
|
6
5
|
import 'graphql';
|
7
|
-
import '
|
6
|
+
import '../siblings.js';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.js';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const schema: {
|
11
12
|
readonly type: "array";
|
@@ -26,13 +27,8 @@ declare const schema: {
|
|
26
27
|
readonly minItems: 1;
|
27
28
|
};
|
28
29
|
readonly values: {
|
29
|
-
readonly
|
30
|
-
readonly enum: ["EnumTypeDefinition"];
|
31
|
-
};
|
30
|
+
readonly type: "boolean";
|
32
31
|
readonly description: "Values of `enum`.";
|
33
|
-
readonly type: "array";
|
34
|
-
readonly uniqueItems: true;
|
35
|
-
readonly minItems: 1;
|
36
32
|
};
|
37
33
|
readonly selections: {
|
38
34
|
readonly items: {
|
@@ -44,13 +40,8 @@ declare const schema: {
|
|
44
40
|
readonly minItems: 1;
|
45
41
|
};
|
46
42
|
readonly variables: {
|
47
|
-
readonly
|
48
|
-
readonly enum: ["OperationDefinition"];
|
49
|
-
};
|
43
|
+
readonly type: "boolean";
|
50
44
|
readonly description: "Variables of operations `query`, `mutation` and `subscription`.";
|
51
|
-
readonly type: "array";
|
52
|
-
readonly uniqueItems: true;
|
53
|
-
readonly minItems: 1;
|
54
45
|
};
|
55
46
|
readonly arguments: {
|
56
47
|
readonly items: {
|
@@ -64,7 +55,6 @@ declare const schema: {
|
|
64
55
|
readonly definitions: {
|
65
56
|
readonly type: "boolean";
|
66
57
|
readonly description: "Definitions – `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`.";
|
67
|
-
readonly default: false;
|
68
58
|
};
|
69
59
|
readonly groups: {
|
70
60
|
readonly minItems: 2;
|