-
-
Notifications
You must be signed in to change notification settings - Fork 679
Add type-based declaration rule of defineProps
and defineEmits
#1968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2506c80
Add `vue/prefer-type-props-decl` rule
Amorites 5fa4d5c
Add rule
Amorites dd6f19d
chore: Related Rules
Amorites a0614b6
Update lib/rules/prefer-type-emits-decl.js
Amorites 1aba686
Update lib/rules/prefer-type-props-decl.js
Amorites d5ff0b4
fix: remove ts eslint-code-block & improve related rules link
Amorites 6545e85
Update lib/rules/prefer-type-emits-decl.js
Amorites 9dd43d8
Update tests/lib/rules/prefer-type-emits-decl.js
Amorites 624396e
chore: rename rule name
Amorites ae2398c
feat: implement renamed rules
Amorites 4619113
update rule docs
Amorites 8b16330
Merge remote-tracking branch 'origin/master' into prefer-type-props-decl
Amorites a4030a5
Add eslint-code-block
Amorites 7ff9ded
fix lint issues
Amorites ee72388
Update docs/rules/define-emits-declaration.md
Amorites 36f9996
Update docs/rules/define-props-declaration.md
Amorites 763fb88
Update docs/rules/define-emits-declaration.md
Amorites aa16805
Update docs/rules/define-props-declaration.md
Amorites 0adae66
add runtime option example
Amorites 169ca72
Fix order in docs
FloEdelmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 | ||
|
||
- `type-based` (default) enforces type-based declaration | ||
- `runtime` enforces runtime declaration | ||
|
||
```json | ||
"vue/define-emits-declaration": ["error", "type-based" | "runtime"] | ||
``` | ||
|
||
### `runtime` | ||
FloEdelmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<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 hidden or 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 | ||
|
||
- `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> | ||
|
||
```json | ||
"vue/define-props-declaration": ["error", "type-based" | "runtime"] | ||
``` | ||
FloEdelmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## :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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.