@graphql-eslint/eslint-plugin 3.12.0-alpha-20221008232037-33da317 → 3.12.0-alpha-20221009195322-d8a697f

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 +21 -21
  2. package/index.mjs +21 -21
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -78,44 +78,44 @@ const codeFileLoaderExtension = (pluckConfig) => api => {
78
78
 
79
79
  const blocksMap = new Map();
80
80
  let onDiskConfig;
81
- let pluckConfig;
82
- let RELEVANT_KEYWORDS;
81
+ let onDiskConfigLoaded = false;
83
82
  const processor = {
84
83
  supportsAutofix: true,
85
84
  preprocess(code, filePath) {
86
- if (!pluckConfig) {
85
+ var _a;
86
+ if (!onDiskConfigLoaded) {
87
87
  onDiskConfig = loadOnDiskGraphQLConfig(filePath);
88
- const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = (onDiskConfig === null || onDiskConfig === void 0 ? void 0 : onDiskConfig.getProjectForFile(filePath).extensions.pluckConfig) || {};
89
- pluckConfig = {
90
- skipIndent: true,
91
- modules,
92
- globalGqlIdentifierName,
93
- gqlMagicComment,
94
- };
95
- RELEVANT_KEYWORDS = [
96
- ...new Set([
97
- ...modules.map(({ identifier }) => identifier),
98
- ...utils.asArray(globalGqlIdentifierName),
99
- gqlMagicComment,
100
- ].filter(Boolean)),
101
- ];
88
+ onDiskConfigLoaded = true;
102
89
  }
90
+ const pluckConfig = (_a = onDiskConfig === null || onDiskConfig === void 0 ? void 0 : onDiskConfig.getProjectForFile(filePath).extensions) === null || _a === void 0 ? void 0 : _a.pluckConfig;
91
+ const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = pluckConfig || {};
92
+ const RELEVANT_KEYWORDS = [
93
+ ...new Set([
94
+ ...modules.map(({ identifier }) => identifier),
95
+ ...utils.asArray(globalGqlIdentifierName),
96
+ gqlMagicComment,
97
+ ].filter(Boolean)),
98
+ ];
103
99
  if (RELEVANT_KEYWORDS.every(keyword => !code.includes(keyword))) {
104
100
  return [code];
105
101
  }
106
102
  try {
107
- const sources = graphqlTagPluck.gqlPluckFromCodeStringSync(filePath, code, pluckConfig);
103
+ const sources = graphqlTagPluck.gqlPluckFromCodeStringSync(filePath, code, {
104
+ skipIndent: true,
105
+ ...pluckConfig,
106
+ });
107
+ const isSvelte = filePath.endsWith('.svelte');
108
108
  const blocks = sources.map(item => ({
109
109
  filename: 'document.graphql',
110
110
  text: item.body,
111
- lineOffset: item.locationOffset.line - 1,
111
+ lineOffset: item.locationOffset.line - (isSvelte ? 3 : 1),
112
112
  // @ts-expect-error -- `index` field exist but show ts error
113
- offset: item.locationOffset.index + 1,
113
+ offset: item.locationOffset.index + (isSvelte ? -52 : 1),
114
114
  }));
115
115
  blocksMap.set(filePath, blocks);
116
116
  return [...blocks, code /* source code must be provided and be last */];
117
117
  }
118
- catch (_a) {
118
+ catch (_b) {
119
119
  // in case of parsing error return code as is
120
120
  return [code];
121
121
  }
package/index.mjs CHANGED
@@ -72,44 +72,44 @@ const codeFileLoaderExtension = (pluckConfig) => api => {
72
72
 
73
73
  const blocksMap = new Map();
74
74
  let onDiskConfig;
75
- let pluckConfig;
76
- let RELEVANT_KEYWORDS;
75
+ let onDiskConfigLoaded = false;
77
76
  const processor = {
78
77
  supportsAutofix: true,
79
78
  preprocess(code, filePath) {
80
- if (!pluckConfig) {
79
+ var _a;
80
+ if (!onDiskConfigLoaded) {
81
81
  onDiskConfig = loadOnDiskGraphQLConfig(filePath);
82
- const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = (onDiskConfig === null || onDiskConfig === void 0 ? void 0 : onDiskConfig.getProjectForFile(filePath).extensions.pluckConfig) || {};
83
- pluckConfig = {
84
- skipIndent: true,
85
- modules,
86
- globalGqlIdentifierName,
87
- gqlMagicComment,
88
- };
89
- RELEVANT_KEYWORDS = [
90
- ...new Set([
91
- ...modules.map(({ identifier }) => identifier),
92
- ...asArray(globalGqlIdentifierName),
93
- gqlMagicComment,
94
- ].filter(Boolean)),
95
- ];
82
+ onDiskConfigLoaded = true;
96
83
  }
84
+ const pluckConfig = (_a = onDiskConfig === null || onDiskConfig === void 0 ? void 0 : onDiskConfig.getProjectForFile(filePath).extensions) === null || _a === void 0 ? void 0 : _a.pluckConfig;
85
+ const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = pluckConfig || {};
86
+ const RELEVANT_KEYWORDS = [
87
+ ...new Set([
88
+ ...modules.map(({ identifier }) => identifier),
89
+ ...asArray(globalGqlIdentifierName),
90
+ gqlMagicComment,
91
+ ].filter(Boolean)),
92
+ ];
97
93
  if (RELEVANT_KEYWORDS.every(keyword => !code.includes(keyword))) {
98
94
  return [code];
99
95
  }
100
96
  try {
101
- const sources = gqlPluckFromCodeStringSync(filePath, code, pluckConfig);
97
+ const sources = gqlPluckFromCodeStringSync(filePath, code, {
98
+ skipIndent: true,
99
+ ...pluckConfig,
100
+ });
101
+ const isSvelte = filePath.endsWith('.svelte');
102
102
  const blocks = sources.map(item => ({
103
103
  filename: 'document.graphql',
104
104
  text: item.body,
105
- lineOffset: item.locationOffset.line - 1,
105
+ lineOffset: item.locationOffset.line - (isSvelte ? 3 : 1),
106
106
  // @ts-expect-error -- `index` field exist but show ts error
107
- offset: item.locationOffset.index + 1,
107
+ offset: item.locationOffset.index + (isSvelte ? -52 : 1),
108
108
  }));
109
109
  blocksMap.set(filePath, blocks);
110
110
  return [...blocks, code /* source code must be provided and be last */];
111
111
  }
112
- catch (_a) {
112
+ catch (_b) {
113
113
  // in case of parsing error return code as is
114
114
  return [code];
115
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "3.12.0-alpha-20221008232037-33da317",
3
+ "version": "3.12.0-alpha-20221009195322-d8a697f",
4
4
  "description": "GraphQL plugin for ESLint",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -14,7 +14,7 @@
14
14
  "chalk": "^4.1.2",
15
15
  "debug": "^4.3.4",
16
16
  "fast-glob": "^3.2.12",
17
- "graphql-config": "^4.3.5",
17
+ "graphql-config": "^4.3.6",
18
18
  "graphql-depth-limit": "^1.1.0",
19
19
  "lodash.lowercase": "^4.3.0"
20
20
  },