@graphql-eslint/eslint-plugin 3.14.1 → 3.14.2-alpha-20221227181549-bdccde8

Sign up to get free protection for your applications and to get access to all the features.
package/cjs/processor.js CHANGED
@@ -4,6 +4,7 @@ exports.processor = void 0;
4
4
  const graphql_tag_pluck_1 = require("@graphql-tools/graphql-tag-pluck");
5
5
  const utils_1 = require("@graphql-tools/utils");
6
6
  const graphql_config_js_1 = require("./graphql-config.js");
7
+ const utils_js_1 = require("./utils.js");
7
8
  const blocksMap = new Map();
8
9
  let onDiskConfig;
9
10
  let onDiskConfigLoaded = false;
@@ -35,18 +36,19 @@ exports.processor = {
35
36
  skipIndent: true,
36
37
  ...pluckConfig,
37
38
  });
38
- const isSvelte = filePath.endsWith('.svelte');
39
39
  const blocks = sources.map(item => ({
40
40
  filename: 'document.graphql',
41
41
  text: item.body,
42
- lineOffset: item.locationOffset.line - (isSvelte ? 3 : 1),
42
+ lineOffset: item.locationOffset.line - 1,
43
43
  // @ts-expect-error -- `index` field exist but show ts error
44
- offset: item.locationOffset.index + (isSvelte ? -52 : 1),
44
+ offset: item.locationOffset.index + 1,
45
45
  }));
46
46
  blocksMap.set(filePath, blocks);
47
47
  return [...blocks, code /* source code must be provided and be last */];
48
48
  }
49
- catch (_a) {
49
+ catch (e) {
50
+ // eslint-disable-next-line no-console
51
+ console.error(e);
50
52
  // in case of parsing error return code as is
51
53
  return [code];
52
54
  }
@@ -55,7 +57,18 @@ exports.processor = {
55
57
  const blocks = blocksMap.get(filePath) || [];
56
58
  for (let i = 0; i < blocks.length; i += 1) {
57
59
  const { lineOffset, offset } = blocks[i];
58
- for (const message of messages[i]) {
60
+ for (const message of messages[i] || []) {
61
+ const isVueOrSvelte = /\.(vue|svelte)$/.test(filePath);
62
+ if (isVueOrSvelte) {
63
+ // We can't show correct report location because after processing with
64
+ // graphql-tag-pluck location is incorrect, disable fixes as well
65
+ delete message.endLine;
66
+ delete message.endColumn;
67
+ delete message.fix;
68
+ delete message.suggestions;
69
+ Object.assign(message, utils_js_1.REPORT_ON_FIRST_CHARACTER);
70
+ continue;
71
+ }
59
72
  message.line += lineOffset;
60
73
  // endLine can not exist if only `loc: { start, column }` was provided to context.report
61
74
  if (typeof message.endLine === 'number') {
package/esm/processor.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { gqlPluckFromCodeStringSync, } from '@graphql-tools/graphql-tag-pluck';
2
2
  import { asArray } from '@graphql-tools/utils';
3
3
  import { loadOnDiskGraphQLConfig } from './graphql-config.js';
4
+ import { REPORT_ON_FIRST_CHARACTER } from './utils.js';
4
5
  const blocksMap = new Map();
5
6
  let onDiskConfig;
6
7
  let onDiskConfigLoaded = false;
@@ -32,18 +33,19 @@ export const processor = {
32
33
  skipIndent: true,
33
34
  ...pluckConfig,
34
35
  });
35
- const isSvelte = filePath.endsWith('.svelte');
36
36
  const blocks = sources.map(item => ({
37
37
  filename: 'document.graphql',
38
38
  text: item.body,
39
- lineOffset: item.locationOffset.line - (isSvelte ? 3 : 1),
39
+ lineOffset: item.locationOffset.line - 1,
40
40
  // @ts-expect-error -- `index` field exist but show ts error
41
- offset: item.locationOffset.index + (isSvelte ? -52 : 1),
41
+ offset: item.locationOffset.index + 1,
42
42
  }));
43
43
  blocksMap.set(filePath, blocks);
44
44
  return [...blocks, code /* source code must be provided and be last */];
45
45
  }
46
- catch (_a) {
46
+ catch (e) {
47
+ // eslint-disable-next-line no-console
48
+ console.error(e);
47
49
  // in case of parsing error return code as is
48
50
  return [code];
49
51
  }
@@ -52,7 +54,18 @@ export const processor = {
52
54
  const blocks = blocksMap.get(filePath) || [];
53
55
  for (let i = 0; i < blocks.length; i += 1) {
54
56
  const { lineOffset, offset } = blocks[i];
55
- for (const message of messages[i]) {
57
+ for (const message of messages[i] || []) {
58
+ const isVueOrSvelte = /\.(vue|svelte)$/.test(filePath);
59
+ if (isVueOrSvelte) {
60
+ // We can't show correct report location because after processing with
61
+ // graphql-tag-pluck location is incorrect, disable fixes as well
62
+ delete message.endLine;
63
+ delete message.endColumn;
64
+ delete message.fix;
65
+ delete message.suggestions;
66
+ Object.assign(message, REPORT_ON_FIRST_CHARACTER);
67
+ continue;
68
+ }
56
69
  message.line += lineOffset;
57
70
  // endLine can not exist if only `loc: { start, column }` was provided to context.report
58
71
  if (typeof message.endLine === 'number') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "3.14.1",
3
+ "version": "3.14.2-alpha-20221227181549-bdccde8",
4
4
  "description": "GraphQL plugin for ESLint",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {