1 | # max-line-length
|
2 |
|
3 | Limit the length of a line.
|
4 |
|
5 |
|
6 | ```css
|
7 | a { color: red }
|
8 | /** ↑
|
9 | * The end */
|
10 | ```
|
11 |
|
12 | Lines that exceed the maximum length but contain no whitespace (other than at the beginning of the line) are ignored.
|
13 |
|
14 | When 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 |
|
20 | For example, with `20`:
|
21 |
|
22 | The following patterns are considered violations:
|
23 |
|
24 |
|
25 | ```css
|
26 | a { color: 0; top: 0; }
|
27 | ```
|
28 |
|
29 |
|
30 | ```css
|
31 | a {
|
32 | background: linear-gradient(red, blue);
|
33 | }
|
34 | ```
|
35 |
|
36 | The following patterns are _not_ considered violations:
|
37 |
|
38 |
|
39 | ```css
|
40 | a {
|
41 | color: 0;
|
42 | top: 0;
|
43 | }
|
44 | ```
|
45 |
|
46 |
|
47 | ```css
|
48 | a {
|
49 | background: url(a-url-that-is-over-20-characters-long);
|
50 | }
|
51 | ```
|
52 |
|
53 | ## Optional secondary options
|
54 |
|
55 | ### `ignore: ["non-comments"]`
|
56 |
|
57 | Only enforce the line-length limit for lines within comments.
|
58 |
|
59 | This 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 |
|
61 | For example, with a maximum length of `30`.
|
62 |
|
63 | The following patterns are considered violations:
|
64 |
|
65 | Each have only one violation.
|
66 |
|
67 |
|
68 | ```css
|
69 | /* This line is too long for my rule */
|
70 | a { color: pink; background: orange; }
|
71 | a { color: pink; /* this comment is also long but not on its own line */ }
|
72 | ```
|
73 |
|
74 |
|
75 | ```css
|
76 | a { 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 | */
|
82 | a { color: pink; /* this comment is also long but not on its own line */ }
|
83 | ```
|
84 |
|
85 | ### `ignore: ["comments"]`
|
86 |
|
87 | Only enforce the line-length limit for lines that are not comments.
|
88 |
|
89 | This also applies to comments that are between code on the same line.
|
90 |
|
91 | For example, with a maximum length of `30`.
|
92 |
|
93 | The following patterns are considered violations:
|
94 |
|
95 |
|
96 | ```css
|
97 | a { color: pink; } /* comment that is too long */
|
98 | ```
|
99 |
|
100 |
|
101 | ```css
|
102 | a { /* this comment is too long for the max length */ }
|
103 | ```
|
104 |
|
105 | The following patterns are _not_ considered violations:
|
106 |
|
107 |
|
108 | ```css
|
109 | /* comment that is too long for my rule*/
|
110 | a { color: pink; }
|
111 | ```
|
112 |
|
113 |
|
114 | ```css
|
115 | /*
|
116 | * comment that is too long the max length
|
117 | * comment that is too long the max length
|
118 | *
|
119 | */
|
120 | a { color: pink; }
|
121 | ```
|
122 |
|
123 | ### `ignorePattern: "/regex/"`
|
124 |
|
125 | Ignore 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 |
|
127 | Given:
|
128 |
|
129 | ```
|
130 | "/^@import\\s+/"
|
131 | ```
|
132 |
|
133 | The following pattern is _not_ considered a violation:
|
134 |
|
135 |
|
136 | ```css
|
137 | @import "../../../../another/css/or/scss/file/or/something.css";
|
138 | ```
|
139 |
|
140 | Given the following, with a maximum length of `20`.
|
141 |
|
142 | ```js
|
143 | ["/https?://[0-9,a-z]*.*/"];
|
144 | ```
|
145 |
|
146 | The following pattern is _not_ considered a violation:
|
147 |
|
148 |
|
149 | ```css
|
150 | /* ignore urls https://www.example.com */
|
151 | ```
|