|
| 1 | +--- |
| 2 | +pageClass: rule-details |
| 3 | +sidebarDepth: 0 |
| 4 | +title: vue/first-attribute-linebreak |
| 5 | +description: enforce the location of first attribute |
| 6 | +--- |
| 7 | +# vue/first-attribute-linebreak |
| 8 | + |
| 9 | +> enforce the location of first attribute |
| 10 | +
|
| 11 | +- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> |
| 12 | +- :gear: This rule is included in all of `"plugin:vue/vue3-strongly-recommended"`, `"plugin:vue/strongly-recommended"`, `"plugin:vue/vue3-recommended"` and `"plugin:vue/recommended"`. |
| 13 | +- :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. |
| 14 | + |
| 15 | +## :book: Rule Details |
| 16 | + |
| 17 | +This rule aims to enforce a consistent location for the first attribute. |
| 18 | + |
| 19 | +<eslint-code-block fix :rules="{'vue/first-attribute-linebreak': ['error']}"> |
| 20 | + |
| 21 | +```vue |
| 22 | +<template> |
| 23 | + <!-- ✓ GOOD --> |
| 24 | + <MyComponent lorem="1"/> |
| 25 | + <MyComponent lorem="1" ipsum="2"/> |
| 26 | + <MyComponent |
| 27 | + lorem="1" |
| 28 | + ipsum="2" |
| 29 | + /> |
| 30 | +
|
| 31 | + <!-- ✗ BAD --> |
| 32 | + <MyComponent lorem="1" |
| 33 | + ipsum="2"/> |
| 34 | +</template> |
| 35 | +``` |
| 36 | + |
| 37 | +</eslint-code-block> |
| 38 | + |
| 39 | +## :wrench: Options |
| 40 | + |
| 41 | +```json |
| 42 | +{ |
| 43 | + "vue/first-attribute-linebreak": ["error", { |
| 44 | + "singleline": "ignore", |
| 45 | + "multiline": "below" |
| 46 | + }] |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +- `singleline` ... The location of the first attribute when the attributes on single line. Default is `"ignore"`. |
| 51 | + - `"below"` ... Requires a newline before the first attribute. |
| 52 | + - `"beside"` ... Disallows a newline before the first attribute. |
| 53 | + - `"ignore"` ... Ignores attribute checking. |
| 54 | +- `multiline` ... The location of the first attribute when the attributes span multiple lines. Default is `"below"`. |
| 55 | + - `"below"` ... Requires a newline before the first attribute. |
| 56 | + - `"beside"` ... Disallows a newline before the first attribute. |
| 57 | + - `"ignore"` ... Ignores attribute checking. |
| 58 | + |
| 59 | +### `"singleline": "beside"` |
| 60 | + |
| 61 | +<eslint-code-block fix :rules="{'vue/first-attribute-linebreak': ['error', {singleline: 'beside'}]}"> |
| 62 | + |
| 63 | +```vue |
| 64 | +<template> |
| 65 | + <!-- ✓ GOOD --> |
| 66 | + <MyComponent lorem="1"/> |
| 67 | + <MyComponent lorem="1" ipsum="2"/> |
| 68 | +
|
| 69 | + <!-- ✗ BAD --> |
| 70 | + <MyComponent |
| 71 | + lorem="1"/> |
| 72 | + <MyComponent |
| 73 | + lorem="1" ipsum="2" |
| 74 | + /> |
| 75 | +</template> |
| 76 | +``` |
| 77 | + |
| 78 | +</eslint-code-block> |
| 79 | + |
| 80 | +### `"singleline": "below"` |
| 81 | + |
| 82 | +<eslint-code-block fix :rules="{'vue/first-attribute-linebreak': ['error', {singleline: 'below'}]}"> |
| 83 | + |
| 84 | +```vue |
| 85 | +<template> |
| 86 | + <!-- ✓ GOOD --> |
| 87 | + <MyComponent |
| 88 | + lorem="1"/> |
| 89 | + <MyComponent |
| 90 | + lorem="1" ipsum="2" |
| 91 | + /> |
| 92 | +
|
| 93 | + <!-- ✗ BAD --> |
| 94 | + <MyComponent lorem="1"/> |
| 95 | + <MyComponent lorem="1" ipsum="2"/> |
| 96 | +</template> |
| 97 | +``` |
| 98 | + |
| 99 | +</eslint-code-block> |
| 100 | + |
| 101 | +### `"multiline": "beside"` |
| 102 | + |
| 103 | +<eslint-code-block fix :rules="{'vue/first-attribute-linebreak': ['error', {multiline: 'beside'}]}"> |
| 104 | + |
| 105 | +```vue |
| 106 | +<template> |
| 107 | + <!-- ✓ GOOD --> |
| 108 | + <MyComponent lorem="1" |
| 109 | + ipsum="2"/> |
| 110 | + <MyComponent :lorem="{ |
| 111 | + a: 1 |
| 112 | + }"/> |
| 113 | +
|
| 114 | + <!-- ✗ BAD --> |
| 115 | + <MyComponent |
| 116 | + lorem="1" |
| 117 | + ipsum="2"/> |
| 118 | + <MyComponent |
| 119 | + :lorem="{ |
| 120 | + a: 1 |
| 121 | + }"/> |
| 122 | +</template> |
| 123 | +``` |
| 124 | + |
| 125 | +</eslint-code-block> |
| 126 | + |
| 127 | +### `"multiline": "below"` |
| 128 | + |
| 129 | +<eslint-code-block fix :rules="{'vue/first-attribute-linebreak': ['error', {multiline: 'below'}]}"> |
| 130 | + |
| 131 | +```vue |
| 132 | +<template> |
| 133 | + <!-- ✓ GOOD --> |
| 134 | + <MyComponent |
| 135 | + lorem="1" |
| 136 | + ipsum="2"/> |
| 137 | + <MyComponent |
| 138 | + :lorem="{ |
| 139 | + a: 1 |
| 140 | + }"/> |
| 141 | +
|
| 142 | + <!-- ✗ BAD --> |
| 143 | + <MyComponent lorem="1" |
| 144 | + ipsum="2"/> |
| 145 | + <MyComponent :lorem="{ |
| 146 | + a: 1 |
| 147 | + }"/> |
| 148 | +</template> |
| 149 | +``` |
| 150 | + |
| 151 | +</eslint-code-block> |
| 152 | + |
| 153 | +## :couple: Related Rules |
| 154 | + |
| 155 | +- [vue/max-attributes-per-line](./max-attributes-per-line.md) |
| 156 | + |
| 157 | +## :books: Further Reading |
| 158 | + |
| 159 | +- [Style guide - Multi attribute elements](https://v3.vuejs.org/style-guide/#multi-attribute-elements-strongly-recommended) |
| 160 | + |
| 161 | +## :mag: Implementation |
| 162 | + |
| 163 | +- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/first-attribute-linebreak.js) |
| 164 | +- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/first-attribute-linebreak.js) |
0 commit comments