@graphql-eslint/eslint-plugin 3.11.1 → 3.11.2-alpha-20220926144959-f269795

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
1
  import { GraphQLConfig } from 'graphql-config';
2
2
  import { ParserOptions } from './types';
3
+ export declare function loadOnDiskGraphQLConfig(filePath: string): GraphQLConfig;
3
4
  export declare function loadGraphQLConfig(options?: ParserOptions): GraphQLConfig;
package/index.js CHANGED
@@ -23,21 +23,22 @@ const codeFrame = require('@babel/code-frame');
23
23
 
24
24
  const debug = debugFactory('graphql-eslint:graphql-config');
25
25
  let graphQLConfig;
26
+ function loadOnDiskGraphQLConfig(filePath) {
27
+ return graphqlConfig.loadConfigSync({
28
+ // load config relative to the file being linted
29
+ rootDir: filePath ? path.dirname(filePath) : undefined,
30
+ throwOnEmpty: false,
31
+ throwOnMissing: false,
32
+ extensions: [addCodeFileLoaderExtension],
33
+ });
34
+ }
26
35
  function loadGraphQLConfig(options = {}) {
27
36
  // We don't want cache config on test environment
28
37
  // Otherwise schema and documents will be same for all tests
29
38
  if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
30
39
  return graphQLConfig;
31
40
  }
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
+ const onDiskConfig = !options.skipGraphQLConfig && loadOnDiskGraphQLConfig(options.filePath);
41
42
  debug('options.skipGraphQLConfig: %o', options.skipGraphQLConfig);
42
43
  if (onDiskConfig) {
43
44
  debug('Graphql-config path %o', onDiskConfig.filepath);
@@ -65,24 +66,22 @@ const addCodeFileLoaderExtension = api => {
65
66
  return { name: 'graphql-eslint-loaders' };
66
67
  };
67
68
 
68
- let RELEVANT_KEYWORDS;
69
- let graphQLTagPluckOptions;
70
69
  const blocksMap = new Map();
70
+ let onDiskConfig;
71
71
  const processor = {
72
72
  supportsAutofix: true,
73
73
  preprocess(code, filePath) {
74
74
  var _a, _b;
75
- if (!RELEVANT_KEYWORDS) {
76
- graphQLTagPluckOptions = (_b = (_a = loadGraphQLConfig().getDefault()) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.graphqlTagPluck;
77
- const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = graphQLTagPluckOptions || {};
78
- RELEVANT_KEYWORDS = [
79
- ...new Set([
80
- ...modules.map(({ identifier }) => identifier),
81
- ...utils.asArray(globalGqlIdentifierName),
82
- gqlMagicComment,
83
- ].filter(Boolean)),
84
- ];
85
- }
75
+ onDiskConfig || (onDiskConfig = loadOnDiskGraphQLConfig(filePath));
76
+ const graphQLTagPluckOptions = (_b = (_a = onDiskConfig === null || onDiskConfig === void 0 ? void 0 : onDiskConfig.getProjectForFile(filePath)) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.graphqlTagPluck;
77
+ const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = graphQLTagPluckOptions || {};
78
+ const RELEVANT_KEYWORDS = [
79
+ ...new Set([
80
+ ...modules.map(({ identifier }) => identifier),
81
+ ...utils.asArray(globalGqlIdentifierName),
82
+ gqlMagicComment,
83
+ ].filter(Boolean)),
84
+ ];
86
85
  if (RELEVANT_KEYWORDS.every(keyword => !code.includes(keyword))) {
87
86
  return [code];
88
87
  }
package/index.mjs CHANGED
@@ -17,21 +17,22 @@ import { codeFrameColumns } from '@babel/code-frame';
17
17
 
18
18
  const debug = debugFactory('graphql-eslint:graphql-config');
19
19
  let graphQLConfig;
20
+ function loadOnDiskGraphQLConfig(filePath) {
21
+ return loadConfigSync({
22
+ // load config relative to the file being linted
23
+ rootDir: filePath ? dirname(filePath) : undefined,
24
+ throwOnEmpty: false,
25
+ throwOnMissing: false,
26
+ extensions: [addCodeFileLoaderExtension],
27
+ });
28
+ }
20
29
  function loadGraphQLConfig(options = {}) {
21
30
  // We don't want cache config on test environment
22
31
  // Otherwise schema and documents will be same for all tests
23
32
  if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
24
33
  return graphQLConfig;
25
34
  }
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
+ const onDiskConfig = !options.skipGraphQLConfig && loadOnDiskGraphQLConfig(options.filePath);
35
36
  debug('options.skipGraphQLConfig: %o', options.skipGraphQLConfig);
36
37
  if (onDiskConfig) {
37
38
  debug('Graphql-config path %o', onDiskConfig.filepath);
@@ -59,24 +60,22 @@ const addCodeFileLoaderExtension = api => {
59
60
  return { name: 'graphql-eslint-loaders' };
60
61
  };
61
62
 
62
- let RELEVANT_KEYWORDS;
63
- let graphQLTagPluckOptions;
64
63
  const blocksMap = new Map();
64
+ let onDiskConfig;
65
65
  const processor = {
66
66
  supportsAutofix: true,
67
67
  preprocess(code, filePath) {
68
68
  var _a, _b;
69
- if (!RELEVANT_KEYWORDS) {
70
- graphQLTagPluckOptions = (_b = (_a = loadGraphQLConfig().getDefault()) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.graphqlTagPluck;
71
- const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = graphQLTagPluckOptions || {};
72
- RELEVANT_KEYWORDS = [
73
- ...new Set([
74
- ...modules.map(({ identifier }) => identifier),
75
- ...asArray(globalGqlIdentifierName),
76
- gqlMagicComment,
77
- ].filter(Boolean)),
78
- ];
79
- }
69
+ onDiskConfig || (onDiskConfig = loadOnDiskGraphQLConfig(filePath));
70
+ const graphQLTagPluckOptions = (_b = (_a = onDiskConfig === null || onDiskConfig === void 0 ? void 0 : onDiskConfig.getProjectForFile(filePath)) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.graphqlTagPluck;
71
+ const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = graphQLTagPluckOptions || {};
72
+ const RELEVANT_KEYWORDS = [
73
+ ...new Set([
74
+ ...modules.map(({ identifier }) => identifier),
75
+ ...asArray(globalGqlIdentifierName),
76
+ gqlMagicComment,
77
+ ].filter(Boolean)),
78
+ ];
80
79
  if (RELEVANT_KEYWORDS.every(keyword => !code.includes(keyword))) {
81
80
  return [code];
82
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "3.11.1",
3
+ "version": "3.11.2-alpha-20220926144959-f269795",
4
4
  "description": "GraphQL plugin for ESLint",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {