From 66c1baa6fd13093d06d633555b98b2ae4074e108 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Fri, 10 Feb 2012 14:23:25 -0800 Subject: [PATCH] fix line and column numbers for compatible vendor prefixes rule (fixes #236) --- src/rules/compatible-vendor-prefixes.js | 18 ++++++++++-------- tests/rules/compatible-vendor-prefixes.js | 7 +++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/rules/compatible-vendor-prefixes.js b/src/rules/compatible-vendor-prefixes.js index 76ac6ee8..0ea65bbf 100644 --- a/src/rules/compatible-vendor-prefixes.js +++ b/src/rules/compatible-vendor-prefixes.js @@ -102,8 +102,8 @@ CSSLint.addRule({ }); parser.addListener("property", function (event) { - var name = event.property.text; - if (CSSLint.Util.indexOf(applyTo, name) > -1) { + var name = event.property; + if (CSSLint.Util.indexOf(applyTo, name.text) > -1) { properties.push(name); } }); @@ -131,15 +131,17 @@ CSSLint.addRule({ for (prop in compatiblePrefixes) { if (compatiblePrefixes.hasOwnProperty(prop)) { variations = compatiblePrefixes[prop]; - if (CSSLint.Util.indexOf(variations, name) > -1) { - if (propertyGroups[prop] === undefined) { + if (CSSLint.Util.indexOf(variations, name.text) > -1) { + if (!propertyGroups[prop]) { propertyGroups[prop] = { full : variations.slice(0), - actual : [] + actual : [], + actualNodes: [] }; } - if (CSSLint.Util.indexOf(propertyGroups[prop].actual, name) === -1) { - propertyGroups[prop].actual.push(name); + if (CSSLint.Util.indexOf(propertyGroups[prop].actual, name.text) === -1) { + propertyGroups[prop].actual.push(name.text); + propertyGroups[prop].actualNodes.push(name); } } } @@ -157,7 +159,7 @@ CSSLint.addRule({ item = full[i]; if (CSSLint.Util.indexOf(actual, item) === -1) { propertiesSpecified = (actual.length === 1) ? actual[0] : (actual.length == 2) ? actual.join(" and ") : actual.join(", "); - reporter.report("The property " + item + " is compatible with " + propertiesSpecified + " and should be included as well.", event.selectors[0].line, event.selectors[0].col, rule); + reporter.report("The property " + item + " is compatible with " + propertiesSpecified + " and should be included as well.", value.actualNodes[0].line, value.actualNodes[0].col, rule); } } diff --git a/tests/rules/compatible-vendor-prefixes.js b/tests/rules/compatible-vendor-prefixes.js index 7806f589..c901c463 100644 --- a/tests/rules/compatible-vendor-prefixes.js +++ b/tests/rules/compatible-vendor-prefixes.js @@ -12,6 +12,8 @@ Assert.areEqual(1, result.messages.length); Assert.areEqual("warning", result.messages[0].type); Assert.areEqual("The property -moz-border-radius is compatible with -webkit-border-radius and should be included as well.", result.messages[0].message); + Assert.areEqual(6, result.messages[0].col); + Assert.areEqual(1, result.messages[0].line); }, "Using -webkit-transition and -moz-transition should warn to also include -o-transition and -ms-transition.": function(){ @@ -19,8 +21,13 @@ Assert.areEqual(2, result.messages.length); Assert.areEqual("warning", result.messages[0].type); Assert.areEqual("The property -o-transition is compatible with -webkit-transition and -moz-transition and should be included as well.", result.messages[0].message); + Assert.areEqual(6, result.messages[0].col); + Assert.areEqual(1, result.messages[0].line); Assert.areEqual("warning", result.messages[1].type); Assert.areEqual("The property -ms-transition is compatible with -webkit-transition and -moz-transition and should be included as well.", result.messages[1].message); + Assert.areEqual(6, result.messages[1].col); + Assert.areEqual(1, result.messages[1].line); + }, "Using -webkit-transform should warn to also include -moz-transform, -ms-transform, and -o-transform.": function(){