Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/seven-cobras-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix broken suggestions on code files when there are multiple choices
16 changes: 11 additions & 5 deletions packages/plugin/src/processor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Linter } from 'eslint';
import { relative } from 'path';
import {
gqlPluckFromCodeStringSync,
GraphQLTagPluckOptions,
} from '@graphql-tools/graphql-tag-pluck';
import { asArray } from '@graphql-tools/utils';
import { GraphQLConfig } from 'graphql-config';
import { loadOnDiskGraphQLConfig } from './graphql-config.js';
import { REPORT_ON_FIRST_CHARACTER } from './utils.js';
import { CWD, REPORT_ON_FIRST_CHARACTER } from './utils.js';

export type Block = Linter.ProcessorFile & {
lineOffset: number;
Expand Down Expand Up @@ -70,9 +71,13 @@ export const processor: Linter.Processor<Block | string> = {
blocksMap.set(filePath, blocks);

return [...blocks, code /* source code must be provided and be last */];
} catch (e) {
} catch (error) {
error.message = `[graphql-eslint] Error while preprocessing "${relative(
CWD,
filePath,
)}" file\n\n${error.message}`;
// eslint-disable-next-line no-console
console.error(e);
console.error(error);
// in case of parsing error return code as is
return [code];
}
Expand Down Expand Up @@ -105,8 +110,9 @@ export const processor: Linter.Processor<Block | string> = {
message.fix.range[1] += offset;
}
for (const suggestion of message.suggestions || []) {
suggestion.fix.range[0] += offset;
suggestion.fix.range[1] += offset;
// DO NOT mutate until https://github.com/eslint/eslint/issues/16716
const [start, end] = suggestion.fix.range;
suggestion.fix.range = [start + offset, end + offset];
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin/tests/__snapshots__/examples.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ exports[`Examples > should work in monorepo 1`] = `
desc: Rename to \`firstName\`,
fix: {
range: [
164,
173,
131,
140,
],
text: firstName,
},
Expand All @@ -67,8 +67,8 @@ exports[`Examples > should work in monorepo 1`] = `
desc: Rename to \`lastName\`,
fix: {
range: [
164,
173,
131,
140,
],
text: lastName,
},
Expand Down