csslint icon indicating copy to clipboard operation
csslint copied to clipboard

Rule is empty when defining root-only CSS variables

Open eliperelman opened this issue 10 years ago • 14 comments

When using csslint with variables against the :root element, it throws the message of "rule is empty".

:root {
  --color-alpha: #fff;
}

This rule should not be considered empty against the :root element that only contains CSS variables as it is considered the de-facto way to create them globally.

eliperelman avatar Sep 04 '14 16:09 eliperelman

+1

mikehenrty avatar Sep 04 '14 18:09 mikehenrty

I agree. This style of variable definition is used in http://github.com/suitcss/suit, which is based on a future css spec. Maybe allow for the user to turn this off?

ismay avatar Sep 12 '14 16:09 ismay

+1 (two years later), also:

  • If you add more than one variable, a Expected RBRACE error pops up.
  • Using a variable in the css then shows these warnings:
    • Set color: Expected (<color> | inherit) but found 'var(--color-alpha)'.
    • Set border-color: Expected (<color>{1,4}) but found 'var(--color-alpha)'.

Mottie avatar Sep 18 '16 15:09 Mottie

caused by https://github.com/CSSLint/parser-lib/issues/120?

gabriellecrawford avatar Oct 14 '16 23:10 gabriellecrawford

@tophf Has fixed this problem, and many others, in our heavily modified version of csslint in case anyone is interested.

Mottie avatar Dec 24 '17 15:12 Mottie

Still broken.

dcloutman avatar Feb 14 '18 16:02 dcloutman

@Mottie @tophf Thanks for suggesting a workaround and your work on this. Can you confirm the license of your modified version? https://github.com/openstyles/stylus/tree/master/vendor-overwrites/csslint

seanw avatar Feb 27 '18 15:02 seanw

We didn't change the license:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

tophf avatar Feb 27 '18 17:02 tophf

@tophf Thanks, the repo is marked as GPL so I wanted to be 100% sure here that you're allowing others to use the modifications under the original non-GPL license.

seanw avatar Feb 27 '18 17:02 seanw

You could also just use a modern (and maintained) style code linter like stylelint 😉.

Arcanemagus avatar Feb 27 '18 17:02 Arcanemagus

Stylelint doesn't validate the css (ref). The authors are deferring the validation to csstree.

That and csslint is less than 100KB in size while Stylelint (without csstree) is over 3MB in size and does not work with browserify nor rollup – which is why we ended up creating the stylelint-bundle repository which removes some of the functionality to get stylelint to bundle and work properly.

Mottie avatar Feb 27 '18 17:02 Mottie

From a security perspective, one pro of csslint is that it doesn't use eval anywhere which isn't the case for csstree last time I checked.

seanw avatar Feb 27 '18 18:02 seanw

@seanw From a functionality perspective, one con of csslint is that it doesn't work on modern CSS including custom properties.

rtm avatar Sep 23 '18 08:09 rtm

What is the solution of this?

Ademord avatar Mar 04 '20 14:03 Ademord