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

Sign up to get free protection for your applications and to get access to all the features.
@@ -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: path.dirname(filePath),
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);
@@ -71,9 +72,10 @@ const blocksMap = new Map();
71
72
  const processor = {
72
73
  supportsAutofix: true,
73
74
  preprocess(code, filePath) {
74
- var _a, _b;
75
+ var _a, _b, _c;
75
76
  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
+ 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;
77
79
  const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = graphQLTagPluckOptions || {};
78
80
  RELEVANT_KEYWORDS = [
79
81
  ...new Set([
@@ -104,7 +106,7 @@ const processor = {
104
106
  blocksMap.set(filePath, blocks);
105
107
  return [...blocks, code /* source code must be provided and be last */];
106
108
  }
107
- catch (_c) {
109
+ catch (_d) {
108
110
  // in case of parsing error return code as is
109
111
  return [code];
110
112
  }
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: dirname(filePath),
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);
@@ -65,9 +66,10 @@ const blocksMap = new Map();
65
66
  const processor = {
66
67
  supportsAutofix: true,
67
68
  preprocess(code, filePath) {
68
- var _a, _b;
69
+ var _a, _b, _c;
69
70
  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
+ 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;
71
73
  const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = graphQLTagPluckOptions || {};
72
74
  RELEVANT_KEYWORDS = [
73
75
  ...new Set([
@@ -98,7 +100,7 @@ const processor = {
98
100
  blocksMap.set(filePath, blocks);
99
101
  return [...blocks, code /* source code must be provided and be last */];
100
102
  }
101
- catch (_c) {
103
+ catch (_d) {
102
104
  // in case of parsing error return code as is
103
105
  return [code];
104
106
  }
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-20220926143611-7437e15",
4
4
  "description": "GraphQL plugin for ESLint",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {