Skip to content

Commit

Permalink
fix(textlint): fix an error on compats fixer formatter
Browse files Browse the repository at this point in the history
Modify to export the function as default, and add test cases for it.

Closes #979
  • Loading branch information
Sean0628 authored and azu committed Jan 4, 2023
1 parent f33931c commit 8c7d3c6
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
Expand Up @@ -9,7 +9,7 @@ function getMessageType(message: any) {
}
}

export function format(results: TextlintFixResult[]) {
export default function (results: TextlintFixResult[]) {
let output = "";
let total = 0;

Expand Down
84 changes: 84 additions & 0 deletions packages/@textlint/fixer-formatter/test/formatters/compats-test.js
@@ -0,0 +1,84 @@
"use strict";
import path from "path";
import compats from "../../src/formatters/compats";
import assert from "assert";

const formatter = (code) => {
return compats(code, { color: false });
};

describe("formatter:compats", function () {
context("when single modified", function () {
it("should return output", function () {
const input = path.join(__dirname, "../fixtures", "single.md");
const code = require("../fixtures/single");
const output = formatter(code, { color: false });
assert.strictEqual(
output,
`
Fixed✔ ${input}: line 5, col 9, Error - Unexpected foo. (foo)
Fixed 1 problem
`.trim()
);
});
});
context("when double modified", function () {
it("should return output", function () {
const input = path.join(__dirname, "../fixtures", "double.md");
const code = require("../fixtures/double");
const output = formatter(code, { color: false });
assert.strictEqual(
output,
`
Fixed✔ ${input}: line 5, col 1, Error - Unexpected foo. (foo)
Fixed✔ ${input}: line 6, col 1, Error - Unexpected bar. (foo)
Fixed 2 problems
`.trim()
);
});
});
context("when multiple files results", function () {
it("should return output", function () {
const singleFile = path.join(__dirname, "../fixtures", "single.md");
const multiple = path.join(__dirname, "../fixtures", "multiple.md");
const code = require("../fixtures/multiple");
const output = formatter(code, { color: false });
assert.strictEqual(
output,
`
Fixed✔ ${singleFile}: line 5, col 9, Error - Unexpected foo. (foo)
Fixed✔ ${multiple}: line 1, col 1, Error - Unexpected foo. (foo)
Fixed✔ ${multiple}: line 1, col 4, Error - Unexpected bar. (foo)
Fixed✔ ${multiple}: line 3, col 1, Error - Unexpected foo. (foo)
Fixed✔ ${multiple}: line 3, col 4, Error - Unexpected bar. (foo)
Fixed✔ ${multiple}: line 7, col 1, Error - Unexpected foo. (foo)
Fixed✔ ${multiple}: line 7, col 4, Error - Unexpected bar. (foo)
Fixed 7 problems
`.trim()
);
});
});

context("when remaining messages", function () {
it("should return output", function () {
const input = path.join(__dirname, "../fixtures", "remaining.md");
const code = require("../fixtures/remaining");
const output = formatter(code, { color: false });
assert.strictEqual(
output,
`
Fixed✔ ${input}: line 5, col 9, Error - Unexpected foo. (foo)
Fixed 1 problem
`.trim()
);
});
});
});

0 comments on commit 8c7d3c6

Please sign in to comment.