From 0485042806bc6d24a86b6562bd94d2f31cb31258 Mon Sep 17 00:00:00 2001 From: Brett Stimmerman Date: Sun, 9 Sep 2012 18:11:28 -0700 Subject: [PATCH 01/16] Add duplicate property-value pairs rule --- src/rules/duplicate-property-value-pairs.js | 54 +++++++++++++++++++ tests/rules/duplicate-property-value-pairs.js | 18 +++++++ 2 files changed, 72 insertions(+) create mode 100644 src/rules/duplicate-property-value-pairs.js create mode 100644 tests/rules/duplicate-property-value-pairs.js diff --git a/src/rules/duplicate-property-value-pairs.js b/src/rules/duplicate-property-value-pairs.js new file mode 100644 index 00000000..d6bbb03e --- /dev/null +++ b/src/rules/duplicate-property-value-pairs.js @@ -0,0 +1,54 @@ +/* + * Rule: Be aware of duplicate property-value pairs. + */ +/*global CSSLint*/ +CSSLint.addRule({ + + //rule information + id: "duplicate-property-value-pairs", + name: "Duplicate property-value pairs", + desc: "Be aware of duplicate property-value pairs. Many duplicates may indicate the need for abstratcion.", + browsers: "All", + + //initialization + init: function(parser, reporter){ + var rule = this; + var count = {}; + + //count how many times "float" is used + parser.addListener("property", function(event){ + var prop = event.property.text.toLowerCase(), + val = event.value.text.toLowerCase(), + key = prop + ':' + val; + + if (!count[key]) { + count[key] = 0; + } + + count[key] += 1; + }); + + //report the results + parser.addListener("endstylesheet", function(){ + var data = [], + msg = []; + + for (var prop in count) { + if (count.hasOwnProperty(prop)) { + data.push([prop, count[prop]]); + } + } + + data.sort(function (a, b) { + return b[1] - a[1]; + }); + + data = data.map(function (item) { + return item[1] + ' => ' + item[0]; + }).join('\n'); + + reporter.rollupWarn('Duplicate property-value-pairs:\n\n' + data); + }); + } + +}); diff --git a/tests/rules/duplicate-property-value-pairs.js b/tests/rules/duplicate-property-value-pairs.js new file mode 100644 index 00000000..56a42d1b --- /dev/null +++ b/tests/rules/duplicate-property-value-pairs.js @@ -0,0 +1,18 @@ +(function(){ + + /*global YUITest, CSSLint*/ + var Assert = YUITest.Assert; + + YUITest.TestRunner.add(new YUITest.TestCase({ + + name: "Duplicate Property-Value Pair Rule Errors", + + "Duplicate property-value pairs should result in a warning": function () { + var result = CSSLint.verify(".foo { color: #f00; } .bar { color: #f00; }", {"duplicate-property-value-pairs": 1}); + Assert.areEqual(1, result.messages.length); + Assert.areEqual("warning", result.messages[0].type); + Assert.areEqual("Duplicate property-value-pairs:\n\n2 => color:#f00", result.messages[0].message); + } + })); + +})(); From e456ed845054f1e665599d88ab5ac375890fe3c9 Mon Sep 17 00:00:00 2001 From: Nicole Sullivan Date: Sun, 9 Sep 2012 22:17:08 -0700 Subject: [PATCH 02/16] separator changed to "|" and divided Prop from value --- src/rules/duplicate-property-value-pairs.js | 4 ++-- tests/rules/duplicate-property-value-pairs.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rules/duplicate-property-value-pairs.js b/src/rules/duplicate-property-value-pairs.js index d6bbb03e..7ff63469 100644 --- a/src/rules/duplicate-property-value-pairs.js +++ b/src/rules/duplicate-property-value-pairs.js @@ -19,7 +19,7 @@ CSSLint.addRule({ parser.addListener("property", function(event){ var prop = event.property.text.toLowerCase(), val = event.value.text.toLowerCase(), - key = prop + ':' + val; + key = prop + '|' + val; if (!count[key]) { count[key] = 0; @@ -44,7 +44,7 @@ CSSLint.addRule({ }); data = data.map(function (item) { - return item[1] + ' => ' + item[0]; + return item[1] + '|' + item[0]; }).join('\n'); reporter.rollupWarn('Duplicate property-value-pairs:\n\n' + data); diff --git a/tests/rules/duplicate-property-value-pairs.js b/tests/rules/duplicate-property-value-pairs.js index 56a42d1b..505a173f 100644 --- a/tests/rules/duplicate-property-value-pairs.js +++ b/tests/rules/duplicate-property-value-pairs.js @@ -11,7 +11,7 @@ var result = CSSLint.verify(".foo { color: #f00; } .bar { color: #f00; }", {"duplicate-property-value-pairs": 1}); Assert.areEqual(1, result.messages.length); Assert.areEqual("warning", result.messages[0].type); - Assert.areEqual("Duplicate property-value-pairs:\n\n2 => color:#f00", result.messages[0].message); + Assert.areEqual("Duplicate property-value-pairs:\n\n2|color|#f00", result.messages[0].message); } })); From ecd91b6e30a97e01f71e3e20bfa86b96a1f3415a Mon Sep 17 00:00:00 2001 From: Nicole Sullivan Date: Sun, 9 Sep 2012 22:17:47 -0700 Subject: [PATCH 03/16] Find duplicate property counts --- src/rules/duplicate-property-count.js | 54 +++++++++++++++++++++++++ tests/rules/duplicate-property-count.js | 18 +++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/rules/duplicate-property-count.js create mode 100644 tests/rules/duplicate-property-count.js diff --git a/src/rules/duplicate-property-count.js b/src/rules/duplicate-property-count.js new file mode 100644 index 00000000..cc4b2ea4 --- /dev/null +++ b/src/rules/duplicate-property-count.js @@ -0,0 +1,54 @@ +/* + * Rule: Be aware of duplicate property-value pairs. + */ +/*global CSSLint*/ +CSSLint.addRule({ + + //rule information + id: "duplicate-property-count", + name: "Duplicate properties", + desc: "Be aware of duplicate properties. Many duplicates may indicate the need for abstratcion.", + browsers: "All", + + //initialization + init: function(parser, reporter){ + var rule = this; + var count = {}; + + //count how many times "float" is used + parser.addListener("property", function(event){ + var prop = event.property.text.toLowerCase(), + val = event.value.text.toLowerCase(), + key = prop + ':' + val; + + if (!count[prop]) { + count[prop] = 0; + } + + count[prop] += 1; + }); + + //report the results + parser.addListener("endstylesheet", function(){ + var data = [], + msg = []; // remove + + for (var prop in count) { + if (count.hasOwnProperty(prop)) { + data.push([prop, count[prop]]); + } + } + + data.sort(function (a, b) { + return b[1] - a[1]; + }); + + data = data.map(function (item) { + return item[1] + ',' + item[0]; + }).join('\n'); + + reporter.rollupWarn('Duplicate property count:\n\n' + data); + }); + } + +}); diff --git a/tests/rules/duplicate-property-count.js b/tests/rules/duplicate-property-count.js new file mode 100644 index 00000000..592725c9 --- /dev/null +++ b/tests/rules/duplicate-property-count.js @@ -0,0 +1,18 @@ +(function(){ + + /*global YUITest, CSSLint*/ + var Assert = YUITest.Assert; + + YUITest.TestRunner.add(new YUITest.TestCase({ + + name: "Duplicate Property-Value Pair Rule Errors", + + "Duplicate property count should result in a warning": function () { + var result = CSSLint.verify(".foo { color: #f00; } .bar { color: #f00; }", {"duplicate-property-count": 1}); + Assert.areEqual(1, result.messages.length); + Assert.areEqual("warning", result.messages[0].type); + Assert.areEqual("Duplicate property count:\n\n2,color", result.messages[0].message); + } + })); + +})(); From b5cb040adef95d8420d05d5ea5e9490640959a14 Mon Sep 17 00:00:00 2001 From: Nicole Sullivan Date: Sun, 9 Sep 2012 22:29:01 -0700 Subject: [PATCH 04/16] Add test and rollupwarn for rules-count --- src/rules/rules-count.js | 3 ++- tests/rules/rules-count.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/rules/rules-count.js diff --git a/src/rules/rules-count.js b/src/rules/rules-count.js index b7712ff2..072b5839 100644 --- a/src/rules/rules-count.js +++ b/src/rules/rules-count.js @@ -21,7 +21,8 @@ CSSLint.addRule({ }); parser.addListener("endstylesheet", function(){ - reporter.stat("rule-count", count); + reporter.stat("rules-count", count); + reporter.rollupWarn('This CSS contains ' + count + ' rules.'); }); } diff --git a/tests/rules/rules-count.js b/tests/rules/rules-count.js new file mode 100644 index 00000000..7cb4bd72 --- /dev/null +++ b/tests/rules/rules-count.js @@ -0,0 +1,20 @@ +(function(){ + + /*global YUITest, CSSLint*/ + var Assert = YUITest.Assert; + + YUITest.TestRunner.add(new YUITest.TestCase({ + + name: "Rule Count Errors", + + "Rules should be counted": function(){ + var result = CSSLint.verify("h1 { color:#fff; }.foo{color: red;}", { "rules-count": 1}); + // console.dir(result); + Assert.areEqual(1, result.messages.length); + Assert.areEqual("warning", result.messages[0].type); + Assert.areEqual("This CSS contains 2 rules.", result.messages[0].message); + } + + })); + +})(); From fd53a9645c3150a448ee94a93c7e9975caf9c972 Mon Sep 17 00:00:00 2001 From: Nicole Sullivan Date: Mon, 31 Dec 2012 17:21:46 -0800 Subject: [PATCH 05/16] instructions for running the dev version --- notes.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 notes.md diff --git a/notes.md b/notes.md new file mode 100644 index 00000000..abaa2500 --- /dev/null +++ b/notes.md @@ -0,0 +1,6 @@ +Steps to run dev version of csslint from the command line (not the current release): + +1. command line: "ant" +1. edit /build/npm/package.json give it a version number like 1.0.0 +1. command line: "npm link" (in the build/npm dir, possibly sudo) +1. command line: "csslint " \ No newline at end of file From c9ce6061da00ba5e55fa29ddb4be6ea4a82f5656 Mon Sep 17 00:00:00 2001 From: niallmur Date: Fri, 31 May 2013 14:51:57 +0200 Subject: [PATCH 06/16] Create non-link-hover --- non-link-hover | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 non-link-hover diff --git a/non-link-hover b/non-link-hover new file mode 100644 index 00000000..91ebc439 --- /dev/null +++ b/non-link-hover @@ -0,0 +1,40 @@ +/* + * Rule: When using a vendor-prefixed gradient, make sure to use them all. + */ +/*global CSSLint*/ +CSSLint.addRule({ + + //rule information + id: "non-link-hover", + name: "Non-Link Hover", + desc: "Using :hover pseudo-selector to non-link elements is known to be slow.", + browsers: "IE", + + //initialization + init: function(parser, reporter){ + var rule = this; + + + parser.addListener("startrule", function(event){ + var selectors = event.selectors, + selector, + part, + modifier, + i, j, k; + + for (i=0; i < selectors.length; i++){ + selector = selectors[i]; + + part = selector.parts[selector.parts.length-1]; + + if (part.modifiers.length-1 !== -1){ + if (part.modifiers[part.modifiers.length-1].text === ":hover" && (part.elementName == null || part.elementName != "a")){ + reporter.warn(rule.desc, part.line, part.col, rule); + } + } + + } + }); + } + +}); From 8a72ca418f7964a61d8432457cf45b767d3987e8 Mon Sep 17 00:00:00 2001 From: niallmur Date: Fri, 31 May 2013 14:55:42 +0200 Subject: [PATCH 07/16] Create non-link-hover This is an extension of work carried out by hpbuniat. The rule he submitted did not work if there was a null before :hover. This rule tests for the IE7/IE8 issue where un-anchored hovers cause poor performance --- src/rules/non-link-hover | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/rules/non-link-hover diff --git a/src/rules/non-link-hover b/src/rules/non-link-hover new file mode 100644 index 00000000..91ebc439 --- /dev/null +++ b/src/rules/non-link-hover @@ -0,0 +1,40 @@ +/* + * Rule: When using a vendor-prefixed gradient, make sure to use them all. + */ +/*global CSSLint*/ +CSSLint.addRule({ + + //rule information + id: "non-link-hover", + name: "Non-Link Hover", + desc: "Using :hover pseudo-selector to non-link elements is known to be slow.", + browsers: "IE", + + //initialization + init: function(parser, reporter){ + var rule = this; + + + parser.addListener("startrule", function(event){ + var selectors = event.selectors, + selector, + part, + modifier, + i, j, k; + + for (i=0; i < selectors.length; i++){ + selector = selectors[i]; + + part = selector.parts[selector.parts.length-1]; + + if (part.modifiers.length-1 !== -1){ + if (part.modifiers[part.modifiers.length-1].text === ":hover" && (part.elementName == null || part.elementName != "a")){ + reporter.warn(rule.desc, part.line, part.col, rule); + } + } + + } + }); + } + +}); From a8b39b3e27a7ea6c11abf128c83725c21e9826ab Mon Sep 17 00:00:00 2001 From: niallmur Date: Fri, 31 May 2013 14:56:31 +0200 Subject: [PATCH 08/16] Create non-link-hover Test case --- tests/rules/non-link-hover | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/rules/non-link-hover diff --git a/tests/rules/non-link-hover b/tests/rules/non-link-hover new file mode 100644 index 00000000..f35761b5 --- /dev/null +++ b/tests/rules/non-link-hover @@ -0,0 +1,19 @@ +(function(){ + + /*global YUITest, CSSLint*/ + var Assert = YUITest.Assert; + + YUITest.TestRunner.add(new YUITest.TestCase({ + name: ":hover; Warning", + "using :hover on non-link ements should result in an warning": function(){ + var result = CSSLint.verify("li:hover {color:blue;} .foo:hover {float:left;} #foo:hover {clear:both;} div.faa :hover {font-size:1px;}", { "non-link-hover": 4 }); + Assert.areEqual(4, result.messages.length); + Assert.areEqual("warn", result.messages[0].type); + Assert.areEqual("Using :hover pseudo-selector to non-link elements is known to be slow.", result.messages[0].message); + }, + "using :hover on link ements should not result in any remark": function(){ + var result = CSSLint.verify("a:hover {color:red;} li a:hover, div a:hover {color:red;}", { "non-link-hover": 0 }); + Assert.areEqual(0, result.messages.length); + } + })); +})(); From e543a3290ae478bc3ca2f776c597c3dc69279a2e Mon Sep 17 00:00:00 2001 From: Niall Murphy Date: Wed, 12 Jun 2013 11:42:15 +0200 Subject: [PATCH 09/16] Update non-link-hover Updated comments and affected browsers --- src/rules/non-link-hover | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rules/non-link-hover b/src/rules/non-link-hover index 91ebc439..a15bfe4a 100644 --- a/src/rules/non-link-hover +++ b/src/rules/non-link-hover @@ -1,5 +1,5 @@ /* - * Rule: When using a vendor-prefixed gradient, make sure to use them all. + * Rule: When using a :hover ensure that it has been anchored with the tag. */ /*global CSSLint*/ CSSLint.addRule({ @@ -8,7 +8,7 @@ CSSLint.addRule({ id: "non-link-hover", name: "Non-Link Hover", desc: "Using :hover pseudo-selector to non-link elements is known to be slow.", - browsers: "IE", + browsers: "IE7, IE8", //initialization init: function(parser, reporter){ From 98a6b6fdc7f636a4735c3e1a5d357aba48c83cac Mon Sep 17 00:00:00 2001 From: Niall Murphy Date: Wed, 12 Jun 2013 13:43:49 +0200 Subject: [PATCH 10/16] Update non-link-hover --- src/rules/non-link-hover | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules/non-link-hover b/src/rules/non-link-hover index a15bfe4a..d3d9a389 100644 --- a/src/rules/non-link-hover +++ b/src/rules/non-link-hover @@ -1,5 +1,5 @@ /* - * Rule: When using a :hover ensure that it has been anchored with the tag. + * Rule: When using a :hover selector ensure that it has been anchored with the tag. */ /*global CSSLint*/ CSSLint.addRule({ From 22745fb20d36a24205d5b61bb146cc13bc3e22cc Mon Sep 17 00:00:00 2001 From: niallmur Date: Wed, 12 Jun 2013 13:34:24 +0100 Subject: [PATCH 11/16] deleted extra non-link-hover file. --- non-link-hover | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 non-link-hover diff --git a/non-link-hover b/non-link-hover deleted file mode 100644 index 91ebc439..00000000 --- a/non-link-hover +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Rule: When using a vendor-prefixed gradient, make sure to use them all. - */ -/*global CSSLint*/ -CSSLint.addRule({ - - //rule information - id: "non-link-hover", - name: "Non-Link Hover", - desc: "Using :hover pseudo-selector to non-link elements is known to be slow.", - browsers: "IE", - - //initialization - init: function(parser, reporter){ - var rule = this; - - - parser.addListener("startrule", function(event){ - var selectors = event.selectors, - selector, - part, - modifier, - i, j, k; - - for (i=0; i < selectors.length; i++){ - selector = selectors[i]; - - part = selector.parts[selector.parts.length-1]; - - if (part.modifiers.length-1 !== -1){ - if (part.modifiers[part.modifiers.length-1].text === ":hover" && (part.elementName == null || part.elementName != "a")){ - reporter.warn(rule.desc, part.line, part.col, rule); - } - } - - } - }); - } - -}); From 8e6e033d1c1e307ac2583d8fa113260f1d4ff96c Mon Sep 17 00:00:00 2001 From: niallmur Date: Wed, 12 Jun 2013 14:14:54 +0100 Subject: [PATCH 12/16] Added a more complicated test case --- tests/rules/non-link-hover | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rules/non-link-hover b/tests/rules/non-link-hover index f35761b5..85535088 100644 --- a/tests/rules/non-link-hover +++ b/tests/rules/non-link-hover @@ -6,13 +6,13 @@ YUITest.TestRunner.add(new YUITest.TestCase({ name: ":hover; Warning", "using :hover on non-link ements should result in an warning": function(){ - var result = CSSLint.verify("li:hover {color:blue;} .foo:hover {float:left;} #foo:hover {clear:both;} div.faa :hover {font-size:1px;}", { "non-link-hover": 4 }); + var result = CSSLint.verify("li:hover {color:blue;} .foo:hover {float:left;} #foo:hover {clear:both;} div.faa :hover {font-size:1px;}", body .test-result .tmp-program .test-program-left .test-program-title .test-program-help-image :hover, body .test-eligibility-result.cw-collapsed-map .test-eligibility-triage .test-top-panel-left-image:hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-right-image :hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-image:hover {background-position: 100% 49%;}, { "non-link-hover": 4 }); Assert.areEqual(4, result.messages.length); Assert.areEqual("warn", result.messages[0].type); Assert.areEqual("Using :hover pseudo-selector to non-link elements is known to be slow.", result.messages[0].message); }, "using :hover on link ements should not result in any remark": function(){ - var result = CSSLint.verify("a:hover {color:red;} li a:hover, div a:hover {color:red;}", { "non-link-hover": 0 }); + var result = CSSLint.verify("a:hover {color:red;} li a:hover, div a:hover {color:red;}", body .test-result .tmp-program .test-program-left .test-program-title .test-program-help-image a:hover, body .test-eligibility-result.cw-collapsed-map .test-eligibility-triage a.test-top-panel-left-image:hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-right-image a:hover, body .test-eligibility-result .test-eligibility-result-triage a.test-panel-image:hover {background-position: 100% 49%;}, { "non-link-hover": 0 }); Assert.areEqual(0, result.messages.length); } })); From 4da270ba11aad8e67b8725d9d66f6eb2079f7660 Mon Sep 17 00:00:00 2001 From: niallmur Date: Wed, 12 Jun 2013 14:17:29 +0100 Subject: [PATCH 13/16] added the .js to file as it was missing --- tests/rules/{non-link-hover => non-link-hover.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/rules/{non-link-hover => non-link-hover.js} (100%) diff --git a/tests/rules/non-link-hover b/tests/rules/non-link-hover.js similarity index 100% rename from tests/rules/non-link-hover rename to tests/rules/non-link-hover.js From f1a88edbf640ce10bd3728f342f483c03e51d241 Mon Sep 17 00:00:00 2001 From: niallmur Date: Tue, 18 Jun 2013 14:51:03 +0100 Subject: [PATCH 14/16] Signed-off-by: niallmur --- tests/rules/non-link-hover.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/rules/non-link-hover.js b/tests/rules/non-link-hover.js index 85535088..d4f08749 100644 --- a/tests/rules/non-link-hover.js +++ b/tests/rules/non-link-hover.js @@ -6,14 +6,14 @@ YUITest.TestRunner.add(new YUITest.TestCase({ name: ":hover; Warning", "using :hover on non-link ements should result in an warning": function(){ - var result = CSSLint.verify("li:hover {color:blue;} .foo:hover {float:left;} #foo:hover {clear:both;} div.faa :hover {font-size:1px;}", body .test-result .tmp-program .test-program-left .test-program-title .test-program-help-image :hover, body .test-eligibility-result.cw-collapsed-map .test-eligibility-triage .test-top-panel-left-image:hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-right-image :hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-image:hover {background-position: 100% 49%;}, { "non-link-hover": 4 }); + var result = CSSLint.verify("li:hover {color:blue;} .foo:hover {float:left;} #foo:hover {clear:both;} div.faa :hover {font-size:1px;}, body .test-result .tmp-program .test-program-left .test-program-title .test-program-help-image :hover, body .test-eligibility-result.cw-collapsed-map .test-eligibility-triage .test-top-panel-left-image:hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-right-image :hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-image:hover {background-position: 100% 49%;}", { "non-link-hover": 4 }); Assert.areEqual(4, result.messages.length); Assert.areEqual("warn", result.messages[0].type); Assert.areEqual("Using :hover pseudo-selector to non-link elements is known to be slow.", result.messages[0].message); }, "using :hover on link ements should not result in any remark": function(){ - var result = CSSLint.verify("a:hover {color:red;} li a:hover, div a:hover {color:red;}", body .test-result .tmp-program .test-program-left .test-program-title .test-program-help-image a:hover, body .test-eligibility-result.cw-collapsed-map .test-eligibility-triage a.test-top-panel-left-image:hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-right-image a:hover, body .test-eligibility-result .test-eligibility-result-triage a.test-panel-image:hover {background-position: 100% 49%;}, { "non-link-hover": 0 }); + var result = CSSLint.verify("a:hover {color:red;} li a:hover, div a:hover {color:red;}, body .test-result .tmp-program .test-program-left .test-program-title .test-program-help-image a:hover, body .test-eligibility-result.cw-collapsed-map .test-eligibility-triage a.test-top-panel-left-image:hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-right-image a:hover, body .test-eligibility-result .test-eligibility-result-triage a.test-panel-image:hover {background-position: 100% 49%;}", { "non-link-hover": 0 }); Assert.areEqual(0, result.messages.length); } })); -})(); +})(); \ No newline at end of file From 0048664985263b43ad9d26edf21810804d28b305 Mon Sep 17 00:00:00 2001 From: niallmur Date: Tue, 18 Jun 2013 15:59:29 +0100 Subject: [PATCH 15/16] update --- tests/rules/non-link-hover.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rules/non-link-hover.js b/tests/rules/non-link-hover.js index d4f08749..31676b8f 100644 --- a/tests/rules/non-link-hover.js +++ b/tests/rules/non-link-hover.js @@ -6,13 +6,13 @@ YUITest.TestRunner.add(new YUITest.TestCase({ name: ":hover; Warning", "using :hover on non-link ements should result in an warning": function(){ - var result = CSSLint.verify("li:hover {color:blue;} .foo:hover {float:left;} #foo:hover {clear:both;} div.faa :hover {font-size:1px;}, body .test-result .tmp-program .test-program-left .test-program-title .test-program-help-image :hover, body .test-eligibility-result.cw-collapsed-map .test-eligibility-triage .test-top-panel-left-image:hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-right-image :hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-image:hover {background-position: 100% 49%;}", { "non-link-hover": 4 }); + var result = CSSLint.verify("li:hover {color:blue;} .foo:hover {float:left;} #foo:hover {clear:both;} div.faa :hover {font-size:1px;}, body .test-result .tmp-program .test-program-left .test-program-title .test-program-help-image :hover, body .test-eligibility-result.cw-collapsed-map .test-eligibility-triage .test-top-panel-left-image:hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-right-image :hover {font-size:1px;}, body .test-eligibility-result .test-eligibility-result-triage .test-panel-image:hover {background-position: 100% 49%;}", { "non-link-hover": 4 }); Assert.areEqual(4, result.messages.length); Assert.areEqual("warn", result.messages[0].type); Assert.areEqual("Using :hover pseudo-selector to non-link elements is known to be slow.", result.messages[0].message); }, "using :hover on link ements should not result in any remark": function(){ - var result = CSSLint.verify("a:hover {color:red;} li a:hover, div a:hover {color:red;}, body .test-result .tmp-program .test-program-left .test-program-title .test-program-help-image a:hover, body .test-eligibility-result.cw-collapsed-map .test-eligibility-triage a.test-top-panel-left-image:hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-right-image a:hover, body .test-eligibility-result .test-eligibility-result-triage a.test-panel-image:hover {background-position: 100% 49%;}", { "non-link-hover": 0 }); + var result = CSSLint.verify("a:hover {color:red;} li a:hover, div a:hover {color:red;}, body .test-result .tmp-program .test-program-left .test-program-title .test-program-help-image a:hover, body .test-eligibility-result.cw-collapsed-map .test-eligibility-triage a.test-top-panel-left-image:hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-right-image a:hover {font-size:1px;}, body .test-eligibility-result .test-eligibility-result-triage a.test-panel-image:hover {background-position: 100% 49%;}", { "non-link-hover": 0 }); Assert.areEqual(0, result.messages.length); } })); From 151b7fe0bebbffb1cd519c866dd4e150fdf0db1c Mon Sep 17 00:00:00 2001 From: niallmur Date: Wed, 26 Jun 2013 17:14:16 +0100 Subject: [PATCH 16/16] Added the ability to deal with an upper case 'A' anchor. Even though this is against convention this is still valid css and wll prevent the :hover performance issue --- src/rules/non-link-hover | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules/non-link-hover b/src/rules/non-link-hover index d3d9a389..a6575264 100644 --- a/src/rules/non-link-hover +++ b/src/rules/non-link-hover @@ -28,7 +28,7 @@ CSSLint.addRule({ part = selector.parts[selector.parts.length-1]; if (part.modifiers.length-1 !== -1){ - if (part.modifiers[part.modifiers.length-1].text === ":hover" && (part.elementName == null || part.elementName != "a")){ + if (part.modifiers[part.modifiers.length-1].text === ":hover" && (part.elementName == null || (part.elementName != "a" && part.elementName != "A"))){ reporter.warn(rule.desc, part.line, part.col, rule); } }