-
-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…1968) * Add `vue/prefer-type-props-decl` rule * Add rule * chore: Related Rules * Update lib/rules/prefer-type-emits-decl.js Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com> * Update lib/rules/prefer-type-props-decl.js Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com> * fix: remove ts eslint-code-block & improve related rules link * Update lib/rules/prefer-type-emits-decl.js Co-authored-by: Flo Edelmann <florian-edelmann@online.de> * Update tests/lib/rules/prefer-type-emits-decl.js Co-authored-by: Flo Edelmann <florian-edelmann@online.de> * chore: rename rule name * feat: implement renamed rules * update rule docs * Add eslint-code-block * fix lint issues * Update docs/rules/define-emits-declaration.md Co-authored-by: Flo Edelmann <florian-edelmann@online.de> * Update docs/rules/define-props-declaration.md Co-authored-by: Flo Edelmann <florian-edelmann@online.de> * Update docs/rules/define-emits-declaration.md Co-authored-by: Flo Edelmann <florian-edelmann@online.de> * Update docs/rules/define-props-declaration.md Co-authored-by: Flo Edelmann <florian-edelmann@online.de> * add runtime option example * Fix order in docs Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com> Co-authored-by: Flo Edelmann <florian-edelmann@online.de>
- Loading branch information
1 parent
bf9b95c
commit 4383a86
Showing
10 changed files
with
663 additions
and
48 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,78 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/define-emits-declaration | ||
description: enforce declaration style of `defineEmits` | ||
--- | ||
# vue/define-emits-declaration | ||
|
||
> enforce declaration style of `defineEmits` | ||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
|
||
## :book: Rule Details | ||
|
||
This rule enforces `defineEmits` typing style which you should use `type-based` or `runtime` declaration. | ||
|
||
This rule only works in setup script and `lang="ts"`. | ||
|
||
<eslint-code-block :rules="{'vue/define-emits-declaration': ['error']}"> | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
/* ✓ GOOD */ | ||
const emit = defineEmits<{ | ||
(e: 'change', id: number): void | ||
(e: 'update', value: string): void | ||
}>() | ||
/* ✗ BAD */ | ||
const emit = defineEmits(['change', 'update']) | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :wrench: Options | ||
|
||
```json | ||
"vue/define-emits-declaration": ["error", "type-based" | "runtime"] | ||
``` | ||
|
||
- `type-based` (default) enforces type-based declaration | ||
- `runtime` enforces runtime declaration | ||
|
||
### `runtime` | ||
|
||
<eslint-code-block :rules="{'vue/define-emits-declaration': ['error', 'runtime']}"> | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
/* ✗ BAD */ | ||
const emit = defineEmits<{ | ||
(e: 'change', id: number): void | ||
(e: 'update', value: string): void | ||
}>() | ||
/* ✓ GOOD */ | ||
const emit = defineEmits(['change', 'update']) | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :couple: Related Rules | ||
|
||
- [vue/define-props-declaration](./define-props-declaration.md) | ||
- [vue/valid-define-emits](./valid-define-emits.md) | ||
|
||
## :books: Further Reading | ||
|
||
- [`defineEmits`](https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits) | ||
- [Typescript-only-features of `defineEmits`](https://vuejs.org/api/sfc-script-setup.html#typescript-only-features) | ||
- [Guide - Typing-component-emits](https://vuejs.org/guide/typescript/composition-api.html#typing-component-emits) | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/define-emits-declaration.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/define-emits-declaration.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/define-props-declaration | ||
description: enforce declaration style of `defineProps` | ||
--- | ||
# vue/define-props-declaration | ||
|
||
> enforce declaration style of `defineProps` | ||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
|
||
## :book: Rule Details | ||
|
||
This rule enforces `defineProps` typing style which you should use `type-based` or `runtime` declaration. | ||
|
||
This rule only works in setup script and `lang="ts"`. | ||
|
||
<eslint-code-block :rules="{'vue/define-props-declaration': ['error']}"> | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
/* ✓ GOOD */ | ||
const props = defineProps<{ | ||
kind: string | ||
}>() | ||
/* ✗ BAD */ | ||
const props = defineProps({ | ||
kind: { type: String } | ||
}) | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :wrench: Options | ||
|
||
```json | ||
"vue/define-props-declaration": ["error", "type-based" | "runtime"] | ||
``` | ||
|
||
- `type-based` (default) enforces type-based declaration | ||
- `runtime` enforces runtime declaration | ||
|
||
### `"runtime"` | ||
|
||
<eslint-code-block :rules="{'vue/define-emits-declaration': ['error', 'runtime']}"> | ||
|
||
```vue | ||
<script setup lang="ts"> | ||
/* ✗ BAD */ | ||
const emit = defineEmits<{ | ||
(e: 'change', id: number): void | ||
(e: 'update', value: string): void | ||
}>() | ||
/* ✓ GOOD */ | ||
const emit = defineEmits(['change', 'update']) | ||
</script> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :couple: Related Rules | ||
|
||
- [vue/define-emits-declaration](./define-emits-declaration.md) | ||
- [vue/valid-define-props](./valid-define-props.md) | ||
|
||
## :books: Further Reading | ||
|
||
- [`defineProps`](https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits) | ||
- [Typescript-only-features of `defineProps`](https://vuejs.org/api/sfc-script-setup.html#typescript-only-features) | ||
- [Guide - Typing-component-props](https://vuejs.org/guide/typescript/composition-api.html#typing-component-props) | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/define-props-declaration.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/define-props-declaration.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
Oops, something went wrong.