Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
stylelint-declaration-use-variable
Advanced tools
A stylelint custom rule to check the use of scss variable on declaration.
:warning: This project is not actively maintained. Please use stylelint-declaration-strict-value :warning:
A stylelint plugin that check the use of scss, less or custom css variable on declaration. Either used with '$', map-get(), '@' or 'var(--var-name)'.
npm install stylelint-declaration-use-variable
Be warned: v0.2.0+ is only compatible with stylelint v3+. For earlier version of stylelint, use earlier versions of this.
Add it to your stylelint config plugins
array, then add "declaration-use-variable"
to your rules,
specifying the property for which you want to check the usage of variable.
Like so:
// .stylelintrc
{
"plugins": [
"stylelint-declaration-use-variable"
],
"rules": {
// ...
"sh-waqar/declaration-use-variable": "color",
// ...
}
}
Multiple properties can be watched by passing them inside array. Regex can also be used inside arrays.
// .stylelintrc
"rules": {
// ...
"sh-waqar/declaration-use-variable": [["/color/", "z-index", "font-size"]],
// ...
}
Passing a regex will watch the variable usage for all matching properties. This rule will match all CSS properties while ignoring Sass and Less variables.
// .stylelintrc
"rules": {
// ...
"sh-waqar/declaration-use-variable": "/color/",
// ...
}
Passing ignoreValues
option, you can accept values which are exact same string or matched by Regex
// .stylelintrc
"rules": {
// ...
"sh-waqar/declaration-use-variable": [["/color/", "font-size", { ignoreValues: ["transparent", "inherit", "/regexForspecialFunc/"] }]],
// ...
}
Preprocessers like scss, less uses variables to make the code clean, maintainable and reusable. But since developers are lazy they might get a chance to miss the use of variables in styling code and that kinda sucks.
$some-cool-color: #efefef;
.foo {
display: inline-block;
text-align: center;
color: #efefef; // Wait a min! there should be a variable.
}
Scss variables using '$' notation and map-get are supported
// Simple variables
$some-cool-color: #efefef;
$some-integer: 123;
$some-pixels: 4px;
color: $some-cool-color;
// Using map-get
$cool-colors: (
blue: #3ea1ec,
red: #eb5745,
);
color: map-get($cool-colors, blue);
If you plan to level-up the usage of your variables by the usage of fancy color-functions - you can!
Instead of a direct variable usage like this:
$white: #fff;
.foo {
color: $white;
}
You could also do things like:
.foo {
color: color($white shade(10%));
}
This will still be seen as a valid code by the plugin. As a side-note, it doesn't matter what kind of variable-syntax
you are using in the color function itself - if the line starts with color(
then it is seen as valid.
If you contribute and wonder about the check for
color(
- it couldn't be done via regex because not only values will be passed to the plugin, but also property names. For some reason, the plugin just dies if you start extending the regex to look for "color". So it must be done via extra-if-check.
FAQs
A stylelint custom rule to check the use of scss variable on declaration.
The npm package stylelint-declaration-use-variable receives a total of 29,843 weekly downloads. As such, stylelint-declaration-use-variable popularity was classified as popular.
We found that stylelint-declaration-use-variable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.