Source code fixer doesn't remove sequential ranges
See original GitHub issueTell us about your environment
- ESLint Version: 5.1.0
- Node Version: 10.6.0
- npm Version: 6.1.0
What parser (default, Babel-ESLint, etc.) are you using? default Please show your full configuration: I cloned eslint repo.
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
I’m developing fixer for no-unused-var
rule. Fixer should remove unused method parameters. Fixer removes one parameter (sometimes with comma) per error. Error is reported for each unused argument.
SourceCodeFixer
should successfully remove sequential ranges, but SourceCodeFixer
recognizes them as overlaps.
I wrote test for SourceCodeFixer
:
const REMOVE_A = {
message: "removea",
fix: {
range: [11, 12],
text: ""
}
};
const REMOVE_B = {
message: "removeb",
fix: {
range: [12, 15],
text: ""
}
};
const REMOVE_C = {
message: "removec",
fix: {
range: [15, 18],
text: ""
}
};
it("should remove text consistently", () => {
const result = SourceCodeFixer.applyFixes('function f(a, b, c) {}', [REMOVE_A, REMOVE_B, REMOVE_C]);
assert.strictEqual(result.output, "function f() {}");
assert.isTrue(result.fixed);
});
What did you expect to happen?
Test should be successful. Output should be "function f() {}"
.
What actually happened? Please include the actual, raw output from ESLint.
Test is failed. Output is "function f(, b) {}"
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (12 by maintainers)
Top GitHub Comments
I’m not sure this is a big problem because ESLint runs rules multiple times when autofixing, so the variable
b
will simply be removed on the next pass when the rule gets run again.It’s true that it would be safe to apply all the fixes in this case, but I’m not sure it’s safe to apply all the fixes in all other cases. I would rather be conservative here.
Yes.