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.

configure.md 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. # Configuration
  2. stylelint _expects a configuration object_.
  3. stylelint uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) to find and load your configuration object. Starting from the current working directory, it looks for the following possible sources:
  4. - a `stylelint` property in `package.json`
  5. - a `.stylelintrc` file
  6. - a `stylelint.config.js` file exporting a JS object
  7. - a `stylelint.config.cjs` file exporting a JS object. When running stylelint in JavaScript packages that specify `"type":"module"` in their `package.json`
  8. The search stops when one of these is found, and stylelint uses that object. You can use the [`--config` or `configFile` option](usage/options.md#configfile) to short-circuit the search.
  9. The `.stylelintrc` file (without extension) can be in JSON or YAML format. You can add a filename extension to help your text editor provide syntax checking and highlighting:
  10. - `.stylelintrc.json`
  11. - `.stylelintrc.yaml` / `.stylelintrc.yml`
  12. - `.stylelintrc.js`
  13. The configuration object has the following properties:
  14. ## `rules`
  15. Rules determine what the linter looks for and complains about. There are [over 170 rules](rules/list.md) built into stylelint.
  16. _No rules are turned on by default and there are no default values. You must explicitly configure each rule to turn it on._
  17. The `rules` property is _an object whose keys are rule names and values are rule configurations_. For example:
  18. ```json
  19. {
  20. "rules": {
  21. "color-no-invalid-hex": true
  22. }
  23. }
  24. ```
  25. Each rule configuration fits one of the following formats:
  26. - `null` (to turn the rule off)
  27. - a single value (the primary option)
  28. - an array with two values (`[primary option, secondary options]`)
  29. Specifying a primary option turns on a rule.
  30. Many rules provide secondary options for further customization. To set secondary options, use a two-member array. For example:
  31. ```json
  32. {
  33. "rules": {
  34. "selector-pseudo-class-no-unknown": [
  35. true,
  36. {
  37. "ignorePseudoClasses": ["global"]
  38. }
  39. ]
  40. }
  41. }
  42. ```
  43. You can add any number of keys in the object. For example, you can:
  44. - turn off `block-no-empty`
  45. - turn on `comment-empty-line-before` with a primary and secondary option
  46. - turn on `max-empty-lines` and `unit-allowed-list` with primary options
  47. ```json
  48. {
  49. "rules": {
  50. "block-no-empty": null,
  51. "comment-empty-line-before": [
  52. "always",
  53. {
  54. "ignore": ["stylelint-commands", "after-comment"]
  55. }
  56. ],
  57. "max-empty-lines": 2,
  58. "unit-allowed-list": ["em", "rem", "%", "s"]
  59. }
  60. }
  61. ```
  62. ### `message`
  63. You can use the `message` secondary option to deliver a custom message when a rule is violated.
  64. For example, the following rule configuration would substitute in custom messages:
  65. ```json
  66. {
  67. "rules": {
  68. "color-hex-case": [
  69. "lower",
  70. {
  71. "message": "Lowercase letters are easier to distinguish from numbers"
  72. }
  73. ],
  74. "indentation": [
  75. 2,
  76. {
  77. "except": ["block"],
  78. "message": "Please use 2 spaces for indentation.",
  79. "severity": "warning"
  80. }
  81. ]
  82. }
  83. }
  84. ```
  85. Alternately, you can write a [custom formatter](../developer-guide/formatters.md) for maximum control if you need serious customization.
  86. ### `severity`
  87. You can use the `severity` secondary option to adjust any specific rule's severity.
  88. The available values for `severity` are:
  89. - `"warning"`
  90. - `"error"` (default)
  91. For example:
  92. ```json
  93. {
  94. "rules": {
  95. "indentation": [
  96. 2,
  97. {
  98. "except": ["value"],
  99. "severity": "warning"
  100. }
  101. ]
  102. }
  103. }
  104. ```
  105. Reporters may use these severity levels to display violations or exit the process differently.
  106. ### `reportDisables`
  107. You can set the `reportDisables` secondary option to report any `stylelint-disable` comments for this rule, effectively disallowing authors to opt out of it.
  108. For example:
  109. ```json
  110. {
  111. "rules": {
  112. "indentation": [
  113. 2,
  114. {
  115. "except": ["value"],
  116. "reportDisables": true
  117. }
  118. ]
  119. }
  120. }
  121. ```
  122. The report is considered to be a lint error.
  123. ## Disable Errors
  124. These configurations provide extra validation for `stylelint-disable` comments. This can be helpful for enforcing useful and well-documented disables.
  125. They are configured like rules. They can have one of three values:
  126. - `null` (to turn the configuration off)
  127. - `true` or `false` (the primary option)
  128. - an array with two values (`[primary option, secondary options]`)
  129. The following secondary options are available:
  130. - `"except"` takes an array of rule names for which the primary option should be inverted.
  131. - `"severity"` adjusts the level of error emitted for the rule, [as above](#severity).
  132. For example, this produces errors for needless disables of all rules except `selector-max-type`:
  133. ```json
  134. {
  135. "reportNeedlessDisables": [true, { "except": ["selector-max-type"] }]
  136. }
  137. ```
  138. And this emits warnings for disables of `color-hex-case` that don't have a description:
  139. ```json
  140. {
  141. "reportDescriptionlessDisables": [
  142. false,
  143. {
  144. "except": ["color-hex-case"],
  145. "severity": "warning"
  146. }
  147. ]
  148. }
  149. ```
  150. ### `reportNeedlessDisables`
  151. Emit errors for `stylelint-disable` comments that don't actually match any lints that need to be disabled.
  152. For example:
  153. ```json
  154. {
  155. "reportNeedlessDisables": true
  156. }
  157. ```
  158. ### `reportInvalidScopeDisables`
  159. Emit errors for `stylelint-disable` comments that don't match rules that are specified in the configuration object.
  160. For example:
  161. ```json
  162. {
  163. "reportInvalidScopeDisables": true
  164. }
  165. ```
  166. ### `reportDescriptionlessDisables`
  167. Emit errors for `stylelint-disable` comments without a description.
  168. For example, when the configuration `{ block-no-empty: true }` is given, the following patterns are reported:
  169. <!-- prettier-ignore -->
  170. ```css
  171. /* stylelint-disable */
  172. a {}
  173. ```
  174. <!-- prettier-ignore -->
  175. ```css
  176. /* stylelint-disable-next-line block-no-empty */
  177. a {}
  178. ```
  179. But, the following patterns (`stylelint-disable -- <description>`) are _not_ reported:
  180. <!-- prettier-ignore -->
  181. ```css
  182. /* stylelint-disable -- This violation is ignorable. */
  183. a {}
  184. ```
  185. <!-- prettier-ignore -->
  186. ```css
  187. /* stylelint-disable-next-line block-no-empty -- This violation is ignorable. */
  188. a {}
  189. ```
  190. For example:
  191. ```json
  192. {
  193. "reportDescriptionlessDisables": true
  194. }
  195. ```
  196. ## `defaultSeverity`
  197. You can set the default severity level for all rules that do not have a severity specified in their secondary options. For example, you can set the default severity to `"warning"`:
  198. ```json
  199. {
  200. "defaultSeverity": "warning"
  201. }
  202. ```
  203. ## `ignoreDisables`
  204. Ignore `stylelint-disable` (e.g. `/* stylelint-disable block-no-empty */`) comments.
  205. For example:
  206. ```json
  207. {
  208. "ignoreDisables": true
  209. }
  210. ```
  211. ## `extends`
  212. You can _extend_ an existing configuration (whether your own or a third-party one).
  213. Popular configurations include:
  214. - [`stylelint-config-recommended`](https://github.com/stylelint/stylelint-config-recommended) - turns on just [possible error rules](rules/list.md#possible-errors)
  215. - [`stylelint-config-standard`](https://github.com/stylelint/stylelint-config-standard) - extends recommended one by turning on 60 [stylistic rules](rules/list.md#stylistic-issues)
  216. You'll find more in [awesome stylelint](https://github.com/stylelint/awesome-stylelint#configs).
  217. When one configuration extends another, it starts with the other's properties then adds to and overrides what's there.
  218. For example, you can extend the [`stylelint-config-standard`](https://github.com/stylelint/stylelint-config-standard) and then change the indentation to tabs and turn off the `number-leading-zero` rule:
  219. ```json
  220. {
  221. "extends": "stylelint-config-standard",
  222. "rules": {
  223. "indentation": "tab",
  224. "number-leading-zero": null
  225. }
  226. }
  227. ```
  228. You can extend an array of existing configurations, with each item in the array taking precedence over the previous item (so the second item overrides rules in the first, the third item overrides rules in the first and the second, and so on, the last item overrides everything else).
  229. For example, with `stylelint-config-standard`, then layer `myExtendableConfig` on top of that, and then override the indentation rule:
  230. ```json
  231. {
  232. "extends": ["stylelint-config-standard", "./myExtendableConfig"],
  233. "rules": {
  234. "indentation": "tab"
  235. }
  236. }
  237. ```
  238. The value of `"extends"` is a "locater" (or an array of "locaters") that is ultimately `require()`d. It can fit whatever format works with Node's `require.resolve()` algorithm. That means a "locater" can be:
  239. - the name of a module in `node_modules` (e.g. `stylelint-config-standard`; that module's `main` file must be a valid JSON configuration)
  240. - an absolute path to a file (which makes sense if you're creating a JS object in a Node.js context and passing it in) with a `.js` or `.json` extension.
  241. - a relative path to a file with a `.js` or `.json` extension, relative to the referencing configuration (e.g. if configA has `extends: "../configB"`, we'll look for `configB` relative to configA).
  242. ## `plugins`
  243. Plugins are rules or sets of rules built by the community that support methodologies, toolsets, _non-standard_ CSS features, or very specific use cases.
  244. Popular plugin packs include:
  245. - [`stylelint-order`](https://github.com/hudochenkov/stylelint-order) - specify the ordering of things, e.g. properties within declaration blocks
  246. - [`stylelint-scss`](https://github.com/kristerkari/stylelint-scss) - enforce a wide variety of linting rules for SCSS-like syntax
  247. You'll find more in [awesome stylelint](https://github.com/stylelint/awesome-stylelint#plugins).
  248. To use one, add a `"plugins"` array to your config, containing "locaters" identifying the plugins you want to use. As with `extends`, above, a "locater" can be either a:
  249. - npm module name
  250. - absolute path
  251. - path relative to the invoking configuration file
  252. Once the plugin is declared, within your `"rules"` object _you'll need to add options_ for the plugin's rule(s), just like any standard rule. Look at the plugin's documentation to know what the rule name should be.
  253. ```json
  254. {
  255. "plugins": ["../special-rule.js"],
  256. "rules": {
  257. "plugin-namespace/special-rule": "everything"
  258. }
  259. }
  260. ```
  261. A "plugin" can provide a single rule or a set of rules. If the plugin you use provides a set, invoke the module in your `"plugins"` configuration value, and use the rules it provides in `"rules"`. For example:
  262. ```json
  263. {
  264. "plugins": ["../some-rule-set.js"],
  265. "rules": {
  266. "some-rule-set/first-rule": "everything",
  267. "some-rule-set/second-rule": "nothing",
  268. "some-rule-set/third-rule": "everything"
  269. }
  270. }
  271. ```
  272. ## `processors`
  273. Processors are functions built by the community that hook into stylelint's pipeline, modifying code on its way into stylelint and modifying results on their way out.
  274. **We discourage their use in favor of using the built-in [syntaxes](../about/syntaxes.md) as processors are incompatible with the [autofix feature](usage/options.md#fix).**
  275. To use one, add a `"processors"` array to your config, containing "locaters" identifying the processors you want to use. As with `extends`, above, a "locater" can be either an npm module name, an absolute path, or a path relative to the invoking configuration file.
  276. ```json
  277. {
  278. "processors": ["stylelint-my-processor"],
  279. "rules": {}
  280. }
  281. ```
  282. If your processor has options, make that item an array whose first item is the "locator" and second item is the options object.
  283. ```json
  284. {
  285. "processors": [
  286. "stylelint-my-processor",
  287. ["some-other-processor", { "optionOne": true, "optionTwo": false }]
  288. ],
  289. "rules": {}
  290. }
  291. ```
  292. Processors can also only be used with the CLI and the Node.js API, not with the PostCSS plugin. (The PostCSS plugin ignores them.)
  293. ## `ignoreFiles`
  294. You can provide a glob or array of globs to ignore specific files.
  295. For example, you can ignore all JavaScript files:
  296. ```json
  297. {
  298. "ignoreFiles": ["**/*.js"]
  299. }
  300. ```
  301. stylelint ignores the `node_modules` directory by default. However, this is overridden if `ignoreFiles` is set.
  302. If the globs are absolute paths, they are used as is. If they are relative, they are analyzed relative to
  303. - `configBasedir`, if it's provided;
  304. - the config's filepath, if the config is a file that stylelint found a loaded;
  305. - or `process.cwd()`.
  306. The `ignoreFiles` property is stripped from extended configs: only the root-level config can ignore files.
  307. _Note that this is not an efficient method for ignoring lots of files._ If you want to ignore a lot of files efficiently, use [`.stylelintignore`](ignore-code.md) or adjust your files globs.