Skip to content

Commit e025e5a

Browse files
committed
Make sure box model rule doesn't warn when width or height are set to auto, etc. (fixes #287)
1 parent 14033f6 commit e025e5a

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/rules/box-model.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ CSSLint.addRule({
3737
}
3838

3939
function endRule(){
40-
var prop;
40+
var prop, value;
4141
if (properties.height){
4242
for (prop in heightProperties){
4343
if (heightProperties.hasOwnProperty(prop) && properties[prop]){
44-
44+
value = properties[prop].value;
4545
//special case for padding
46-
if (!(prop == "padding" && properties[prop].value.parts.length === 2 && properties[prop].value.parts[0].value === 0)){
46+
if (!(prop == "padding" && value.parts.length === 2 && value.parts[0].value === 0)){
4747
reporter.report("Using height with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
4848
}
4949
}
@@ -53,8 +53,9 @@ CSSLint.addRule({
5353
if (properties.width){
5454
for (prop in widthProperties){
5555
if (widthProperties.hasOwnProperty(prop) && properties[prop]){
56-
57-
if (!(prop == "padding" && properties[prop].value.parts.length === 2 && properties[prop].value.parts[1].value === 0)){
56+
value = properties[prop].value;
57+
58+
if (!(prop == "padding" && value.parts.length === 2 && value.parts[1].value === 0)){
5859
reporter.report("Using width with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
5960
}
6061
}
@@ -76,7 +77,7 @@ CSSLint.addRule({
7677
properties[name] = { line: event.property.line, col: event.property.col, value: event.value };
7778
}
7879
} else {
79-
if (name == "width" || name == "height"){
80+
if (/^(width|height)/i.test(name) && /^(length|percentage)/.test(event.value.parts[0].type)){
8081
properties[name] = 1;
8182
}
8283
}

tests/rules/box-model.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,22 @@
1818
var result = CSSLint.verify(".foo { width: 100px; padding: 0; }", { "box-model": 1 });
1919
Assert.areEqual(0, result.messages.length);
2020
},
21+
22+
"Using width:auto with padding should not result in a warning": function(){
23+
var result = CSSLint.verify(".foo { width: auto; padding: 10px; }", { "box-model": 1 });
24+
Assert.areEqual(0, result.messages.length);
25+
},
2126

27+
"Using width:available with padding should not result in a warning": function(){
28+
var result = CSSLint.verify(".foo { width: available; padding: 10px; }", { "box-model": 1 });
29+
Assert.areEqual(0, result.messages.length);
30+
},
31+
32+
"Using height:auto with padding should not result in a warning": function(){
33+
var result = CSSLint.verify(".foo { height: auto; padding: 10px; }", { "box-model": 1 });
34+
Assert.areEqual(0, result.messages.length);
35+
},
36+
2237
"Using width and padding-left should result in a warning": function(){
2338
var result = CSSLint.verify(".foo { width: 100px; padding-left: 10px; }", { "box-model": 1 });
2439
Assert.areEqual(1, result.messages.length);

0 commit comments

Comments
 (0)