-
-
Notifications
You must be signed in to change notification settings - Fork 930
/
README.md
202 lines (170 loc) · 3.81 KB
/
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# declaration-block-no-redundant-longhand-properties
Disallow redundant longhand properties within declaration-block.
<!-- prettier-ignore -->
```css
a {
padding-top: 1px;
padding-right: 2px;
padding-bottom: 3px;
padding-left: 4px; }
/** ↑
* These longhand properties */
```
The longhand properties in the example above can be more concisely written as:
<!-- prettier-ignore -->
```css
a {
padding: 1px 2px 3px 4px;
}
```
This rule will only complain if you've used the longhand equivalent of _all_ the properties that the shorthand will set and if their values are not [CSS-wide keywords](https://www.w3.org/TR/css-values/#common-keywords) like `initial`, `inherit` etc.
This rule complains when the following shorthand properties can be used:
- `margin`
- `padding`
- `inset`
- `background`
- `font`
- `border`
- `border-top`
- `border-bottom`
- `border-left`
- `border-right`
- `border-width`
- `border-style`
- `border-color`
- `list-style`
- `border-radius`
- `transition`
- `animation`
- `border-block-end`
- `border-block-start`
- `border-image`
- `border-inline-end`
- `border-inline-start`
- `column-rule`
- `columns`
- `flex`
- `flex-flow`
- `grid`
- `grid-area`
- `grid-column`
- `grid-gap`
- `grid-row`
- `grid-template`
- `outline`
- `text-decoration`
- `text-emphasis`
- `mask`
**Please note** that properties are considered to be redundant if they may be written shorthand according to the specification, **regardless of the behavior of any individual browser**. For example, due to Internet Explorer's implementation of Flexbox, [it may not be possible to use the shorthand property `flex`](https://github.com/philipwalton/flexbugs#flexbug-8), but the longhand form is still considered a problem.
Flexbox-related properties can be ignored using `ignoreShorthands: ["/flex/"]` (see below).
The [`fix` option](../../../docs/user-guide/options.md#fix) can automatically fix most of the problems reported by this rule.
The [`message` secondary option](../../../docs/user-guide/configure.md#message) can accept the arguments of this rule.
## Options
### `true`
The following patterns are considered problems:
<!-- prettier-ignore -->
```css
a {
margin-top: 1px;
margin-right: 2px;
margin-bottom: 3px;
margin-left: 4px;
}
```
<!-- prettier-ignore -->
```css
a {
font-style: italic;
font-variant: normal;
font-weight: bold;
font-stretch: normal;
font-size: 14px;
line-height: 1.2;
font-family: serif;
}
```
<!-- prettier-ignore -->
```css
a {
-webkit-transition-property: top;
-webkit-transition-duration: 2s;
-webkit-transition-timing-function: ease;
-webkit-transition-delay: 0.5s;
}
```
The following patterns are _not_ considered problems:
<!-- prettier-ignore -->
```css
a {
margin: 1px 2px 3px 4px;
}
```
<!-- prettier-ignore -->
```css
a {
font: italic normal bold normal 14px/1.2 serif;
}
```
<!-- prettier-ignore -->
```css
a {
-webkit-transition: top 2s ease 0.5s;
}
```
<!-- prettier-ignore -->
```css
a {
margin-top: 1px;
margin-right: 2px;
}
```
<!-- prettier-ignore -->
```css
a {
margin-top: 1px;
margin-right: 2px;
margin-bottom: 3px;
}
```
## Optional secondary options
### `ignoreShorthands: ["/regex/", /regex/, "string"]`
Given:
```json
["padding", "/border/"]
```
The following patterns are _not_ considered problems:
<!-- prettier-ignore -->
```css
a {
padding-top: 20px;
padding-right: 10px;
padding-bottom: 30px;
padding-left: 10px;
}
```
<!-- prettier-ignore -->
```css
a {
border-top-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-width: 1px;
}
```
<!-- prettier-ignore -->
```css
a {
border-top-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-width: 1px;
}
```
<!-- prettier-ignore -->
```css
a {
border-top-color: green;
border-top-style: double;
border-top-width: 7px;
}
```