@graphql-eslint/eslint-plugin 3.11.2-alpha-20220926143611-7437e15 → 3.11.2-alpha-20220926144959-f269795

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.js +14 -17
  2. package/index.mjs +14 -17
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -26,7 +26,7 @@ let graphQLConfig;
26
26
  function loadOnDiskGraphQLConfig(filePath) {
27
27
  return graphqlConfig.loadConfigSync({
28
28
  // load config relative to the file being linted
29
- rootDir: path.dirname(filePath),
29
+ rootDir: filePath ? path.dirname(filePath) : undefined,
30
30
  throwOnEmpty: false,
31
31
  throwOnMissing: false,
32
32
  extensions: [addCodeFileLoaderExtension],
@@ -66,25 +66,22 @@ const addCodeFileLoaderExtension = api => {
66
66
  return { name: 'graphql-eslint-loaders' };
67
67
  };
68
68
 
69
- let RELEVANT_KEYWORDS;
70
- let graphQLTagPluckOptions;
71
69
  const blocksMap = new Map();
70
+ let onDiskConfig;
72
71
  const processor = {
73
72
  supportsAutofix: true,
74
73
  preprocess(code, filePath) {
75
- var _a, _b, _c;
76
- if (!RELEVANT_KEYWORDS) {
77
- graphQLTagPluckOptions =
78
- (_c = (_b = (_a = loadOnDiskGraphQLConfig(filePath)) === null || _a === void 0 ? void 0 : _a.getDefault()) === null || _b === void 0 ? void 0 : _b.extensions) === null || _c === void 0 ? void 0 : _c.graphqlTagPluck;
79
- const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = graphQLTagPluckOptions || {};
80
- RELEVANT_KEYWORDS = [
81
- ...new Set([
82
- ...modules.map(({ identifier }) => identifier),
83
- ...utils.asArray(globalGqlIdentifierName),
84
- gqlMagicComment,
85
- ].filter(Boolean)),
86
- ];
87
- }
74
+ var _a, _b;
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
+ ];
88
85
  if (RELEVANT_KEYWORDS.every(keyword => !code.includes(keyword))) {
89
86
  return [code];
90
87
  }
@@ -106,7 +103,7 @@ const processor = {
106
103
  blocksMap.set(filePath, blocks);
107
104
  return [...blocks, code /* source code must be provided and be last */];
108
105
  }
109
- catch (_d) {
106
+ catch (_c) {
110
107
  // in case of parsing error return code as is
111
108
  return [code];
112
109
  }
package/index.mjs CHANGED
@@ -20,7 +20,7 @@ let graphQLConfig;
20
20
  function loadOnDiskGraphQLConfig(filePath) {
21
21
  return loadConfigSync({
22
22
  // load config relative to the file being linted
23
- rootDir: dirname(filePath),
23
+ rootDir: filePath ? dirname(filePath) : undefined,
24
24
  throwOnEmpty: false,
25
25
  throwOnMissing: false,
26
26
  extensions: [addCodeFileLoaderExtension],
@@ -60,25 +60,22 @@ const addCodeFileLoaderExtension = api => {
60
60
  return { name: 'graphql-eslint-loaders' };
61
61
  };
62
62
 
63
- let RELEVANT_KEYWORDS;
64
- let graphQLTagPluckOptions;
65
63
  const blocksMap = new Map();
64
+ let onDiskConfig;
66
65
  const processor = {
67
66
  supportsAutofix: true,
68
67
  preprocess(code, filePath) {
69
- var _a, _b, _c;
70
- if (!RELEVANT_KEYWORDS) {
71
- graphQLTagPluckOptions =
72
- (_c = (_b = (_a = loadOnDiskGraphQLConfig(filePath)) === null || _a === void 0 ? void 0 : _a.getDefault()) === null || _b === void 0 ? void 0 : _b.extensions) === null || _c === void 0 ? void 0 : _c.graphqlTagPluck;
73
- const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = graphQLTagPluckOptions || {};
74
- RELEVANT_KEYWORDS = [
75
- ...new Set([
76
- ...modules.map(({ identifier }) => identifier),
77
- ...asArray(globalGqlIdentifierName),
78
- gqlMagicComment,
79
- ].filter(Boolean)),
80
- ];
81
- }
68
+ var _a, _b;
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
+ ];
82
79
  if (RELEVANT_KEYWORDS.every(keyword => !code.includes(keyword))) {
83
80
  return [code];
84
81
  }
@@ -100,7 +97,7 @@ const processor = {
100
97
  blocksMap.set(filePath, blocks);
101
98
  return [...blocks, code /* source code must be provided and be last */];
102
99
  }
103
- catch (_d) {
100
+ catch (_c) {
104
101
  // in case of parsing error return code as is
105
102
  return [code];
106
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "3.11.2-alpha-20220926143611-7437e15",
3
+ "version": "3.11.2-alpha-20220926144959-f269795",
4
4
  "description": "GraphQL plugin for ESLint",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {