Skip to content

Commit

Permalink
Fix: Support autofix at the very start of blocks (fixes #117) (#119)
Browse files Browse the repository at this point in the history
Previously, if a rule added an autofix at index 0 of a code block, all
code from the start of the markdown file until the start of that code
block would be removed. Now, the autofix is applied as expected.

Fixes lydell/eslint-plugin-simple-import-sort#22
  • Loading branch information
lydell authored and btmills committed Oct 8, 2019
1 parent 2de2490 commit dc90961
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/processor.js
Expand Up @@ -274,7 +274,7 @@ function adjustBlock(block) {
// then going back one.
let i = 1;

while (i < block.rangeMap.length && block.rangeMap[i].js < range) {
while (i < block.rangeMap.length && block.rangeMap[i].js <= range) {
i++;
}

Expand Down
21 changes: 21 additions & 0 deletions tests/lib/plugin.js
Expand Up @@ -320,6 +320,27 @@ describe("plugin", () => {
assert.strictEqual(actual, expected);
});

it("at the very start of a block", () => {
const input = [
"This is Markdown.",
"",
"```js",
"'use strict'",
"```"
].join("\n");
const expected = [
"This is Markdown.",
"",
"```js",
"\"use strict\"",
"```"
].join("\n");
const report = cli.executeOnText(input, "test.md");
const actual = report.results[0].output;

assert.strictEqual(actual, expected);
});

it("in blocks with uncommon tags", () => {
const input = [
"This is Markdown.",
Expand Down

0 comments on commit dc90961

Please sign in to comment.