|
| 1 | +--- |
| 2 | +pageClass: rule-details |
| 3 | +sidebarDepth: 0 |
| 4 | +title: vue/padding-lines-in-component-definition |
| 5 | +description: require or disallow padding lines in component definition |
| 6 | +--- |
| 7 | +# vue/padding-lines-in-component-definition |
| 8 | + |
| 9 | +> require or disallow padding lines in component definition |
| 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 | +- :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. |
| 13 | + |
| 14 | +## :book: Rule Details |
| 15 | + |
| 16 | +This rule requires or disallows blank lines in the component definition. Properly blank lines help developers improve code readability and code style flexibility. |
| 17 | + |
| 18 | +<eslint-code-block fix :rules="{'vue/padding-lines-in-component-definition': ['error']}"> |
| 19 | + |
| 20 | +```vue |
| 21 | +<script> |
| 22 | +/* ✗ BAD */ |
| 23 | +export default { |
| 24 | + props: { |
| 25 | + modelValue: { |
| 26 | + type: String, |
| 27 | + default: '', |
| 28 | + }, |
| 29 | + }, |
| 30 | + data() { |
| 31 | + return { |
| 32 | + count: 0, |
| 33 | + }; |
| 34 | + } |
| 35 | +} |
| 36 | +</script> |
| 37 | +``` |
| 38 | + |
| 39 | +</eslint-code-block> |
| 40 | + |
| 41 | +<eslint-code-block fix :rules="{'vue/padding-lines-in-component-definition': ['error']}"> |
| 42 | + |
| 43 | +```vue |
| 44 | +<script> |
| 45 | +/* ✓ GOOD */ |
| 46 | +export default { |
| 47 | + props: { |
| 48 | + modelValue: { |
| 49 | + type: String, |
| 50 | + default: '', |
| 51 | + }, |
| 52 | + }, |
| 53 | +
|
| 54 | + data() { |
| 55 | + return { |
| 56 | + count: 0, |
| 57 | + }; |
| 58 | + } |
| 59 | +} |
| 60 | +</script> |
| 61 | +``` |
| 62 | + |
| 63 | +</eslint-code-block> |
| 64 | + |
| 65 | +## :wrench: Options |
| 66 | + |
| 67 | +```json |
| 68 | +{ |
| 69 | + "vue/padding-lines-in-component-definition": ["error", { |
| 70 | + "betweenOptions": "always" | "never", |
| 71 | + |
| 72 | + "withinOption": { |
| 73 | + "props": { |
| 74 | + "betweenItems": "always" | "never" | "ignore", |
| 75 | + "withinEach": "always" | "never" | "ignore", |
| 76 | + } | "always" | "never" | "ignore", // shortcut to set both |
| 77 | + |
| 78 | + "data": { |
| 79 | + "betweenItems": "always" | "never" | "ignore", |
| 80 | + "withinEach": "always" | "never" | "ignore", |
| 81 | + } | "always" | "never" | "ignore" // shortcut to set both |
| 82 | + |
| 83 | + // ... all options |
| 84 | + } | "always" | "never" | "ignore", |
| 85 | + |
| 86 | + "groupSingleLineProperties": true | false |
| 87 | + }] |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +- `betweenOptions` ... Setting padding lines between options. default `always` |
| 92 | +- `withinOption` ... Setting padding lines within option |
| 93 | + - `emits` ... Setting padding between lines between `emits` and `defineEmits`. default `always` |
| 94 | + - `props` ... Setting padding between lines between `props` and `defineProps`. default `always` |
| 95 | + - ... |
| 96 | +- `groupSingleLineProperties` ... Setting groupings of multiple consecutive single-line properties (e.g. `name`, `inheritAttrs`), default `true` |
| 97 | + |
| 98 | +### Group single-line properties |
| 99 | + |
| 100 | +<eslint-code-block fix :rules="{'vue/padding-lines-in-component-definition': ['error', { betweenOptions: 'always', withinOption: 'always', groupSingleLineProperties: true}]}"> |
| 101 | + |
| 102 | +```vue |
| 103 | +<script> |
| 104 | +export default { |
| 105 | + name: 'GroupSingleLineProperties', |
| 106 | + inheritAttrs: false, |
| 107 | + |
| 108 | + props: { |
| 109 | + modelValue: { |
| 110 | + type: String, |
| 111 | + default: '', |
| 112 | + }, |
| 113 | + }, |
| 114 | + |
| 115 | + data() { |
| 116 | + return { |
| 117 | + count: 0, |
| 118 | + }; |
| 119 | + } |
| 120 | +} |
| 121 | +</script> |
| 122 | +``` |
| 123 | + |
| 124 | +</eslint-code-block> |
| 125 | + |
| 126 | +### With custom options |
| 127 | + |
| 128 | +<eslint-code-block fix :rules="{'vue/padding-lines-in-component-definition': ['error', { betweenOptions: 'always', withinOption: { props: { betweenItems: 'always', withinEach: 'never' }, customOption: { betweenItems: 'always', withinEach: 'ignore' } }, groupSingleLineProperties: true}]}"> |
| 129 | + |
| 130 | +```vue |
| 131 | +<script> |
| 132 | +export default { |
| 133 | + props: { |
| 134 | + modelValue: { |
| 135 | + type: String, |
| 136 | + default: '', |
| 137 | + }, |
| 138 | + |
| 139 | + isActive: { |
| 140 | + type: Boolean, |
| 141 | + default: false, |
| 142 | + }, |
| 143 | + }, |
| 144 | + |
| 145 | + customOption: { |
| 146 | + foo: () => { |
| 147 | + return 'foo' |
| 148 | + }, |
| 149 | + |
| 150 | + bar: () => { |
| 151 | + return 'bar' |
| 152 | + } |
| 153 | + }, |
| 154 | +} |
| 155 | +</script> |
| 156 | +``` |
| 157 | + |
| 158 | +</eslint-code-block> |
| 159 | + |
| 160 | +## :mag: Implementation |
| 161 | + |
| 162 | +- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/padding-lines-in-component-definition.js) |
| 163 | +- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/padding-lines-in-component-definition.js) |
0 commit comments