From baeb536ac817a03b637f2fdc03be4d97a72edf45 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 22 Aug 2013 17:35:16 -0700 Subject: [PATCH] Add "rule" attribute to "lintxml" output format Summary: Currently, there's no way to determine which rule generated a lint message if you have a parser on top of CSSLint. Provide a `rule` attribute which has the rule ID. (The specific motivating use case is that I have a program which runs multiple linters, manages lint message severity above the linter level, and has more severity levels than CSSLint itself does, so using flags like `--ignore` would require special casing and reduce flexibility.) Test Plan: Added new test coverage and executed unit tests. --- src/formatters/lint-xml.js | 10 +++++++--- tests/formatters/lint-xml.js | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/formatters/lint-xml.js b/src/formatters/lint-xml.js index 10155399..00db0d90 100644 --- a/src/formatters/lint-xml.js +++ b/src/formatters/lint-xml.js @@ -39,7 +39,7 @@ CSSLint.addFormatter({ * - & is the escape sequence for & * - < is the escape sequence for < * - > is the escape sequence for > - * + * * @param {String} message to escape * @return escaped message as {String} */ @@ -51,13 +51,17 @@ CSSLint.addFormatter({ }; if (messages.length > 0) { - + output.push(""); CSSLint.Util.forEach(messages, function (message, i) { if (message.rollup) { output.push(""); } else { - output.push(""); } }); diff --git a/tests/formatters/lint-xml.js b/tests/formatters/lint-xml.js index 7e1a6a14..d41f936e 100644 --- a/tests/formatters/lint-xml.js +++ b/tests/formatters/lint-xml.js @@ -6,7 +6,7 @@ YUITest.TestRunner.add(new YUITest.TestCase({ name: "Lint XML formatter test", - + "File with no problems should say so": function(){ var result = { messages: [], stats: [] }, expected = ""; @@ -38,6 +38,25 @@ expected = "" + file + error1 + error2 + "", actual = CSSLint.format(result, "FILE", "lint-xml"); Assert.areEqual(expected, actual); + }, + + "Messages should include rule IDs": function() { + var result = { messages: [ + { type: "error", line: 1, col: 1, message: "X", evidence: "Y", rule: { id: "Z" } } + ], stats: [] }; + + var expected = + '' + + '' + + '' + + '' + + '' + + ''; + + var actual = CSSLint.format(result, "FILE", "lint-xml"); + + Assert.areEqual(expected, actual); } + })); })();