CSSLint / csslint

Automated linting of Cascading Stylesheets
http://csslint.net
Other
4.77k stars 483 forks source link

Would be good to have allow-blocks, like ignore-blocks, in addition to oneline version #640

Open rowanthorpe opened 8 years ago

rowanthorpe commented 8 years ago

With great joy I saw the csslint-ignore-block and csslint-allow-line features were merged recently (I've been cherrypicking them both for personal use since they were PR-ed). It would be nice if we could also have multiline allow-blocks (like ignore-blocks) for certain feature(s), e.g:

@viewport {
    /* csslint allow(known-properties, important):start */
    orientation: landscape !important;
    color: red !important;
    /* csslint allow(known-properties, important):end */
    width: auto;
}

Obviously this is a contrived/unimaginative example for illustration-purposes. It probably wouldn't be worth trying to support highly sophisticated permutations (like doing "allow-start" for 2 features, then "allow-stop" for 1 of them, then "allow-start" a 3rd, then "allow-stop" 1st & 3rd...), but at least a version which exactly matches the parameter-list in the start and stop commands would be helpful, or even a more simple/robust/flexible-but-more-verbose solution could take only one parameter (so starting/stopping multiple features would require multiple start comments and multiple stop comments...):

/* csslint allow(known-properties):start */
/* csslint allow(important):start */
[blah blah blah]
/* csslint allow(important):end */
[blah blah blah]
/* csslint allow(known-properties):end */

However the implementation, the two benefits would be:

  1. (obvious) a concise way to allow a specific feature over multiple lines
  2. (not-so-obvious) a non-breaking "allow" when generating css with tools like Sass

The problem when generating from Sass with the existing "allow" oneline-construct can be seen below:

  1. SCSS

    orientation: landscape; /* csslint allow: known-properties */

    ...becomes...

    CSS

    orientation: landscape;
    /* csslint allow: known-properties */
  2. SCSS

    /* csslint allow: known-properties */ orientation: landscape;

    ...becomes...

    CSS

    /* csslint allow: known-properties */
    orientation: landscape;
  3. SCSS

    orientation: landscape /* csslint allow: known-properties */ ;

    ...becomes...

    CSS

    orientation: landscape;

Pinging @akrawitz ("allow" creator) and @cwygoda ("ignore" creator) for feedback. Do you have suggestions for better syntax than I suggested? Also, if someone does implement allow-blocks ("ignore" syntax), for the sake of symmetry is it worth also implementing ignore-lines ("allow" syntax)? (which would be an easy hack).

cwygoda commented 8 years ago

I think having an common set of ways to specify allow and ignore on line and block level would be good. This could also be used to implement both features in a common way to reduce complexity.