# stylelint-declaration-use-variable

> A stylelint custom rule to check the use of scss variable on declaration.

Latest version **1.7.3** (published 2021-05-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install stylelint-declaration-use-variable
pnpm add stylelint-declaration-use-variable
yarn add stylelint-declaration-use-variable
bun add stylelint-declaration-use-variable
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.7.3 |
| Published | 2021-05-15 |
| First published | 2016-03-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 81 |
| Author | sh-waqar |
| Maintainers | sh-waqar, stukalin |
| Keywords | stylelint, stylelint-plugin, css, variable, scss, z-index, color |

## Links

- npm: https://www.npmjs.com/package/stylelint-declaration-use-variable
- Repository: https://github.com/sh-waqar/stylelint-declaration-use-variable
- Issues: https://github.com/sh-waqar/stylelint-declaration-use-variable/issues
- npm.io page: https://npm.io/package/stylelint-declaration-use-variable

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 1.7.3 (latest) — 2021-05-15
- 1.7.2 — 2019-11-04
- 1.7.1 — 2019-11-04
- 1.7.0 — 2018-07-31
- 1.6.1 — 2018-02-23
- 1.6.0 — 2016-08-27
- 1.5.0 — 2016-07-21
- 1.4.0 — 2016-07-02
- 1.3.0 — 2016-05-08
- 1.2.0 — 2016-05-07
- 1.1.0 — 2016-03-13
- 0.0.2 — 2016-03-10
- 1.0.1 — 2016-03-10
- 1.0.0 — 2016-03-03

## README

# stylelint-declaration-use-variable

[![Build Status](https://travis-ci.org/sh-waqar/stylelint-declaration-use-variable.svg?branch=master)](https://travis-ci.org/sh-waqar/stylelint-declaration-use-variable)

**:warning: This project is not actively maintained. Please use [stylelint-declaration-strict-value](https://github.com/AndyOGo/stylelint-declaration-strict-value) :warning:**

A [stylelint](https://github.com/stylelint/stylelint) plugin that check the use of scss, less or custom css variable on declaration. Either used with '$', map-get(), '@' or 'var(--var-name)'.

## Installation

```
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.

## Usage

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:

```js
// .stylelintrc
{
  "plugins": [
    "stylelint-declaration-use-variable"
  ],
  "rules": {
    // ...
    "sh-waqar/declaration-use-variable": "color",
    // ...
  }
}
```

#### Multiple properties

Multiple properties can be watched by passing them inside array. Regex can also be used inside arrays.

```js
// .stylelintrc
"rules": {
  // ...
  "sh-waqar/declaration-use-variable": [["/color/", "z-index", "font-size"]],
  // ...
}
```

#### Regex support

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.

```js
// .stylelintrc
"rules": {
  // ...
  "sh-waqar/declaration-use-variable": "/color/",
  // ...
}
```

#### Options

Passing `ignoreValues` option, you can accept values which are exact same string or matched by Regex

```js
// .stylelintrc
"rules": {
  // ...
  "sh-waqar/declaration-use-variable": [["/color/", "font-size", { ignoreValues: ["transparent", "inherit", "/regexForspecialFunc/"] }]],
  // ...
}
```

## Details

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.

```scss
$some-cool-color: #efefef;

.foo {
    display: inline-block;
    text-align: center;
    color: #efefef; // Wait a min! there should be a variable.
}
```

### Supported scss variables

Scss variables using '$' notation and map-get are supported
```scss
// 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);

```

### Supported color functions

If you plan to level-up the usage of your variables by the usage of fancy [color-functions](https://github.com/postcss/postcss-color-function) - you can!

Instead of a direct variable usage like this:
```scss
$white: #fff;

.foo {
  color: $white;
}
```

You could also do things like:
```scss
.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.

---
_Source: https://npm.io/package/stylelint-declaration-use-variable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
