From 0485042806bc6d24a86b6562bd94d2f31cb31258 Mon Sep 17 00:00:00 2001 From: Brett Stimmerman Date: Sun, 9 Sep 2012 18:11:28 -0700 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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