Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

combine.md 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. # Combining rules
  2. You can combine rules to enforce strict conventions.
  3. ## `*-newline/space-before` and `*-newline/space-after` rules
  4. Say you want to enforce no space before and a single space after the colon in every declaration:
  5. <!-- prettier-ignore -->
  6. ```css
  7. a { color: pink; }
  8. /** ↑
  9. * No space before and a single space after this colon */
  10. ```
  11. You can enforce that with:
  12. ```json
  13. {
  14. "declaration-colon-space-after": "always",
  15. "declaration-colon-space-before": "never"
  16. }
  17. ```
  18. Some _things_ (e.g. declaration blocks and value lists) can span more than one line. In these cases, `newline` rules and extra options can be used to provide flexibility.
  19. For example, this is the complete set of `value-list-comma-*` rules and their options:
  20. - `value-list-comma-space-after`: `"always"|"never"|"always-single-line"|"never-single-line"`
  21. - `value-list-comma-space-before`: `"always"|"never"|"always-single-line"|"never-single-line"`
  22. - `value-list-comma-newline-after`: `"always"|"always-multi-line|"never-multi-line"`
  23. - `value-list-comma-newline-before`: `"always"|"always-multi-line"|"never-multi-line"`
  24. Where `*-multi-line` and `*-single-line` are in reference to the value list (the _thing_). For example, given:
  25. <!-- prettier-ignore -->
  26. ```css
  27. a,
  28. b {
  29. color: red;
  30. font-family: sans, serif, monospace; /* single-line value list */
  31. } ↑ ↑
  32. /** ↑ ↑
  33. * The value list starts here and ends here */
  34. ```
  35. There is only a single-line value list in this example. The selector is multi-line, as is the declaration block and, as such, also the rule. But the value list isn't. The `*-multi-line` and `*-single-line` refer to the value list in the context of this rule.
  36. ### Example A
  37. Say you only want to allow single-line value lists. And you want to enforce no space before and a single space after the commas:
  38. <!-- prettier-ignore -->
  39. ```css
  40. a {
  41. font-family: sans, serif, monospace;
  42. box-shadow: 1px 1px 1px red, 2px 2px 1px 1px blue inset, 2px 2px 1px 2px blue inset;
  43. }
  44. ```
  45. You can enforce that with:
  46. ```json
  47. {
  48. "value-list-comma-space-after": "always",
  49. "value-list-comma-space-before": "never"
  50. }
  51. ```
  52. ### Example B
  53. Say you want to allow both single-line and multi-line value lists. You want there to be a single space after the commas in the single-line lists and no space before the commas in both the single-line and multi-line lists:
  54. <!-- prettier-ignore -->
  55. ```css
  56. a {
  57. font-family: sans, serif, monospace; /* single-line value list with space after, but no space before */
  58. box-shadow: 1px 1px 1px red, /* multi-line value list ... */
  59. 2px 2px 1px 1px blue inset, /* ... with newline after, ... */
  60. 2px 2px 1px 2px blue inset; /* ... but no space before */
  61. }
  62. ```
  63. You can enforce that with:
  64. ```json
  65. {
  66. "value-list-comma-newline-after": "always-multi-line",
  67. "value-list-comma-space-after": "always-single-line",
  68. "value-list-comma-space-before": "never"
  69. }
  70. ```
  71. ### Example C
  72. Say you want to allow both single-line and multi-line value lists. You want there to be no space before the commas in the single-line lists and always a space after the commas in both lists:
  73. <!-- prettier-ignore -->
  74. ```css
  75. a {
  76. font-family: sans, serif, monospace;
  77. box-shadow: 1px 1px 1px red
  78. , 2px 2px 1px 1px blue inset
  79. , 2px 2px 1px 2px blue inset;
  80. }
  81. ```
  82. You can enforce that with:
  83. ```json
  84. {
  85. "value-list-comma-newline-before": "always-multi-line",
  86. "value-list-comma-space-after": "always",
  87. "value-list-comma-space-before": "never-single-line"
  88. }
  89. ```
  90. ### Example D
  91. The rules are flexible enough to enforce entirely different conventions for single-line and multi-line lists. Say you want to allow both single-line and multi-line value lists. You want the single-line lists to have a single space before and after the colons. Whereas you want the multi-line lists to have a single newline before the commas, but no space after:
  92. <!-- prettier-ignore -->
  93. ```css
  94. a {
  95. font-family: sans , serif , monospace; /* single-line list with a single space before and after the comma */
  96. box-shadow: 1px 1px 1px red /* multi-line list ... */
  97. ,2px 2px 1px 1px blue inset /* ... with newline before, ... */
  98. ,2px 2px 1px 2px blue inset; /* ... but no space after the comma */
  99. }
  100. ```
  101. You can enforce that with:
  102. ```json
  103. {
  104. "value-list-comma-newline-after": "never-multi-line",
  105. "value-list-comma-newline-before": "always-multi-line",
  106. "value-list-comma-space-after": "always-single-line",
  107. "value-list-comma-space-before": "always-single-line"
  108. }
  109. ```
  110. ### Example E
  111. Say you want to disable single-line blocks:
  112. <!-- prettier-ignore -->
  113. ```css
  114. a { color: red; }
  115. /** ↑
  116. * Declaration blocks like this */
  117. ```
  118. Use the `block-opening-brace-newline-after` and `block-opening-brace-newline-before` rules together. For example, this config:
  119. ```json
  120. {
  121. "block-opening-brace-newline-after": ["always"],
  122. "block-closing-brace-newline-before": ["always"]
  123. }
  124. ```
  125. Would allow:
  126. <!-- prettier-ignore -->
  127. ```css
  128. a {
  129. color: red;
  130. }
  131. ```
  132. But not these patterns:
  133. <!-- prettier-ignore -->
  134. ```css
  135. a { color: red;
  136. }
  137. a {
  138. color: red; }
  139. a { color: red; }
  140. ```
  141. To allow single-line blocks but enforce newlines with multi-line blocks, use the `"always-multi-line"` option for both rules.
  142. ## `*-empty-line-before` and `*-max-empty-lines` rules
  143. These rules work together to control where empty lines are allowed.
  144. Each _thing_ is responsible for pushing itself away from the _preceding thing_, rather than pushing the _subsequent thing_ away. This consistency is to avoid conflicts and is why there aren't any `*-empty-line-after` rules in stylelint.
  145. Say you want to enforce the following:
  146. <!-- prettier-ignore -->
  147. ```css
  148. a {
  149. background: green;
  150. color: red;
  151. @media (min-width: 30em) {
  152. color: blue;
  153. }
  154. }
  155. b {
  156. --custom-property: green;
  157. background: pink;
  158. color: red;
  159. }
  160. ```
  161. You can do that with:
  162. ```json
  163. {
  164. "at-rule-empty-line-before": [
  165. "always",
  166. {
  167. "except": ["first-nested"]
  168. }
  169. ],
  170. "custom-property-empty-line-before": [
  171. "always",
  172. {
  173. "except": ["after-custom-property", "first-nested"]
  174. }
  175. ],
  176. "declaration-empty-line-before": [
  177. "always",
  178. {
  179. "except": ["after-declaration", "first-nested"]
  180. }
  181. ],
  182. "block-closing-brace-empty-line-before": "never",
  183. "rule-empty-line-before": ["always-multi-line"]
  184. }
  185. ```
  186. We recommend that you set your primary option (e.g. `"always"` or `"never"`) to whatever is your most common occurrence and define your exceptions with the `except` optional secondary options. There are many values for the `except` option e.g. `first-nested`, `after-comment` etc.
  187. The `*-empty-line-before` rules control whether there must never be an empty line or whether there must be _one or more_ empty lines before a _thing_. The `*-max-empty-lines` rules complement this by controlling _the number_ of empty lines within _things_. The `max-empty-lines` rule sets a limit across the entire source. A _stricter_ limit can then be set within _things_ using the likes of `function-max-empty-lines`, `selector-max-empty-lines` and `value-list-max-empty-lines`.
  188. For example, say you want to enforce the following:
  189. <!-- prettier-ignore -->
  190. ```css
  191. a,
  192. b {
  193. box-shadow:
  194. inset 0 2px 0 #dcffa6,
  195. 0 2px 5px #000;
  196. }
  197. c {
  198. transform:
  199. translate(
  200. 1,
  201. 1
  202. );
  203. }
  204. ```
  205. i.e. a maximum of 1 empty line within the whole source, but no empty lines within functions, selector lists and value lists.
  206. You can do that with:
  207. ```json
  208. {
  209. "function-max-empty-lines": 0,
  210. "max-empty-lines": 1,
  211. "selector-list-max-empty-lines": 0,
  212. "value-list-max-empty-lines": 0
  213. }
  214. ```
  215. ## `*-allowed-list`, `*-disallowed-list`, `color-named` and applicable `*-no-*` rules
  216. These rules work together to (dis)allow language features and constructs.
  217. There are `*-allowed-list` and `*-disallowed-list` rules that target the constructs of the CSS language: at-rules, functions, declarations (i.e. property-value pairs), properties and units. These rules (dis)allow any language features that make use of these constructs (e.g. `@media`, `rgb()`). However, there are features not caught by these `*-allowed-list` and `*-disallowed-list` rules (or are, but would require complex regex to configure). There are individual rules, usually a `*-no-*` rule (e.g. `color-no-hex` and `selector-no-id`), to disallow each of these features.
  218. Say you want to disallow the `@debug` language extension. You can do that using either the `at-rule-disallowed-list` or `at-rule-allowed-list` rules because the `@debug` language extension uses the at-rule construct e.g.
  219. ```json
  220. {
  221. "at-rule-disallowed-list": ["debug"]
  222. }
  223. ```
  224. Say you want to, for whatever reason, disallow the whole at-rule construct. You can do that using:
  225. ```json
  226. {
  227. "at-rule-allowed-list": []
  228. }
  229. ```
  230. Say you want to disallow the value `none` for the `border` properties. You can do that using either the `declaration-property-value-disallowed-list` or `declaration-property-value-allowed-list` e.g.
  231. ```json
  232. {
  233. "declaration-property-value-disallowed-list": [
  234. {
  235. "/^border/": ["none"]
  236. }
  237. ]
  238. }
  239. ```
  240. ## `color-*` and `function-*` rules
  241. Most `<color>` values are _functions_. As such, they can be (dis)allowed using either the `function-allowed-list` or `function-disallowed-list` rules. Two other color representations aren't functions: named colors and hex colors. There are two specific rules that (dis)allow these: `color-named` and `color-no-hex`, respectively.
  242. Say you want to enforce using a named color _if one exists for your chosen color_ and use `hwb` color if one does not, e.g.:
  243. <!-- prettier-ignore -->
  244. ```css
  245. a {
  246. background: hwb(235, 0%, 0%); /* there is no named color equivalent for this color */
  247. color: black;
  248. }
  249. ```
  250. If you're taking an allow approach, you can do that with:
  251. ```json
  252. {
  253. "color-named": "always-where-possible",
  254. "color-no-hex": true,
  255. "function-allowed-list": ["hwb"]
  256. }
  257. ```
  258. Or, if you're taking a disallow approach:
  259. ```json
  260. {
  261. "color-named": "always-where-possible",
  262. "color-no-hex": true,
  263. "function-disallowed-list": ["/^rgb/", "/^hsl/", "gray"]
  264. }
  265. ```
  266. This approach scales to when language extensions (that use the two built-in extendable syntactic constructs of at-rules and functions) are used. For example, say you want to disallow all standard color presentations in favour of using a custom color representation function, e.g. `my-color(red with a dash of green / 5%)`. You can do that with:
  267. ```json
  268. {
  269. "color-named": "never",
  270. "color-no-hex": true,
  271. "function-allowed-list": ["my-color"]
  272. }
  273. ```
  274. ## Manage conflicts
  275. Each rule stands alone, so sometimes it's possible to configure rules such that they conflict with one another. For example, you could turn on two conflicting allow and disallow list rules, e.g. `unit-allowed-list` and `unit-disallowed-list`.
  276. It's your responsibility as the configuration author to resolve these conflicts.