Skip to content

Commit

Permalink
Chore: add tests for extending fix ranges (refs #13706)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Oct 10, 2020
1 parent 551b1e9 commit 9373893
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/lib/linter/report-translator.js
Expand Up @@ -368,6 +368,35 @@ describe("createReportTranslator", () => {
);
});

it("should respect ranges of empty insertions when merging fixes to one.", () => {
const reportDescriptor = {
node,
loc: location,
message,
*fix() {
yield { range: [4, 5], text: "cd" };
yield { range: [2, 2], text: "" };
yield { range: [7, 7], text: "" };
}
};

assert.deepStrictEqual(
translateReport(reportDescriptor),
{
ruleId: "foo-rule",
severity: 2,
message: "foo",
line: 2,
column: 1,
nodeType: "ExpressionStatement",
fix: {
range: [2, 7],
text: "o\ncdar"
}
}
);
});

it("should pass through fixes if only one is present", () => {
const reportDescriptor = {
node,
Expand Down
44 changes: 44 additions & 0 deletions tests/lib/linter/rule-fixer.js
Expand Up @@ -30,6 +30,17 @@ describe("RuleFixer", () => {

});

it("should allow inserting empty text", () => {

const result = ruleFixer.insertTextBefore({ range: [10, 20] }, "");

assert.deepStrictEqual(result, {
range: [10, 10],
text: ""
});

});

});

describe("insertTextBeforeRange", () => {
Expand All @@ -45,6 +56,17 @@ describe("RuleFixer", () => {

});

it("should allow inserting empty text", () => {

const result = ruleFixer.insertTextBeforeRange([10, 20], "");

assert.deepStrictEqual(result, {
range: [10, 10],
text: ""
});

});

});

describe("insertTextAfter", () => {
Expand All @@ -60,6 +82,17 @@ describe("RuleFixer", () => {

});

it("should allow inserting empty text", () => {

const result = ruleFixer.insertTextAfter({ range: [10, 20] }, "");

assert.deepStrictEqual(result, {
range: [20, 20],
text: ""
});

});

});

describe("insertTextAfterRange", () => {
Expand All @@ -75,6 +108,17 @@ describe("RuleFixer", () => {

});

it("should allow inserting empty text", () => {

const result = ruleFixer.insertTextAfterRange([10, 20], "");

assert.deepStrictEqual(result, {
range: [20, 20],
text: ""
});

});

});

describe("removeAfter", () => {
Expand Down

0 comments on commit 9373893

Please sign in to comment.