Skip to content

Commit 8a13335

Browse files
author
Nicholas C. Zakas
committed
Make sure float: none doesn't count as a float for rules that care (fixes #10)
1 parent a2ef767 commit 8a13335

File tree

10 files changed

+88
-20
lines changed

10 files changed

+88
-20
lines changed

build/csslint-node.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9716,7 +9716,7 @@ CSSLint.addRule({
97169716

97179717
var propertiesToCheck = {
97189718
display: 1,
9719-
"float": 1,
9719+
"float": "none",
97209720
height: 1,
97219721
width: 1,
97229722
margin: 1,
@@ -9798,7 +9798,9 @@ CSSLint.addRule({
97989798

97999799
function reportProperty(name, display){
98009800
if (properties[name]){
9801-
reporter.warn(name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
9801+
if (!(typeof propertiesToCheck[name] == "string") || properties[name].value.toLowerCase() != propertiesToCheck[name]){
9802+
reporter.warn(name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
9803+
}
98029804
}
98039805
}
98049806
}
@@ -9878,7 +9880,8 @@ CSSLint.addRule({
98789880

98799881
//count how many times "float" is used
98809882
parser.addListener("property", function(event){
9881-
if (event.property == "float"){
9883+
if (event.property.text.toLowerCase() == "float" &&
9884+
event.value.text.toLowerCase() != "none"){
98829885
count++;
98839886
}
98849887
});

build/csslint-rhino.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9717,7 +9717,7 @@ CSSLint.addRule({
97179717

97189718
var propertiesToCheck = {
97199719
display: 1,
9720-
"float": 1,
9720+
"float": "none",
97219721
height: 1,
97229722
width: 1,
97239723
margin: 1,
@@ -9799,7 +9799,9 @@ CSSLint.addRule({
97999799

98009800
function reportProperty(name, display){
98019801
if (properties[name]){
9802-
reporter.warn(name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
9802+
if (!(typeof propertiesToCheck[name] == "string") || properties[name].value.toLowerCase() != propertiesToCheck[name]){
9803+
reporter.warn(name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
9804+
}
98039805
}
98049806
}
98059807
}
@@ -9879,7 +9881,8 @@ CSSLint.addRule({
98799881

98809882
//count how many times "float" is used
98819883
parser.addListener("property", function(event){
9882-
if (event.property == "float"){
9884+
if (event.property.text.toLowerCase() == "float" &&
9885+
event.value.text.toLowerCase() != "none"){
98839886
count++;
98849887
}
98859888
});

build/csslint-tests.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@
239239
Assert.areEqual("float can't be used with display: inline.", result.messages[0].message);
240240
},
241241

242+
"Float:none with inline-block should not result in a warning": function(){
243+
var result = CSSLint.verify(".foo { float: none; display: inline-block; }", { "display-property-grouping": 1 });
244+
Assert.areEqual(0, result.messages.length);
245+
},
246+
247+
"Float:none with inline should result not in a warning": function(){
248+
var result = CSSLint.verify(".foo { float: none; display: inline; }", { "display-property-grouping": 1 });
249+
Assert.areEqual(0, result.messages.length);
250+
},
251+
242252
"Height with inline should result in a warning": function(){
243253
var result = CSSLint.verify(".foo { height: 100px; display: inline; }", { "display-property-grouping": 1 });
244254
Assert.areEqual(1, result.messages.length);
@@ -412,7 +422,17 @@
412422
Assert.areEqual(1, result.messages.length);
413423
Assert.areEqual("warning", result.messages[0].type);
414424
Assert.areEqual("float can't be used with display: table-cell.", result.messages[0].message);
415-
}
425+
},
426+
427+
"Float:none with table-row should not result in a warning": function(){
428+
var result = CSSLint.verify(".foo { float: none; display: table-row; }", { "display-property-grouping": 1 });
429+
Assert.areEqual(0, result.messages.length);
430+
},
431+
432+
"Float:none with table-cell should not result in a warning": function(){
433+
var result = CSSLint.verify(".foo { float: none; display: table-cell; }", { "display-property-grouping": 1 });
434+
Assert.areEqual(0, result.messages.length);
435+
}
416436

417437
}));
418438

@@ -481,6 +501,11 @@
481501
Assert.areEqual(1, result.messages.length);
482502
Assert.areEqual("warning", result.messages[0].type);
483503
Assert.areEqual("Too many floats (11), abstraction needed.", result.messages[0].message);
504+
},
505+
506+
"float: none should not count and therefore should not result in a warning": function(){
507+
var result = CSSLint.verify(".foo { float: none; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; }", { "floats": 1 });
508+
Assert.areEqual(0, result.messages.length);
484509
}
485510
}));
486511

build/csslint-worker.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9716,7 +9716,7 @@ CSSLint.addRule({
97169716

97179717
var propertiesToCheck = {
97189718
display: 1,
9719-
"float": 1,
9719+
"float": "none",
97209720
height: 1,
97219721
width: 1,
97229722
margin: 1,
@@ -9798,7 +9798,9 @@ CSSLint.addRule({
97989798

97999799
function reportProperty(name, display){
98009800
if (properties[name]){
9801-
reporter.warn(name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
9801+
if (!(typeof propertiesToCheck[name] == "string") || properties[name].value.toLowerCase() != propertiesToCheck[name]){
9802+
reporter.warn(name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
9803+
}
98029804
}
98039805
}
98049806
}
@@ -9878,7 +9880,8 @@ CSSLint.addRule({
98789880

98799881
//count how many times "float" is used
98809882
parser.addListener("property", function(event){
9881-
if (event.property == "float"){
9883+
if (event.property.text.toLowerCase() == "float" &&
9884+
event.value.text.toLowerCase() != "none"){
98829885
count++;
98839886
}
98849887
});

build/csslint.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9717,7 +9717,7 @@ CSSLint.addRule({
97179717

97189718
var propertiesToCheck = {
97199719
display: 1,
9720-
"float": 1,
9720+
"float": "none",
97219721
height: 1,
97229722
width: 1,
97239723
margin: 1,
@@ -9799,7 +9799,9 @@ CSSLint.addRule({
97999799

98009800
function reportProperty(name, display){
98019801
if (properties[name]){
9802-
reporter.warn(name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
9802+
if (!(typeof propertiesToCheck[name] == "string") || properties[name].value.toLowerCase() != propertiesToCheck[name]){
9803+
reporter.warn(name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
9804+
}
98039805
}
98049806
}
98059807
}
@@ -9879,7 +9881,8 @@ CSSLint.addRule({
98799881

98809882
//count how many times "float" is used
98819883
parser.addListener("property", function(event){
9882-
if (event.property == "float"){
9884+
if (event.property.text.toLowerCase() == "float" &&
9885+
event.value.text.toLowerCase() != "none"){
98839886
count++;
98849887
}
98859888
});

build/npm/lib/csslint-node.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9716,7 +9716,7 @@ CSSLint.addRule({
97169716

97179717
var propertiesToCheck = {
97189718
display: 1,
9719-
"float": 1,
9719+
"float": "none",
97209720
height: 1,
97219721
width: 1,
97229722
margin: 1,
@@ -9798,7 +9798,9 @@ CSSLint.addRule({
97989798

97999799
function reportProperty(name, display){
98009800
if (properties[name]){
9801-
reporter.warn(name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
9801+
if (!(typeof propertiesToCheck[name] == "string") || properties[name].value.toLowerCase() != propertiesToCheck[name]){
9802+
reporter.warn(name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
9803+
}
98029804
}
98039805
}
98049806
}
@@ -9878,7 +9880,8 @@ CSSLint.addRule({
98789880

98799881
//count how many times "float" is used
98809882
parser.addListener("property", function(event){
9881-
if (event.property == "float"){
9883+
if (event.property.text.toLowerCase() == "float" &&
9884+
event.value.text.toLowerCase() != "none"){
98829885
count++;
98839886
}
98849887
});

src/rules/display-property-grouping.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CSSLint.addRule({
1919

2020
var propertiesToCheck = {
2121
display: 1,
22-
"float": 1,
22+
"float": "none",
2323
height: 1,
2424
width: 1,
2525
margin: 1,
@@ -101,7 +101,9 @@ CSSLint.addRule({
101101

102102
function reportProperty(name, display){
103103
if (properties[name]){
104-
reporter.warn(name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
104+
if (!(typeof propertiesToCheck[name] == "string") || properties[name].value.toLowerCase() != propertiesToCheck[name]){
105+
reporter.warn(name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
106+
}
105107
}
106108
}
107109
}

src/rules/floats.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ CSSLint.addRule({
1717

1818
//count how many times "float" is used
1919
parser.addListener("property", function(event){
20-
if (event.property == "float"){
20+
if (event.property.text.toLowerCase() == "float" &&
21+
event.value.text.toLowerCase() != "none"){
2122
count++;
2223
}
2324
});

tests/rules/display-property-grouping.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
Assert.areEqual("float can't be used with display: inline.", result.messages[0].message);
2828
},
2929

30+
"Float:none with inline-block should not result in a warning": function(){
31+
var result = CSSLint.verify(".foo { float: none; display: inline-block; }", { "display-property-grouping": 1 });
32+
Assert.areEqual(0, result.messages.length);
33+
},
34+
35+
"Float:none with inline should result not in a warning": function(){
36+
var result = CSSLint.verify(".foo { float: none; display: inline; }", { "display-property-grouping": 1 });
37+
Assert.areEqual(0, result.messages.length);
38+
},
39+
3040
"Height with inline should result in a warning": function(){
3141
var result = CSSLint.verify(".foo { height: 100px; display: inline; }", { "display-property-grouping": 1 });
3242
Assert.areEqual(1, result.messages.length);
@@ -200,7 +210,17 @@
200210
Assert.areEqual(1, result.messages.length);
201211
Assert.areEqual("warning", result.messages[0].type);
202212
Assert.areEqual("float can't be used with display: table-cell.", result.messages[0].message);
203-
}
213+
},
214+
215+
"Float:none with table-row should not result in a warning": function(){
216+
var result = CSSLint.verify(".foo { float: none; display: table-row; }", { "display-property-grouping": 1 });
217+
Assert.areEqual(0, result.messages.length);
218+
},
219+
220+
"Float:none with table-cell should not result in a warning": function(){
221+
var result = CSSLint.verify(".foo { float: none; display: table-cell; }", { "display-property-grouping": 1 });
222+
Assert.areEqual(0, result.messages.length);
223+
}
204224

205225
}));
206226

tests/rules/floats.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
Assert.areEqual(1, result.messages.length);
2525
Assert.areEqual("warning", result.messages[0].type);
2626
Assert.areEqual("Too many floats (11), abstraction needed.", result.messages[0].message);
27+
},
28+
29+
"float: none should not count and therefore should not result in a warning": function(){
30+
var result = CSSLint.verify(".foo { float: none; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; }", { "floats": 1 });
31+
Assert.areEqual(0, result.messages.length);
2732
}
2833
}));
2934

0 commit comments

Comments
 (0)