-
-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
padding-lines-in-component-definition
rule (#2052)
- Loading branch information
Showing
6 changed files
with
1,765 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/padding-lines-in-component-definition | ||
description: require or disallow padding lines in component definition | ||
--- | ||
# vue/padding-lines-in-component-definition | ||
|
||
> require or disallow padding lines in component definition | ||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
- :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. | ||
|
||
## :book: Rule Details | ||
|
||
This rule requires or disallows blank lines in the component definition. Properly blank lines help developers improve code readability and code style flexibility. | ||
|
||
<eslint-code-block fix :rules="{'vue/padding-lines-in-component-definition': ['error']}"> | ||
|
||
```vue | ||
<script> | ||
/* ✗ BAD */ | ||
export default { | ||
props: { | ||
modelValue: { | ||
type: String, | ||
default: '', | ||
}, | ||
}, | ||
data() { | ||
return { | ||
count: 0, | ||
}; | ||
} | ||
} | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
<eslint-code-block fix :rules="{'vue/padding-lines-in-component-definition': ['error']}"> | ||
|
||
```vue | ||
<script> | ||
/* ✓ GOOD */ | ||
export default { | ||
props: { | ||
modelValue: { | ||
type: String, | ||
default: '', | ||
}, | ||
}, | ||
data() { | ||
return { | ||
count: 0, | ||
}; | ||
} | ||
} | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :wrench: Options | ||
|
||
```json | ||
{ | ||
"vue/padding-lines-in-component-definition": ["error", { | ||
"betweenOptions": "always" | "never", | ||
|
||
"withinOption": { | ||
"props": { | ||
"betweenItems": "always" | "never" | "ignore", | ||
"withinEach": "always" | "never" | "ignore", | ||
} | "always" | "never" | "ignore", // shortcut to set both | ||
|
||
"data": { | ||
"betweenItems": "always" | "never" | "ignore", | ||
"withinEach": "always" | "never" | "ignore", | ||
} | "always" | "never" | "ignore" // shortcut to set both | ||
|
||
// ... all options | ||
} | "always" | "never" | "ignore", | ||
|
||
"groupSingleLineProperties": true | false | ||
}] | ||
} | ||
``` | ||
|
||
- `betweenOptions` ... Setting padding lines between options. default `always` | ||
- `withinOption` ... Setting padding lines within option | ||
- `emits` ... Setting padding between lines between `emits` and `defineEmits`. default `always` | ||
- `props` ... Setting padding between lines between `props` and `defineProps`. default `always` | ||
- ... | ||
- `groupSingleLineProperties` ... Setting groupings of multiple consecutive single-line properties (e.g. `name`, `inheritAttrs`), default `true` | ||
|
||
### Group single-line properties | ||
|
||
<eslint-code-block fix :rules="{'vue/padding-lines-in-component-definition': ['error', { betweenOptions: 'always', withinOption: 'always', groupSingleLineProperties: true}]}"> | ||
|
||
```vue | ||
<script> | ||
export default { | ||
name: 'GroupSingleLineProperties', | ||
inheritAttrs: false, | ||
props: { | ||
modelValue: { | ||
type: String, | ||
default: '', | ||
}, | ||
}, | ||
data() { | ||
return { | ||
count: 0, | ||
}; | ||
} | ||
} | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
### With custom options | ||
|
||
<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}]}"> | ||
|
||
```vue | ||
<script> | ||
export default { | ||
props: { | ||
modelValue: { | ||
type: String, | ||
default: '', | ||
}, | ||
isActive: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
customOption: { | ||
foo: () => { | ||
return 'foo' | ||
}, | ||
bar: () => { | ||
return 'bar' | ||
} | ||
}, | ||
} | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/padding-lines-in-component-definition.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/padding-lines-in-component-definition.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.