Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Do not output undefined as line and column when it's unavailable in checkstyle format #13519

Merged
merged 1 commit into from Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>");
});
});
});