1
0
mirror of https://github.com/thangisme/notes.git synced 2024-06-20 20:25:28 +00:00
notes/node_modules/stylelint-scss/src/rules/dollar-variable-no-missing-interpolation/README.md
Patrick Marsceill b7b0d0d7bf
Initial commit
2017-03-09 13:16:08 -05:00

112 lines
2.0 KiB
Markdown

# dollar-variable-no-missing-interpolation
Disallow Sass variables that are used without interpolation with CSS features that use custom identifiers.
```scss
.class {
$var: "my-anim";
animation-name: $var;
// ↑
// This variable needs to be interpolated
// because its value is a string
}
```
Sass variables that contain a custom identifier as a string always require interpolation when used. Some CSS [at-rules](https://css-tricks.com/the-at-rules-of-css/) require variable interpolation even when the custom identifier value is not a string.
For example, your CSS animation could look like this:
```scss
animation: myAnim 5s;
```
When you store your custom identifier as string in a Sass variable...
```scss
$myVar: "myAnim";
```
...then you need to make sure that the variable is interpolated when it gets used:
```scss
animation: #{$myVar} 5s;
```
If you do not interpolate the variable, Sass will compile your animation name to a string, producing invalid CSS:
```scss
animation: "myAnim" 5s;
```
This rule can only check for variables that are defined inside the same file where they are used.
The following patterns are considered warnings:
```scss
$var: my-anim;
@keyframes $var {}
```
```scss
$var: "circled-digits";
@counter-style $var {
system: fixed;
symbols: ;
suffix: ' ';
speak-as: numbers;
}
```
```scss
$var: "my-counter";
body {
counter-reset: $var;
}
```
```scss
$var: "my-anim";
@supports (animation-name: $var) {
@keyframes {}
}
```
The following patterns are *not* considered warnings:
```scss
$var: my-anim;
@keyframes #{$var} {}
```
```scss
$var: circled-digits;
@counter-style #{$var} {
system: fixed;
symbols: ;
suffix: ' ';
speak-as: numbers;
}
```
```scss
$var: my-counter;
body {
counter-reset: $var;
}
```
```scss
$var: my-anim;
@supports (animation-name: $var) {
@keyframes {}
}
```