|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- # indentation
-
- Specify indentation.
-
- <!-- prettier-ignore -->
- ```css
- |@media print {
- | a {
- | ↑ background-position: top left,
- | ↑ ↑ top right;
- | ↑}↑ ↑
- |}↑ ↑ ↑
- /** ↑ ↑ ↑
- * The indentation at these three points */
- ```
-
- The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule.
-
- ## Options
-
- `int|"tab"`, where `int` is the number of spaces
-
- ### `2`
-
- Always indent at-rules, rules, comments, declarations, inside parentheses and multi-line values by 2 spaces.
-
- The following patterns are considered violations:
-
- <!-- prettier-ignore -->
- ```css
- @media print {
- a {
- background-position: top left,
- top right;
- }
- }
- ```
-
- <!-- prettier-ignore -->
- ```css
- @media print {
- a {
- background-position: top left,
- top right;
- }
- }
- ```
-
- <!-- prettier-ignore -->
- ```css
- @media print {
- a {
- background-position: top left,
- top right;
- }
- }
- ```
-
- <!-- prettier-ignore -->
- ```css
- @media print {
- a,
- b {
- background-position: top left,
- top right;
- }
- }
- ```
-
- <!-- prettier-ignore -->
- ```css
- a {
- /* blergh */
- color: pink;
- }
- /* blergh */
- ```
-
- <!-- prettier-ignore -->
- ```css
- @media print,
- (-webkit-min-device-pixel-ratio: 1.25),
- (min-resolution: 120dpi) {}
- ```
-
- <!-- prettier-ignore -->
- ```css
- a {
- color: rgb(
- 255,
- 255,
- 255
- );
- top: 0;
- }
- ```
-
- The following patterns are _not_ considered violations:
-
- <!-- prettier-ignore -->
- ```css
- @media print {
- a {
- background-position: top left,
- top right;
- }
- }
- ```
-
- <!-- prettier-ignore -->
- ```css
- @media print {
- a,
- b {
- background-position: top left,
- top right;
- }
- }
- ```
-
- <!-- prettier-ignore -->
- ```css
- a {
- /* blergh */
- color: pink;
- }
- /* blergh */
- ```
-
- <!-- prettier-ignore -->
- ```css
- @media print,
- (-webkit-min-device-pixel-ratio: 1.25),
- (min-resolution: 120dpi) {}
- ```
-
- <!-- prettier-ignore -->
- ```css
- a {
- color: rgb(
- 255,
- 255,
- 255
- );
- top: 0;
- }
- ```
-
- ## Optional secondary options
-
- ### `baseIndentLevel: int|"auto"`
-
- By default, the indent level of the CSS code block in non-CSS-like files is determined by the shortest indent of non-empty line. The setting `baseIndentLevel` allows you to define a relative indent level based on CSS code block opening or closing line.
-
- For example, with `[ 2, { baseIndentLevel: 1 } ]`, CSS should be indented 1 levels higher than `<style>` tag:
-
- ```html
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <style>
- a {
- display: block;
- }
- </style>
- </head>
- </html>
- ```
-
- ### `indentInsideParens: "twice"|"once-at-root-twice-in-block"`
-
- By default, _one extra_ indentation (of your specified type) is expected after newlines inside parentheses, and the closing parenthesis is expected to have no extra indentation.
-
- If you would like to change the quantity of extra indentation inside parentheses, use this option.
-
- `"twice"` means you expect two extra indentations (of your specified type) after newlines inside parentheses, and expect the closing parenthesis to have one extra indentation. For example:
-
- <!-- prettier-ignore -->
- ```css
- a {
- color: rgb(
- 255,
- 255,
- 255
- );
- top: 0;
- }
- ```
-
- `"once-at-root-twice-in-block"` means two things: You want the behavior of `"once"`, as documented above, when the parenthetical expression is part of a node that is an immediate descendent of the root — i.e. not inside a block. And you want the behavior of `"twice"`, as documented above, when the parenthetical expression is part of a node that is inside a block. For example:
-
- <!-- prettier-ignore -->
- ```css
- @import (
- "foo.css"
- );
-
- a {
- color: rgb(
- 255,
- 255,
- 255
- );
- top: 0;
- }
- ```
-
- ### `indentClosingBrace: true|false`
-
- If `true`, the closing brace of a block (rule or at-rule) will be expected at the same indentation level as the block's inner nodes.
-
- For example, with `indentClosingBrace: true`.
-
- The following patterns are considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {
- color: pink;
- }
- ```
-
- <!-- prettier-ignore -->
- ```css
- @media print {
- a {
- color: pink;
- }
- }
- ```
-
- The following patterns are _not_ considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {
- color: pink;
- }
- ```
-
- <!-- prettier-ignore -->
- ```css
- @media print {
- a {
- color: pink;
- }
- }
- ```
-
- ### `except: ["block", "param", "value"]`
-
- Do _not_ indent for these things.
-
- For example, with `2`.
-
- The following patterns are considered violations:
-
- <!-- prettier-ignore -->
- ```css
- @media print,
- (-webkit-min-device-pixel-ratio: 1.25),
- (min-resolution: 120dpi) {
- a {
- background-position: top left,
- top right;
- }
- }
- ```
-
- The following patterns are _not_ considered violations:
-
- <!-- prettier-ignore -->
- ```css
- @media print,
- (-webkit-min-device-pixel-ratio: 1.25),
- (min-resolution: 120dpi) {
- a {
- background-position: top left,
- top right;
- }
- }
- ```
-
- ### `ignore: ["inside-parens", "param", "value"]`
-
- #### `"inside-parens"`
-
- Ignore the indentation inside parentheses.
-
- For example, with `2`.
-
- The following patterns are _not_ considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {
- color: rgb(
- 255,
- 255,
- 255
- );
- top: 0;
- }
- ```
-
- #### `"param"`
-
- Ignore the indentation of at-rule params.
-
- For example, with `2`.
-
- The following patterns are _not_ considered violations:
-
- <!-- prettier-ignore -->
- ```css
- @media print,
- (-webkit-min-device-pixel-ratio: 1.25),
- (min-resolution: 120dpi) {
- }
- ```
-
- #### `"value"`
-
- Ignore the indentation of values.
-
- For example, with `2`.
-
- The following patterns are _not_ considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {
- background-position: top left,
- top right,
- bottom left,
- bottom right;
- }
- ```
|