mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
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:
parent
196ceb76bb
commit
aead459fb2
10 changed files with 111 additions and 20 deletions
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue