|
1 | 1 | import { Linter } from 'eslint';
|
| 2 | +import { relative } from 'path'; |
2 | 3 | import {
|
3 | 4 | gqlPluckFromCodeStringSync,
|
4 | 5 | GraphQLTagPluckOptions,
|
5 | 6 | } from '@graphql-tools/graphql-tag-pluck';
|
6 | 7 | import { asArray } from '@graphql-tools/utils';
|
7 | 8 | import { GraphQLConfig } from 'graphql-config';
|
8 | 9 | import { loadOnDiskGraphQLConfig } from './graphql-config.js';
|
9 |
| -import { REPORT_ON_FIRST_CHARACTER } from './utils.js'; |
| 10 | +import { CWD, REPORT_ON_FIRST_CHARACTER } from './utils.js'; |
10 | 11 |
|
11 | 12 | export type Block = Linter.ProcessorFile & {
|
12 | 13 | lineOffset: number;
|
@@ -70,9 +71,13 @@ export const processor: Linter.Processor<Block | string> = {
|
70 | 71 | blocksMap.set(filePath, blocks);
|
71 | 72 |
|
72 | 73 | return [...blocks, code /* source code must be provided and be last */];
|
73 |
| - } catch (e) { |
| 74 | + } catch (error) { |
| 75 | + error.message = `[graphql-eslint] Error while preprocessing "${relative( |
| 76 | + CWD, |
| 77 | + filePath, |
| 78 | + )}" file\n\n${error.message}`; |
74 | 79 | // eslint-disable-next-line no-console
|
75 |
| - console.error(e); |
| 80 | + console.error(error); |
76 | 81 | // in case of parsing error return code as is
|
77 | 82 | return [code];
|
78 | 83 | }
|
@@ -105,8 +110,9 @@ export const processor: Linter.Processor<Block | string> = {
|
105 | 110 | message.fix.range[1] += offset;
|
106 | 111 | }
|
107 | 112 | for (const suggestion of message.suggestions || []) {
|
108 |
| - suggestion.fix.range[0] += offset; |
109 |
| - suggestion.fix.range[1] += offset; |
| 113 | + // DO NOT mutate until https://github.com/eslint/eslint/issues/16716 |
| 114 | + const [start, end] = suggestion.fix.range; |
| 115 | + suggestion.fix.range = [start + offset, end + offset]; |
110 | 116 | }
|
111 | 117 | }
|
112 | 118 | }
|
|
0 commit comments