feat(unstable): support multiple fixes from lint plugins (#28040)

This PR supports returning multiple changes from a lint fix. It works
the same way as eslint, see
https://eslint.org/docs/latest/extend/custom-rules#applying-fixes .

- Return a single fix
- Return an array of fixes
- Return a generator function with fixes
This commit is contained in:
Marvin Hagemeister 2025-02-11 15:24:28 +01:00 committed by GitHub
parent 196ceb76bb
commit aead459fb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 111 additions and 20 deletions

View file

@ -234,11 +234,20 @@ export class Context {
const start = range[0];
const end = range[1];
let fix;
/** @type {Deno.lint.FixData[]} */
const fixes = [];
if (typeof data.fix === "function") {
const fixer = new Fixer();
fix = data.fix(fixer);
const result = data.fix(fixer);
if (Symbol.iterator in result) {
for (const fix of result) {
fixes.push(fix);
}
} else {
fixes.push(result);
}
}
doReport(
@ -247,7 +256,7 @@ export class Context {
data.hint,
start,
end,
fix,
fixes,
);
}
}