Skip to content

Commit

Permalink
Fix: Formatters keep trailing '.' if preceded by a space (fixes #9154) (
Browse files Browse the repository at this point in the history
  • Loading branch information
i-ron-y authored and not-an-aardvark committed Sep 9, 2017
1 parent 88d5d4d commit 51132d6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/formatters/codeframe.js
Expand Up @@ -47,7 +47,7 @@ function formatFilePath(filePath, line, column) {
*/
function formatMessage(message, parentResult) {
const type = (message.fatal || message.severity === 2) ? chalk.red("error") : chalk.yellow("warning");
const msg = `${chalk.bold(message.message.replace(/\.$/, ""))}`;
const msg = `${chalk.bold(message.message.replace(/([^ ])\.$/, "$1"))}`;
const ruleId = message.fatal ? "" : chalk.dim(`(${message.ruleId})`);
const filePath = formatFilePath(parentResult.filePath, message.line, message.column);
const sourceCode = parentResult.output ? parentResult.output : parentResult.source;
Expand Down
2 changes: 1 addition & 1 deletion lib/formatters/stylish.js
Expand Up @@ -65,7 +65,7 @@ module.exports = function(results) {
message.line || 0,
message.column || 0,
messageType,
message.message.replace(/\.$/, ""),
message.message.replace(/([^ ])\.$/, "$1"),
chalk.dim(message.ruleId || "")
];
}),
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/formatters/codeframe.js
Expand Up @@ -170,6 +170,26 @@ describe("formatter:codeframe", () => {
});
});

describe("when passed a message that ends with ' .'", () => {
const code = [{
filePath: "foo.js",
messages: [{
ruleId: "foo",
message: "Unexpected .",
severity: 2,
source: "foo"
}],
errorCount: 1,
warningCount: 0
}];

it("should return a string in the correct format (retaining the ' .')", () => {
const result = formatter(code);

assert.equal(stripAnsi(result), "error: Unexpected . (foo) at foo.js\n\n\n1 error found.");
});
});

describe("when passed multiple messages", () => {
const code = [{
filePath: "foo.js",
Expand Down
25 changes: 25 additions & 0 deletions tests/lib/formatters/stylish.js
Expand Up @@ -152,6 +152,31 @@ describe("formatter:stylish", () => {
});
});

describe("when passed a message that ends with ' .'", () => {
const code = [{
filePath: "foo.js",
errorCount: 0,
warningCount: 1,
fixableErrorCount: 0,
fixableWarningCount: 0,
messages: [{
message: "Unexpected .",
severity: 1,
line: 5,
column: 10,
ruleId: "foo"
}]
}];

it("should return a string in the correct format (retaining the ' .')", () => {
const result = formatter(code);

assert.equal(result, "\nfoo.js\n 5:10 warning Unexpected . foo\n\n\u2716 1 problem (0 errors, 1 warning)\n");
assert.equal(chalkStub.yellow.bold.callCount, 1);
assert.equal(chalkStub.red.bold.callCount, 0);
});
});

describe("when passed a fatal error message", () => {
const code = [{
filePath: "foo.js",
Expand Down

0 comments on commit 51132d6

Please sign in to comment.