Skip to content

Commit

Permalink
Added supportsAutofix to the processor (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
arusanov authored Nov 29, 2020
1 parent 1a201c4 commit c9bbdbe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/lucky-eggs-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@graphql-eslint/eslint-plugin": patch
---

Added `supportsAutofix` to the processor.
Fixes can be applied in JS,TS files now.
9 changes: 8 additions & 1 deletion packages/plugin/src/processors/code-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ type Block = {
text: string;
filename: string;
lineOffset?: number;
offset?: number;
};

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

return {
supportsAutofix: true,
preprocess: (text: string, filename: string): Array<{ text: string; filename: string }> => {
const blocks: Block[] = [];
blocksMap.set(filename, blocks);
Expand All @@ -41,6 +43,7 @@ export function createGraphqlProcessor() {
filename: `document.graphql`,
text: item.content,
lineOffset: item.loc.start.line - 1,
offset: item.start + 1,
});
}

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

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

if (message.endLine != null) {
message.endLine += lineOffset;
}
if (message.fix && typeof offset !== 'undefined') {
message.fix.range[0] = offset + message.fix.range[0];
message.fix.range[1] = offset + message.fix.range[1];
}
}
}
}
Expand Down

0 comments on commit c9bbdbe

Please sign in to comment.