1 | # declaration-block-no-duplicate-properties
|
2 |
|
3 | Disallow duplicate properties within declaration blocks.
|
4 |
|
5 |
|
6 | ```css
|
7 | a { color: pink; color: orange; }
|
8 | /** ↑ ↑
|
9 | * These duplicated properties */
|
10 | ```
|
11 |
|
12 | This rule ignores variables (`$sass`, `@less`, `--custom-property`).
|
13 |
|
14 | ## Options
|
15 |
|
16 | ### `true`
|
17 |
|
18 | The following patterns are considered violations:
|
19 |
|
20 |
|
21 | ```css
|
22 | a { color: pink; color: orange; }
|
23 | ```
|
24 |
|
25 |
|
26 | ```css
|
27 | a { color: pink; background: orange; color: orange }
|
28 | ```
|
29 |
|
30 | The following patterns are _not_ considered violations:
|
31 |
|
32 |
|
33 | ```css
|
34 | a { color: pink; }
|
35 | ```
|
36 |
|
37 |
|
38 | ```css
|
39 | a { color: pink; background: orange; }
|
40 | ```
|
41 |
|
42 | ## Optional secondary options
|
43 |
|
44 | ### `ignore: ["consecutive-duplicates"]`
|
45 |
|
46 | Ignore consecutive duplicated properties.
|
47 |
|
48 | They can prove to be useful fallbacks for older browsers.
|
49 |
|
50 | The following patterns are considered violations:
|
51 |
|
52 |
|
53 | ```css
|
54 | p {
|
55 | font-size: 16px;
|
56 | font-weight: 400;
|
57 | font-size: 1rem;
|
58 | }
|
59 | ```
|
60 |
|
61 | The following patterns are _not_ considered violations:
|
62 |
|
63 |
|
64 | ```css
|
65 | p {
|
66 | font-size: 16px;
|
67 | font-size: 1rem;
|
68 | font-weight: 400;
|
69 | }
|
70 | ```
|
71 |
|
72 | ### `ignore: ["consecutive-duplicates-with-different-values"]`
|
73 |
|
74 | Ignore consecutive duplicated properties with different values.
|
75 |
|
76 | Including duplicate properties (fallbacks) is useful to deal with older browsers support for CSS properties. E.g. using `px` units when `rem` isn't available.
|
77 |
|
78 | The following patterns are considered violations:
|
79 |
|
80 |
|
81 | ```css
|
82 | /* properties with the same value */
|
83 | p {
|
84 | font-size: 16px;
|
85 | font-size: 16px;
|
86 | font-weight: 400;
|
87 | }
|
88 | ```
|
89 |
|
90 |
|
91 | ```css
|
92 | /* nonconsecutive duplicates */
|
93 | p {
|
94 | font-size: 16px;
|
95 | font-weight: 400;
|
96 | font-size: 1rem;
|
97 | }
|
98 | ```
|
99 |
|
100 | The following patterns are _not_ considered violations:
|
101 |
|
102 |
|
103 | ```css
|
104 | p {
|
105 | font-size: 16px;
|
106 | font-size: 1rem;
|
107 | font-weight: 400;
|
108 | }
|
109 | ```
|
110 |
|
111 | ### `ignoreProperties: ["/regex/", "non-regex"]`
|
112 |
|
113 | Ignore duplicates of specific properties.
|
114 |
|
115 | Given:
|
116 |
|
117 | ```
|
118 | ["color", "/background-/"]
|
119 | ```
|
120 |
|
121 | The following patterns are considered violations:
|
122 |
|
123 |
|
124 | ```css
|
125 | a { color: pink; background: orange; background: white; }
|
126 | ```
|
127 |
|
128 |
|
129 | ```css
|
130 | a { background: orange; color: pink; background: white; }
|
131 | ```
|
132 |
|
133 | The following patterns are _not_ considered violations:
|
134 |
|
135 |
|
136 | ```css
|
137 | a { color: pink; color: orange; background-color: orange; background-color: white; }
|
138 | ```
|
139 |
|
140 |
|
141 | ```css
|
142 | a { color: pink; background-color: orange; color: orange; background-color: white; }
|
143 | ```
|