Skip to content

Commit

Permalink
Fix: Do not output undefined as line and column when it's unavailab…
Browse files Browse the repository at this point in the history
…le (#13519)
  • Loading branch information
haya14busa committed Jul 31, 2020
1 parent 493b5b4 commit 318fe10
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/cli-engine/formatters/checkstyle.js
Expand Up @@ -42,8 +42,8 @@ module.exports = function(results) {

messages.forEach(message => {
output += [
`<error line="${xmlEscape(message.line)}"`,
`column="${xmlEscape(message.column)}"`,
`<error line="${xmlEscape(message.line || 0)}"`,
`column="${xmlEscape(message.column || 0)}"`,
`severity="${xmlEscape(getMessageType(message))}"`,
`message="${xmlEscape(message.message)}${message.ruleId ? ` (${message.ruleId})` : ""}"`,
`source="${message.ruleId ? xmlEscape(`eslint.rules.${message.ruleId}`) : ""}" />`
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/cli-engine/formatters/checkstyle.js
Expand Up @@ -151,4 +151,21 @@ describe("formatter:checkstyle", () => {
assert.strictEqual(result, "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle version=\"4.3\"><file name=\"foo.js\"><error line=\"5\" column=\"10\" severity=\"error\" message=\"Unexpected foo.\" source=\"\" /></file></checkstyle>");
});
});

describe("when passing single message without line and column", () => {
const code = [{
filePath: "foo.js",
messages: [{
message: "Unexpected foo.",
severity: 2,
ruleId: "foo"
}]
}];

it("should return line and column as 0 instead of undefined", () => {
const result = formatter(code);

assert.strictEqual(result, "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle version=\"4.3\"><file name=\"foo.js\"><error line=\"0\" column=\"0\" severity=\"error\" message=\"Unexpected foo. (foo)\" source=\"eslint.rules.foo\" /></file></checkstyle>");
});
});
});

0 comments on commit 318fe10

Please sign in to comment.