UNPKG

3.31 kBMarkdownView Raw
1# max-line-length
2
3Limit the length of a line.
4
5<!-- prettier-ignore -->
6```css
7a { color: red }
8/** ↑
9 * The end */
10```
11
12Lines that exceed the maximum length but contain no whitespace (other than at the beginning of the line) are ignored.
13
14When evaluating the line length, the arguments of any `url(...)` functions are excluded from the calculation, because typically you have no control over the length of these arguments. This means that long `url()` functions should not contribute to violations.
15
16## Options
17
18`int`: Maximum number of characters allowed.
19
20For example, with `20`:
21
22The following patterns are considered violations:
23
24<!-- prettier-ignore -->
25```css
26a { color: 0; top: 0; }
27```
28
29<!-- prettier-ignore -->
30```css
31a {
32 background: linear-gradient(red, blue);
33}
34```
35
36The following patterns are _not_ considered violations:
37
38<!-- prettier-ignore -->
39```css
40a {
41 color: 0;
42 top: 0;
43}
44```
45
46<!-- prettier-ignore -->
47```css
48a {
49 background: url(a-url-that-is-over-20-characters-long);
50}
51```
52
53## Optional secondary options
54
55### `ignore: ["non-comments"]`
56
57Only enforce the line-length limit for lines within comments.
58
59This does not apply to comments that are stuck in between other stuff, only to lines that begin at the beginning or in the middle of a comment.
60
61For example, with a maximum length of `30`.
62
63The following patterns are considered violations:
64
65Each have only one violation.
66
67<!-- prettier-ignore -->
68```css
69/* This line is too long for my rule */
70a { color: pink; background: orange; }
71a { color: pink; /* this comment is also long but not on its own line */ }
72```
73
74<!-- prettier-ignore -->
75```css
76a { color: pink; background: orange; }
77/**
78 * This line is short,
79 * but this line is too long for my liking,
80 * though this one is fine
81 */
82a { color: pink; /* this comment is also long but not on its own line */ }
83```
84
85### `ignore: ["comments"]`
86
87Only enforce the line-length limit for lines that are not comments.
88
89This also applies to comments that are between code on the same line.
90
91For example, with a maximum length of `30`.
92
93The following patterns are considered violations:
94
95<!-- prettier-ignore -->
96```css
97a { color: pink; } /* comment that is too long */
98```
99
100<!-- prettier-ignore -->
101```css
102a { /* this comment is too long for the max length */ }
103```
104
105The following patterns are _not_ considered violations:
106
107<!-- prettier-ignore -->
108```css
109/* comment that is too long for my rule*/
110a { color: pink; }
111```
112
113<!-- prettier-ignore -->
114```css
115/*
116 * comment that is too long the max length
117 * comment that is too long the max length
118 *
119 */
120a { color: pink; }
121```
122
123### `ignorePattern: "/regex/"`
124
125Ignore any line that matches the given regex pattern, regardless of whether it is comment or not. The regex may be passed as a string (for JSON configuration) by enclosing in forward-slashes, or an ordinary JavaScript RegExp may be used.
126
127Given:
128
129```
130"/^@import\\s+/"
131```
132
133The following pattern is _not_ considered a violation:
134
135<!-- prettier-ignore -->
136```css
137@import "../../../../another/css/or/scss/file/or/something.css";
138```
139
140Given the following, with a maximum length of `20`.
141
142```js
143["/https?://[0-9,a-z]*.*/"];
144```
145
146The following pattern is _not_ considered a violation:
147
148<!-- prettier-ignore -->
149```css
150/* ignore urls https://www.example.com */
151```