|
| 1 | +--- |
| 2 | +pageClass: rule-details |
| 3 | +sidebarDepth: 0 |
| 4 | +title: vue/block-tag-newline |
| 5 | +description: enforce line breaks after opening and before closing block-level tags |
| 6 | +--- |
| 7 | +# vue/block-tag-newline |
| 8 | +> enforce line breaks after opening and before closing block-level tags |
| 9 | +
|
| 10 | +- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. |
| 11 | + |
| 12 | +## :book: Rule Details |
| 13 | + |
| 14 | +This rule enforces a line break (or no line break) after opening and before closing block tags. |
| 15 | + |
| 16 | +<eslint-code-block fix :rules="{'vue/block-tag-newline': ['error']}"> |
| 17 | + |
| 18 | +```vue |
| 19 | +<!-- ✓ GOOD --> |
| 20 | +<template><input></template> |
| 21 | +
|
| 22 | +<script> |
| 23 | +export default {} |
| 24 | +</script> |
| 25 | +``` |
| 26 | + |
| 27 | +</eslint-code-block> |
| 28 | + |
| 29 | +<eslint-code-block fix :rules="{'vue/block-tag-newline': ['error']}"> |
| 30 | + |
| 31 | +```vue |
| 32 | +<!-- ✗ BAD --> |
| 33 | +<template> |
| 34 | +<input></template> |
| 35 | +
|
| 36 | +<script> |
| 37 | +export default {}</script> |
| 38 | +``` |
| 39 | + |
| 40 | +</eslint-code-block> |
| 41 | + |
| 42 | +## :wrench: Options |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "vue/block-tag-newline": ["error", { |
| 47 | + "singleline": "always" | "never" | "consistent" | "ignore", |
| 48 | + "multiline": "always" | "never" | "consistent" | "ignore", |
| 49 | + "maxEmptyLines": 0, |
| 50 | + "blocks": { |
| 51 | + "template": { |
| 52 | + "singleline": "always" | "never" | "consistent" | "ignore", |
| 53 | + "multiline": "always" | "never" | "consistent" | "ignore", |
| 54 | + "maxEmptyLines": 0, |
| 55 | + }, |
| 56 | + "script": { |
| 57 | + "singleline": "always" | "never" | "consistent" | "ignore", |
| 58 | + "multiline": "always" | "never" | "consistent" | "ignore", |
| 59 | + "maxEmptyLines": 0, |
| 60 | + }, |
| 61 | + "my-block": { |
| 62 | + "singleline": "always" | "never" | "consistent" | "ignore", |
| 63 | + "multiline": "always" | "never" | "consistent" | "ignore", |
| 64 | + "maxEmptyLines": 0, |
| 65 | + } |
| 66 | + } |
| 67 | + }] |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +- `singleline` ... the configuration for single-line blocks. |
| 72 | + - `"consistent"` ... (default) requires consistent usage of line breaks for each pair of tags. It reports an error if one tag in the pair has a linebreak inside it and the other tag does not. |
| 73 | + - `"always"` ... require one line break after opening and before closing block tags. |
| 74 | + - `"never"` ... disallow line breaks after opening and before closing block tags. |
| 75 | +- `multiline` ... the configuration for multi-line blocks. |
| 76 | + - `"consistent"` ... requires consistent usage of line breaks for each pair of tags. It reports an error if one tag in the pair has a linebreak inside it and the other tag does not. |
| 77 | + - `"always"` ... (default) require one line break after opening and before closing block tags. |
| 78 | + - `"never"` ... disallow line breaks after opening and before closing block tags. |
| 79 | +- `maxEmptyLines` ... specifies the maximum number of empty lines allowed. default 0. |
| 80 | +- `blocks` ... specifies for each block name. |
| 81 | + |
| 82 | +### `{ "singleline": "never", "multiline": "always" }` |
| 83 | + |
| 84 | +<eslint-code-block fix :rules="{'vue/block-tag-newline': ['error', { 'singleline': 'never', 'multiline': 'always' }]}"> |
| 85 | + |
| 86 | +```vue |
| 87 | +<!-- ✓ GOOD --> |
| 88 | +<template><input></template> |
| 89 | +
|
| 90 | +<script> |
| 91 | +export default { |
| 92 | +} |
| 93 | +</script> |
| 94 | +``` |
| 95 | + |
| 96 | +</eslint-code-block> |
| 97 | + |
| 98 | +<eslint-code-block fix :rules="{'vue/block-tag-newline': ['error', { 'singleline': 'never', 'multiline': 'always' }]}"> |
| 99 | + |
| 100 | +```vue |
| 101 | +<!-- ✗ BAD --> |
| 102 | +<template> |
| 103 | +<input> |
| 104 | +</template> |
| 105 | +
|
| 106 | +<script>export default { |
| 107 | +}</script> |
| 108 | +``` |
| 109 | + |
| 110 | +</eslint-code-block> |
| 111 | + |
| 112 | +### `{ "singleline": "always", "multiline": "always", "maxEmptyLines": 1 }` |
| 113 | + |
| 114 | +<eslint-code-block fix :rules="{'vue/block-tag-newline': ['error', { 'singleline': 'always', 'multiline': 'always', 'maxEmptyLines': 1 }]}"> |
| 115 | + |
| 116 | +```vue |
| 117 | +<!-- ✓ GOOD --> |
| 118 | +<template> |
| 119 | +
|
| 120 | +<input> |
| 121 | +
|
| 122 | +</template> |
| 123 | +
|
| 124 | +<script> |
| 125 | +
|
| 126 | +export default { |
| 127 | +} |
| 128 | +
|
| 129 | +</script> |
| 130 | +``` |
| 131 | + |
| 132 | +</eslint-code-block> |
| 133 | + |
| 134 | +<eslint-code-block fix :rules="{'vue/block-tag-newline': ['error', { 'singleline': 'always', 'multiline': 'always', 'maxEmptyLines': 1 }]}"> |
| 135 | + |
| 136 | +```vue |
| 137 | +<!-- ✗ BAD --> |
| 138 | +<template> |
| 139 | +
|
| 140 | +
|
| 141 | +<input> |
| 142 | +
|
| 143 | +
|
| 144 | +</template> |
| 145 | +
|
| 146 | +<script> |
| 147 | +
|
| 148 | +
|
| 149 | +export default { |
| 150 | +} |
| 151 | +
|
| 152 | +
|
| 153 | +</script> |
| 154 | +``` |
| 155 | + |
| 156 | +</eslint-code-block> |
| 157 | + |
| 158 | +## :mag: Implementation |
| 159 | + |
| 160 | +- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/block-tag-newline.js) |
| 161 | +- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/block-tag-newline.js) |
0 commit comments