Skip to content

Commit 34263b1

Browse files
author
Nicholas C. Zakas
committed
Fixed bug with box model rule (fixes CSSLint#135)
1 parent 67b91ee commit 34263b1

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Next (not yet released)
22

3+
* Fixed bug with box model rule (fixes #135)
34
* Added rule to check property name against list of known properties (fixes #136)
45
* Ensure consistency across error messages (fixes #89)
56
* Updated parser to handle CSS escaping (fixes #97)

src/rules/box-model.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ CSSLint.addRule({
4040

4141
if (heightProperties[name] || widthProperties[name]){
4242
if (!/^0\S*$/.test(event.value) && !(name == "border" && event.value == "none")){
43-
properties[name] = { line: event.property.line, col: event.property.col };
43+
properties[name] = { line: event.property.line, col: event.property.col, value: event.value };
4444
}
4545
} else {
4646
if (name == "width" || name == "height"){
@@ -55,15 +55,26 @@ CSSLint.addRule({
5555
if (properties["height"]){
5656
for (prop in heightProperties){
5757
if (heightProperties.hasOwnProperty(prop) && properties[prop]){
58-
reporter.warn("Broken box model: using height with " + prop + ".", properties[prop].line, properties[prop].col, rule);
58+
59+
//special case for padding
60+
if (prop == "padding" && properties[prop].value.parts.length == 2 && properties[prop].value.parts[0].value == 0){
61+
//noop
62+
} else {
63+
reporter.warn("Broken box model: using height with " + prop + ".", properties[prop].line, properties[prop].col, rule);
64+
}
5965
}
6066
}
6167
}
6268

6369
if (properties["width"]){
6470
for (prop in widthProperties){
6571
if (widthProperties.hasOwnProperty(prop) && properties[prop]){
66-
reporter.warn("Broken box model: using width with " + prop + ".", properties[prop].line, properties[prop].col, rule);
72+
73+
if (prop == "padding" && properties[prop].value.parts.length == 2 && properties[prop].value.parts[1].value == 0){
74+
//noop
75+
} else {
76+
reporter.warn("Broken box model: using width with " + prop + ".", properties[prop].line, properties[prop].col, rule);
77+
}
6778
}
6879
}
6980
}

tests/rules/box-model.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
var result = CSSLint.verify(".foo { width: 100px; padding-bottom: 10px; }", { "box-model": 1 });
5353
Assert.areEqual(0, result.messages.length);
5454
},
55+
56+
"Using width and padding-to-bottom should not result in a warning": function(){
57+
var result = CSSLint.verify(".foo { width: 100px; padding: 10px 0; }", { "box-model": 1 });
58+
Assert.areEqual(0, result.messages.length);
59+
},
5560

5661
"Using width and border should result in a warning": function(){
5762
var result = CSSLint.verify(".foo { width: 100px; border: 10px; }", { "box-model": 1 });
@@ -115,6 +120,11 @@
115120
var result = CSSLint.verify(".foo { height: 100px; padding-right: 10px; }", { "box-model": 1 });
116121
Assert.areEqual(0, result.messages.length);
117122
},
123+
124+
"Using height and padding-left-right should not result in a warning": function(){
125+
var result = CSSLint.verify(".foo { height: 100px; padding: 0 10px; }", { "box-model": 1 });
126+
Assert.areEqual(0, result.messages.length);
127+
},
118128

119129
"Using height and padding-top should result in a warning": function(){
120130
var result = CSSLint.verify(".foo { height: 100px; padding-top: 10px; }", { "box-model": 1 });

0 commit comments

Comments
 (0)