CSSLint: Ignore single line in CSS file?
Asked Answered
L

4

6

I'm working with a CSS file that uses Mozilla's -moz-element(#element) directive for a background-image. The code looks like:

#foo {background-image: -moz-element(#element);}

When I run this through CSSLint, it tells me that the "Rule is empty", despite the fact that it's obviously not. I could attempt to run CSSLint via command line and use --ignore, but what I'm really looking for is a way to ignore just that single line from within my CSS file. Is there a way to do that?

And just for clarity, what I'm looking for is the analogue to how JSHint does things, which looks like this:

var notChecked = 'This line won't get checked'; // jshint ignore:line

Leverhulme answered 25/3, 2015 at 6:22 Comment(3)
I don't know CSSList, but if it really treats -moz- prefixed names as not there, you might get away with putting this line inside a @-moz-document rule. See MDN.Aggravate
Not really looking for a way to hack my code to get it to work with CSSLint (I'd just disable CSSLint completely before I did that). Looking for an elegant one-line ignore that keeps things nice. Thanks tho.Leverhulme
Wouldn't it be better to figure out why CSSLint reports a spurious warning for that line, and fix that issue, rather than trying to ignore the line?Naevus
L
2

CSSLint does not currently support a single-line ignore function from within a CSS file. Hopefully (would be awesome!) this changes in the future.

Leverhulme answered 1/4, 2015 at 2:2 Comment(0)
C
8

Using an embedded ruleset:

/*csslint important: false*/

.example {
  display: none ! important 
}

/*csslint important: true*/
Chantry answered 8/2, 2016 at 0:11 Comment(1)
Status: Not worked for me. // 1. It's not documented. // 2. It doesn't worked, if I needed to ignore 2 or more rules in the same file. Example. // Thanks.Houdon
L
2

CSSLint does not currently support a single-line ignore function from within a CSS file. Hopefully (would be awesome!) this changes in the future.

Leverhulme answered 1/4, 2015 at 2:2 Comment(0)
P
0

One can also ignore sections with:

/* csslint ignore:start */
@import('normalize.css');
/* csslint ignore:end */

And also allow:

.foo.bar { /* csslint allow: adjoining-classes */
  margin: 0;
}
Piero answered 27/9, 2016 at 14:52 Comment(3)
v0.5 came out 5 years ago (July 29, 2011 - v0.5.0). I suggest you upgrade to v1.0.Piero
Doesn't work for me in 1.0.4. For example: /* csslint ignore:start */ section { display: grid; grid-template-columns: 1fr 3fr; } / * csslint ignore:end */Labored
The GitHub repository is linked in the answer. Feel free to review the current issues and create a new one if none exists.Piero
M
-2

In version 0.9.10+ you can use "embedded rulesets" directly in the CSS file.

If that doesn't work, you could try placing that line in a CSS comment, for example:

/* #foo {background-image: -moz-element(#element);} */
Moreau answered 25/3, 2015 at 17:11 Comment(1)
Do you know how I'd use the "embedded rulesets" to single-out and ignore a solitary line?Leverhulme

© 2022 - 2024 — McMap. All rights reserved.