@graphql-eslint/eslint-plugin 3.11.0-alpha-20220923194422-95bf79f → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  import { GraphQLConfig } from 'graphql-config';
2
2
  import { ParserOptions } from './types';
3
- export declare function loadGraphQLConfig(options: ParserOptions): GraphQLConfig;
3
+ export declare function loadGraphQLConfig(options?: ParserOptions): GraphQLConfig;
package/index.d.ts CHANGED
@@ -4,10 +4,7 @@ export * from './testkit';
4
4
  export * from './types';
5
5
  export { requireGraphQLSchemaFromContext, requireSiblingsOperations } from './utils';
6
6
  export declare const processors: {
7
- graphql: import("eslint").Linter.Processor<string | (import("eslint").Linter.ProcessorFile & {
8
- lineOffset: number;
9
- offset: number;
10
- })>;
7
+ graphql: import("eslint").Linter.Processor<string | import("./processor").Block>;
11
8
  };
12
9
  export declare const configs: {
13
10
  [k: string]: {
package/index.js CHANGED
@@ -5,23 +5,76 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
7
  const graphqlTagPluck = require('@graphql-tools/graphql-tag-pluck');
8
+ const utils = require('@graphql-tools/utils');
9
+ const path = require('path');
10
+ const debugFactory = _interopDefault(require('debug'));
11
+ const graphqlConfig = require('graphql-config');
12
+ const codeFileLoader = require('@graphql-tools/code-file-loader');
8
13
  const graphql = require('graphql');
9
14
  const validate = require('graphql/validation/validate');
10
15
  const fs = require('fs');
11
- const path = require('path');
12
16
  const lowerCase = _interopDefault(require('lodash.lowercase'));
13
17
  const chalk = _interopDefault(require('chalk'));
14
- const utils = require('@graphql-tools/utils');
15
18
  const valueFromASTUntyped = require('graphql/utilities/valueFromASTUntyped');
16
19
  const depthLimit = _interopDefault(require('graphql-depth-limit'));
17
- const debugFactory = _interopDefault(require('debug'));
18
20
  const fastGlob = _interopDefault(require('fast-glob'));
19
- const graphqlConfig = require('graphql-config');
20
- const codeFileLoader = require('@graphql-tools/code-file-loader');
21
21
  const eslint = require('eslint');
22
22
  const codeFrame = require('@babel/code-frame');
23
23
 
24
- const RELEVANT_KEYWORDS = ['gql', 'graphql', '/* GraphQL */'];
24
+ const debug = debugFactory('graphql-eslint:graphql-config');
25
+ let graphQLConfig;
26
+ function loadGraphQLConfig(options = {}) {
27
+ // We don't want cache config on test environment
28
+ // Otherwise schema and documents will be same for all tests
29
+ if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
30
+ return graphQLConfig;
31
+ }
32
+ const onDiskConfig = options.skipGraphQLConfig
33
+ ? null
34
+ : graphqlConfig.loadConfigSync({
35
+ // load config relative to the file being linted
36
+ rootDir: options.filePath ? path.dirname(options.filePath) : undefined,
37
+ throwOnEmpty: false,
38
+ throwOnMissing: false,
39
+ extensions: [addCodeFileLoaderExtension],
40
+ });
41
+ debug('options.skipGraphQLConfig: %o', options.skipGraphQLConfig);
42
+ if (onDiskConfig) {
43
+ debug('Graphql-config path %o', onDiskConfig.filepath);
44
+ }
45
+ const configOptions = options.projects
46
+ ? { projects: options.projects }
47
+ : {
48
+ schema: (options.schema || ''),
49
+ documents: options.documents || options.operations,
50
+ extensions: options.extensions,
51
+ include: options.include,
52
+ exclude: options.exclude,
53
+ };
54
+ graphQLConfig =
55
+ onDiskConfig ||
56
+ new graphqlConfig.GraphQLConfig({
57
+ config: configOptions,
58
+ filepath: 'virtual-config',
59
+ }, [addCodeFileLoaderExtension]);
60
+ return graphQLConfig;
61
+ }
62
+ const addCodeFileLoaderExtension = api => {
63
+ api.loaders.schema.register(new codeFileLoader.CodeFileLoader());
64
+ api.loaders.documents.register(new codeFileLoader.CodeFileLoader());
65
+ return { name: 'graphql-eslint-loaders' };
66
+ };
67
+
68
+ var _a, _b;
69
+ const graphQLTagPluckOptions = (_b = (_a = loadGraphQLConfig().getDefault()) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.graphqlTagPluck;
70
+ const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = graphQLTagPluckOptions || {};
71
+ const RELEVANT_KEYWORDS = [
72
+ ...new Set([
73
+ ...modules.map(({ identifier }) => identifier),
74
+ ...utils.asArray(globalGqlIdentifierName),
75
+ gqlMagicComment,
76
+ ].filter(Boolean)),
77
+ ];
25
78
  const blocksMap = new Map();
26
79
  const processor = {
27
80
  supportsAutofix: true,
@@ -33,8 +86,8 @@ const processor = {
33
86
  code,
34
87
  filePath,
35
88
  options: {
36
- globalGqlIdentifierName: ['gql', 'graphql'],
37
89
  skipIndent: true,
90
+ ...graphQLTagPluckOptions,
38
91
  },
39
92
  });
40
93
  const blocks = extractedDocuments.map(item => ({
@@ -4206,7 +4259,7 @@ const rules = {
4206
4259
  };
4207
4260
 
4208
4261
  const schemaCache = new Map();
4209
- const debug = debugFactory('graphql-eslint:schema');
4262
+ const debug$1 = debugFactory('graphql-eslint:schema');
4210
4263
  function getSchema(projectForFile, options = {}) {
4211
4264
  const schemaKey = utils.asArray(projectForFile.schema).sort().join(',');
4212
4265
  if (!schemaKey) {
@@ -4217,14 +4270,14 @@ function getSchema(projectForFile, options = {}) {
4217
4270
  }
4218
4271
  let schema;
4219
4272
  try {
4220
- debug('Loading schema from %o', projectForFile.schema);
4273
+ debug$1('Loading schema from %o', projectForFile.schema);
4221
4274
  schema = projectForFile.loadSchemaSync(projectForFile.schema, 'GraphQLSchema', options.schemaOptions);
4222
- if (debug.enabled) {
4223
- debug('Schema loaded: %o', schema instanceof graphql.GraphQLSchema);
4275
+ if (debug$1.enabled) {
4276
+ debug$1('Schema loaded: %o', schema instanceof graphql.GraphQLSchema);
4224
4277
  const schemaPaths = fastGlob.sync(projectForFile.schema, {
4225
4278
  absolute: true,
4226
4279
  });
4227
- debug('Schema pointers %O', schemaPaths);
4280
+ debug$1('Schema pointers %O', schemaPaths);
4228
4281
  }
4229
4282
  }
4230
4283
  catch (error) {
@@ -4235,7 +4288,7 @@ function getSchema(projectForFile, options = {}) {
4235
4288
  return schema;
4236
4289
  }
4237
4290
 
4238
- const debug$1 = debugFactory('graphql-eslint:operations');
4291
+ const debug$2 = debugFactory('graphql-eslint:operations');
4239
4292
  const handleVirtualPath = (documents) => {
4240
4293
  const filepathMap = Object.create(null);
4241
4294
  return documents.map(source => {
@@ -4261,16 +4314,16 @@ const getSiblings = (projectForFile) => {
4261
4314
  }
4262
4315
  let siblings = operationsCache.get(documentsKey);
4263
4316
  if (!siblings) {
4264
- debug$1('Loading operations from %o', projectForFile.documents);
4317
+ debug$2('Loading operations from %o', projectForFile.documents);
4265
4318
  const documents = projectForFile.loadDocumentsSync(projectForFile.documents, {
4266
4319
  skipGraphQLImport: true,
4267
4320
  });
4268
- if (debug$1.enabled) {
4269
- debug$1('Loaded %d operations', documents.length);
4321
+ if (debug$2.enabled) {
4322
+ debug$2('Loaded %d operations', documents.length);
4270
4323
  const operationsPaths = fastGlob.sync(projectForFile.documents, {
4271
4324
  absolute: true,
4272
4325
  });
4273
- debug$1('Operations pointers %O', operationsPaths);
4326
+ debug$2('Operations pointers %O', operationsPaths);
4274
4327
  }
4275
4328
  siblings = handleVirtualPath(documents);
4276
4329
  operationsCache.set(documentsKey, siblings);
@@ -4375,50 +4428,6 @@ function getSiblingOperations(projectForFile) {
4375
4428
  return siblingOperations;
4376
4429
  }
4377
4430
 
4378
- const debug$2 = debugFactory('graphql-eslint:graphql-config');
4379
- let graphQLConfig;
4380
- function loadGraphQLConfig(options) {
4381
- // We don't want cache config on test environment
4382
- // Otherwise schema and documents will be same for all tests
4383
- if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
4384
- return graphQLConfig;
4385
- }
4386
- const onDiskConfig = options.skipGraphQLConfig
4387
- ? null
4388
- : graphqlConfig.loadConfigSync({
4389
- // load config relative to the file being linted
4390
- rootDir: options.filePath ? path.dirname(options.filePath) : undefined,
4391
- throwOnEmpty: false,
4392
- throwOnMissing: false,
4393
- extensions: [addCodeFileLoaderExtension],
4394
- });
4395
- debug$2('options.skipGraphQLConfig: %o', options.skipGraphQLConfig);
4396
- if (onDiskConfig) {
4397
- debug$2('Graphql-config path %o', onDiskConfig.filepath);
4398
- }
4399
- const configOptions = options.projects
4400
- ? { projects: options.projects }
4401
- : {
4402
- schema: (options.schema || ''),
4403
- documents: options.documents || options.operations,
4404
- extensions: options.extensions,
4405
- include: options.include,
4406
- exclude: options.exclude,
4407
- };
4408
- graphQLConfig =
4409
- onDiskConfig ||
4410
- new graphqlConfig.GraphQLConfig({
4411
- config: configOptions,
4412
- filepath: 'virtual-config',
4413
- }, [addCodeFileLoaderExtension]);
4414
- return graphQLConfig;
4415
- }
4416
- const addCodeFileLoaderExtension = api => {
4417
- api.loaders.schema.register(new codeFileLoader.CodeFileLoader());
4418
- api.loaders.documents.register(new codeFileLoader.CodeFileLoader());
4419
- return { name: 'graphql-eslint-loaders' };
4420
- };
4421
-
4422
4431
  const debug$3 = debugFactory('graphql-eslint:parser');
4423
4432
  debug$3('cwd %o', process.cwd());
4424
4433
  function parseForESLint(code, options = {}) {
package/index.mjs CHANGED
@@ -1,21 +1,74 @@
1
1
  import { parseCode } from '@graphql-tools/graphql-tag-pluck';
2
+ import { asArray, getDocumentNodeFromSchema, parseGraphQLSDL } from '@graphql-tools/utils';
3
+ import { dirname, extname, basename, relative, resolve } from 'path';
4
+ import debugFactory from 'debug';
5
+ import { loadConfigSync, GraphQLConfig } from 'graphql-config';
6
+ import { CodeFileLoader } from '@graphql-tools/code-file-loader';
2
7
  import { Kind, visit, validate, TokenKind, isScalarType, DirectiveLocation, isInterfaceType, TypeInfo, visitWithTypeInfo, isObjectType as isObjectType$1, Source, isNonNullType, isListType, GraphQLObjectType, GraphQLInterfaceType, GraphQLSchema, GraphQLError } from 'graphql';
3
8
  import { validateSDL } from 'graphql/validation/validate';
4
9
  import { statSync, existsSync, readFileSync } from 'fs';
5
- import { dirname, extname, basename, relative, resolve } from 'path';
6
10
  import lowerCase from 'lodash.lowercase';
7
11
  import chalk from 'chalk';
8
- import { getDocumentNodeFromSchema, asArray, parseGraphQLSDL } from '@graphql-tools/utils';
9
12
  import { valueFromASTUntyped } from 'graphql/utilities/valueFromASTUntyped';
10
13
  import depthLimit from 'graphql-depth-limit';
11
- import debugFactory from 'debug';
12
14
  import fastGlob from 'fast-glob';
13
- import { loadConfigSync, GraphQLConfig } from 'graphql-config';
14
- import { CodeFileLoader } from '@graphql-tools/code-file-loader';
15
15
  import { RuleTester, Linter } from 'eslint';
16
16
  import { codeFrameColumns } from '@babel/code-frame';
17
17
 
18
- const RELEVANT_KEYWORDS = ['gql', 'graphql', '/* GraphQL */'];
18
+ const debug = debugFactory('graphql-eslint:graphql-config');
19
+ let graphQLConfig;
20
+ function loadGraphQLConfig(options = {}) {
21
+ // We don't want cache config on test environment
22
+ // Otherwise schema and documents will be same for all tests
23
+ if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
24
+ return graphQLConfig;
25
+ }
26
+ const onDiskConfig = options.skipGraphQLConfig
27
+ ? null
28
+ : loadConfigSync({
29
+ // load config relative to the file being linted
30
+ rootDir: options.filePath ? dirname(options.filePath) : undefined,
31
+ throwOnEmpty: false,
32
+ throwOnMissing: false,
33
+ extensions: [addCodeFileLoaderExtension],
34
+ });
35
+ debug('options.skipGraphQLConfig: %o', options.skipGraphQLConfig);
36
+ if (onDiskConfig) {
37
+ debug('Graphql-config path %o', onDiskConfig.filepath);
38
+ }
39
+ const configOptions = options.projects
40
+ ? { projects: options.projects }
41
+ : {
42
+ schema: (options.schema || ''),
43
+ documents: options.documents || options.operations,
44
+ extensions: options.extensions,
45
+ include: options.include,
46
+ exclude: options.exclude,
47
+ };
48
+ graphQLConfig =
49
+ onDiskConfig ||
50
+ new GraphQLConfig({
51
+ config: configOptions,
52
+ filepath: 'virtual-config',
53
+ }, [addCodeFileLoaderExtension]);
54
+ return graphQLConfig;
55
+ }
56
+ const addCodeFileLoaderExtension = api => {
57
+ api.loaders.schema.register(new CodeFileLoader());
58
+ api.loaders.documents.register(new CodeFileLoader());
59
+ return { name: 'graphql-eslint-loaders' };
60
+ };
61
+
62
+ var _a, _b;
63
+ const graphQLTagPluckOptions = (_b = (_a = loadGraphQLConfig().getDefault()) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.graphqlTagPluck;
64
+ const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = graphQLTagPluckOptions || {};
65
+ const RELEVANT_KEYWORDS = [
66
+ ...new Set([
67
+ ...modules.map(({ identifier }) => identifier),
68
+ ...asArray(globalGqlIdentifierName),
69
+ gqlMagicComment,
70
+ ].filter(Boolean)),
71
+ ];
19
72
  const blocksMap = new Map();
20
73
  const processor = {
21
74
  supportsAutofix: true,
@@ -27,8 +80,8 @@ const processor = {
27
80
  code,
28
81
  filePath,
29
82
  options: {
30
- globalGqlIdentifierName: ['gql', 'graphql'],
31
83
  skipIndent: true,
84
+ ...graphQLTagPluckOptions,
32
85
  },
33
86
  });
34
87
  const blocks = extractedDocuments.map(item => ({
@@ -4200,7 +4253,7 @@ const rules = {
4200
4253
  };
4201
4254
 
4202
4255
  const schemaCache = new Map();
4203
- const debug = debugFactory('graphql-eslint:schema');
4256
+ const debug$1 = debugFactory('graphql-eslint:schema');
4204
4257
  function getSchema(projectForFile, options = {}) {
4205
4258
  const schemaKey = asArray(projectForFile.schema).sort().join(',');
4206
4259
  if (!schemaKey) {
@@ -4211,14 +4264,14 @@ function getSchema(projectForFile, options = {}) {
4211
4264
  }
4212
4265
  let schema;
4213
4266
  try {
4214
- debug('Loading schema from %o', projectForFile.schema);
4267
+ debug$1('Loading schema from %o', projectForFile.schema);
4215
4268
  schema = projectForFile.loadSchemaSync(projectForFile.schema, 'GraphQLSchema', options.schemaOptions);
4216
- if (debug.enabled) {
4217
- debug('Schema loaded: %o', schema instanceof GraphQLSchema);
4269
+ if (debug$1.enabled) {
4270
+ debug$1('Schema loaded: %o', schema instanceof GraphQLSchema);
4218
4271
  const schemaPaths = fastGlob.sync(projectForFile.schema, {
4219
4272
  absolute: true,
4220
4273
  });
4221
- debug('Schema pointers %O', schemaPaths);
4274
+ debug$1('Schema pointers %O', schemaPaths);
4222
4275
  }
4223
4276
  }
4224
4277
  catch (error) {
@@ -4229,7 +4282,7 @@ function getSchema(projectForFile, options = {}) {
4229
4282
  return schema;
4230
4283
  }
4231
4284
 
4232
- const debug$1 = debugFactory('graphql-eslint:operations');
4285
+ const debug$2 = debugFactory('graphql-eslint:operations');
4233
4286
  const handleVirtualPath = (documents) => {
4234
4287
  const filepathMap = Object.create(null);
4235
4288
  return documents.map(source => {
@@ -4255,16 +4308,16 @@ const getSiblings = (projectForFile) => {
4255
4308
  }
4256
4309
  let siblings = operationsCache.get(documentsKey);
4257
4310
  if (!siblings) {
4258
- debug$1('Loading operations from %o', projectForFile.documents);
4311
+ debug$2('Loading operations from %o', projectForFile.documents);
4259
4312
  const documents = projectForFile.loadDocumentsSync(projectForFile.documents, {
4260
4313
  skipGraphQLImport: true,
4261
4314
  });
4262
- if (debug$1.enabled) {
4263
- debug$1('Loaded %d operations', documents.length);
4315
+ if (debug$2.enabled) {
4316
+ debug$2('Loaded %d operations', documents.length);
4264
4317
  const operationsPaths = fastGlob.sync(projectForFile.documents, {
4265
4318
  absolute: true,
4266
4319
  });
4267
- debug$1('Operations pointers %O', operationsPaths);
4320
+ debug$2('Operations pointers %O', operationsPaths);
4268
4321
  }
4269
4322
  siblings = handleVirtualPath(documents);
4270
4323
  operationsCache.set(documentsKey, siblings);
@@ -4369,50 +4422,6 @@ function getSiblingOperations(projectForFile) {
4369
4422
  return siblingOperations;
4370
4423
  }
4371
4424
 
4372
- const debug$2 = debugFactory('graphql-eslint:graphql-config');
4373
- let graphQLConfig;
4374
- function loadGraphQLConfig(options) {
4375
- // We don't want cache config on test environment
4376
- // Otherwise schema and documents will be same for all tests
4377
- if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
4378
- return graphQLConfig;
4379
- }
4380
- const onDiskConfig = options.skipGraphQLConfig
4381
- ? null
4382
- : loadConfigSync({
4383
- // load config relative to the file being linted
4384
- rootDir: options.filePath ? dirname(options.filePath) : undefined,
4385
- throwOnEmpty: false,
4386
- throwOnMissing: false,
4387
- extensions: [addCodeFileLoaderExtension],
4388
- });
4389
- debug$2('options.skipGraphQLConfig: %o', options.skipGraphQLConfig);
4390
- if (onDiskConfig) {
4391
- debug$2('Graphql-config path %o', onDiskConfig.filepath);
4392
- }
4393
- const configOptions = options.projects
4394
- ? { projects: options.projects }
4395
- : {
4396
- schema: (options.schema || ''),
4397
- documents: options.documents || options.operations,
4398
- extensions: options.extensions,
4399
- include: options.include,
4400
- exclude: options.exclude,
4401
- };
4402
- graphQLConfig =
4403
- onDiskConfig ||
4404
- new GraphQLConfig({
4405
- config: configOptions,
4406
- filepath: 'virtual-config',
4407
- }, [addCodeFileLoaderExtension]);
4408
- return graphQLConfig;
4409
- }
4410
- const addCodeFileLoaderExtension = api => {
4411
- api.loaders.schema.register(new CodeFileLoader());
4412
- api.loaders.documents.register(new CodeFileLoader());
4413
- return { name: 'graphql-eslint-loaders' };
4414
- };
4415
-
4416
4425
  const debug$3 = debugFactory('graphql-eslint:parser');
4417
4426
  debug$3('cwd %o', process.cwd());
4418
4427
  function parseForESLint(code, options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "3.11.0-alpha-20220923194422-95bf79f",
3
+ "version": "3.11.0",
4
4
  "description": "GraphQL plugin for ESLint",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
package/processor.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import type { Linter } from 'eslint';
2
- declare type Block = Linter.ProcessorFile & {
1
+ import { Linter } from 'eslint';
2
+ export declare type Block = Linter.ProcessorFile & {
3
3
  lineOffset: number;
4
4
  offset: number;
5
5
  };
6
6
  export declare const processor: Linter.Processor<Block | string>;
7
- export {};