Add alphabetical order rule #433

Merged
merged 1 commit into from Apr 8, 2014

Conversation

Projects
None yet
5 participants
Contributor

hsablonniere commented Nov 24, 2013

This rule verifies that all properties of a single rule are in alphabetical order.

I know order is a serious debate. I don't want to impose it. I just think people who want to enforce order should be able to do so using awesome csslint ;-)

clakech commented Nov 24, 2013

👍

@benschwarz benschwarz and 1 other commented on an outdated diff Nov 24, 2013

tests/rules/order-alphabetical.js
+ "Rules with properties not in alphabetical order should result in a warning": function(){
+ var result = CSSLint.verify("li { z-index: 2; color: red; }", { "order-alphabetical": 1 });
+ Assert.areEqual(1, result.messages.length);
+ Assert.areEqual("warning", result.messages[0].type);
+ Assert.areEqual("Rule doesn't have all its properties in alphabetical ordered.", result.messages[0].message);
+ },
+
+ "Rules with prefixed properties not in alphabetical order (without the prefix) should result in a warning": function(){
+ var result = CSSLint.verify("li { -moz-transition: none; -webkit-box-shadow: none; }", { "order-alphabetical": 1 });
+ Assert.areEqual(1, result.messages.length);
+ Assert.areEqual("warning", result.messages[0].type);
+ Assert.areEqual("Rule doesn't have all its properties in alphabetical ordered.", result.messages[0].message);
+ },
+
+ "Rules with properties in alphabetical order should not result in a warning": function(){
+ var result = CSSLint.verify("li { -webkit-box-shadow: none; color: red; -moz-transition: none; }", { "order-alphabetical": 1 });
@benschwarz

benschwarz Nov 24, 2013

so -webkit-box-shadow orders before -moz-transition because its box-shadow?

@hsablonniere

hsablonniere Nov 24, 2013

Contributor

Yes. The order doesn't care about prefixes, so even if w is after m, the order is using b and t.

I didn't want to enforce order between prefixes of the same property.

Contributor

hsablonniere commented Nov 24, 2013

I could add a second "no warning" test without prefixed properties maybe...

@nschonni nschonni commented on an outdated diff Nov 24, 2013

src/rules/order-alphabetical.js
+ var rule = this,
+ properties;
+
+ var startRule = function () {
+ properties = [];
+ };
+
+ parser.addListener("startrule", startRule);
+ parser.addListener("startfontface", startRule);
+ parser.addListener("startpage", startRule);
+ parser.addListener("startpagemargin", startRule);
+ parser.addListener("startkeyframerule", startRule);
+
+ parser.addListener("property", function(event){
+ var name = event.property.text,
+ lowerCasePrefixLessName = name.toLowerCase().replace(/^-.*?-/, '');
@nschonni

nschonni Nov 24, 2013

Member

Minor thing, but it's probably best to keep the quoting consistent (even though it isn't throughout the repo right now)

Contributor

hsablonniere commented Nov 25, 2013

I added a "no warning" test with unprefixed properties and changed the single quotes to double ones...

Contributor

hsablonniere commented Jan 20, 2014

Any news on this feature ?

@nschonni nschonni added a commit that referenced this pull request Apr 8, 2014

@nschonni nschonni Merge pull request #433 from hsablonniere/add-order-alphabetical
Add alphabetical order rule
b92b866

@nschonni nschonni merged commit b92b866 into CSSLint:master Apr 8, 2014

1 check passed

default The Travis CI build passed
Details

nschonni added this to the 0.11.0 milestone Apr 8, 2014

@XhmikosR XhmikosR modified the milestone: 0.11.0, 1.0.0 Jan 9, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment