Skip to content

Commit c9bbdbe

Browse files
authored
Added supportsAutofix to the processor (#176)
1 parent 1a201c4 commit c9bbdbe

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.changeset/lucky-eggs-fetch.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@graphql-eslint/eslint-plugin": patch
3+
---
4+
5+
Added `supportsAutofix` to the processor.
6+
Fixes can be applied in JS,TS files now.

packages/plugin/src/processors/code-files.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ type Block = {
99
text: string;
1010
filename: string;
1111
lineOffset?: number;
12+
offset?: number;
1213
};
1314

1415
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1516
export function createGraphqlProcessor() {
1617
const blocksMap = new Map<string, Block[]>();
1718

1819
return {
20+
supportsAutofix: true,
1921
preprocess: (text: string, filename: string): Array<{ text: string; filename: string }> => {
2022
const blocks: Block[] = [];
2123
blocksMap.set(filename, blocks);
@@ -41,6 +43,7 @@ export function createGraphqlProcessor() {
4143
filename: `document.graphql`,
4244
text: item.content,
4345
lineOffset: item.loc.start.line - 1,
46+
offset: item.start + 1,
4447
});
4548
}
4649

@@ -58,14 +61,18 @@ export function createGraphqlProcessor() {
5861
if (blocks && blocks.length > 0) {
5962
for (let i = 0; i < messageLists.length; ++i) {
6063
const messages = messageLists[i];
61-
const { lineOffset } = blocks[i];
64+
const { lineOffset, offset } = blocks[i];
6265

6366
for (const message of messages) {
6467
message.line += lineOffset;
6568

6669
if (message.endLine != null) {
6770
message.endLine += lineOffset;
6871
}
72+
if (message.fix && typeof offset !== 'undefined') {
73+
message.fix.range[0] = offset + message.fix.range[0];
74+
message.fix.range[1] = offset + message.fix.range[1];
75+
}
6976
}
7077
}
7178
}

0 commit comments

Comments
 (0)