Skip to content

Commit dc90961

Browse files
lydellbtmills
authored andcommitted
Fix: Support autofix at the very start of blocks (fixes #117) (#119)
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
1 parent 2de2490 commit dc90961

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/processor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ function adjustBlock(block) {
274274
// then going back one.
275275
let i = 1;
276276

277-
while (i < block.rangeMap.length && block.rangeMap[i].js < range) {
277+
while (i < block.rangeMap.length && block.rangeMap[i].js <= range) {
278278
i++;
279279
}
280280

tests/lib/plugin.js

+21
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,27 @@ describe("plugin", () => {
320320
assert.strictEqual(actual, expected);
321321
});
322322

323+
it("at the very start of a block", () => {
324+
const input = [
325+
"This is Markdown.",
326+
"",
327+
"```js",
328+
"'use strict'",
329+
"```"
330+
].join("\n");
331+
const expected = [
332+
"This is Markdown.",
333+
"",
334+
"```js",
335+
"\"use strict\"",
336+
"```"
337+
].join("\n");
338+
const report = cli.executeOnText(input, "test.md");
339+
const actual = report.results[0].output;
340+
341+
assert.strictEqual(actual, expected);
342+
});
343+
323344
it("in blocks with uncommon tags", () => {
324345
const input = [
325346
"This is Markdown.",

0 commit comments

Comments
 (0)