UNPKG

1.51 kBMarkdownView Raw
1# length-zero-no-unit
2
3Disallow units for zero lengths.
4
5<!-- prettier-ignore -->
6```css
7a { top: 0px; }
8/** ↑↑
9 * This zero and this type of length unit */
10```
11
12_Lengths_ refer to distance measurements. A length is a _dimension_, which is a _number_ immediately followed by a _unit identifier_. However, for zero lengths the unit identifier is optional. The length units are: `em`, `ex`, `ch`, `vw`, `vh`, `cm`, `mm`, `in`, `pt`, `pc`, `px`, `rem`, `vmin`, and `vmax`.
13
14This rule ignores lengths within math functions (e.g. `calc`) in favor of the [`function-calc-no-invalid`](../function-calc-no-invalid/README.md) rule.
15
16The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule.
17
18## Options
19
20### `true`
21
22The following patterns are considered violations:
23
24<!-- prettier-ignore -->
25```css
26a { top: 0px }
27```
28
29<!-- prettier-ignore -->
30```css
31a { top: 0.000em }
32```
33
34The following patterns are _not_ considered violations:
35
36<!-- prettier-ignore -->
37```css
38a { top: 0 } /* no unit */
39```
40
41<!-- prettier-ignore -->
42```css
43a { transition-delay: 0s; } /* dimension */
44```
45
46<!-- prettier-ignore -->
47```css
48a { top: 2in; }
49```
50
51<!-- prettier-ignore -->
52```css
53a { top: 1.001vh }
54```
55
56## Optional secondary options
57
58### `ignore: ["custom-properties"]`
59
60#### `"custom-properties"`
61
62Ignore units for zero length in custom properties.
63
64The following pattern is _not_ considered a violation:
65
66<!-- prettier-ignore -->
67```css
68a { --x: 0px; }
69```