Skip to content

Commit 188d984

Browse files
i-ron-ynot-an-aardvark
authored andcommitted
Fix: Formatters keep trailing '.' if preceded by a space (fixes #9154) (#9247)
1 parent abc6b53 commit 188d984

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function formatFilePath(filePath, line, column) {
4747
*/
4848
function formatMessage(message, parentResult) {
4949
const type = (message.fatal || message.severity === 2) ? chalk.red("error") : chalk.yellow("warning");
50-
const msg = `${chalk.bold(message.message.replace(/\.$/, ""))}`;
50+
const msg = `${chalk.bold(message.message.replace(/([^ ])\.$/, "$1"))}`;
5151
const ruleId = message.fatal ? "" : chalk.dim(`(${message.ruleId})`);
5252
const filePath = formatFilePath(parentResult.filePath, message.line, message.column);
5353
const sourceCode = parentResult.output ? parentResult.output : parentResult.source;

test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,26 @@ describe("formatter:codeframe", () => {
170170
});
171171
});
172172

173+
describe("when passed a message that ends with ' .'", () => {
174+
const code = [{
175+
filePath: "foo.js",
176+
messages: [{
177+
ruleId: "foo",
178+
message: "Unexpected .",
179+
severity: 2,
180+
source: "foo"
181+
}],
182+
errorCount: 1,
183+
warningCount: 0
184+
}];
185+
186+
it("should return a string in the correct format (retaining the ' .')", () => {
187+
const result = formatter(code);
188+
189+
assert.equal(stripAnsi(result), "error: Unexpected . (foo) at foo.js\n\n\n1 error found.");
190+
});
191+
});
192+
173193
describe("when passed multiple messages", () => {
174194
const code = [{
175195
filePath: "foo.js",

0 commit comments

Comments
 (0)