-
-
Notifications
You must be signed in to change notification settings - Fork 685
feat(no-shadow-native-events): initial implementation #2558
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
Open
JoCa96
wants to merge
34
commits into
vuejs:master
Choose a base branch
from
JoCa96:joca96/feat-no-shadow-native
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
7b640fe
initial version
JoCa96 8ad0f4b
added invalid tests
JoCa96 fe3615d
added valid tests cases
JoCa96 892f277
clean up
JoCa96 391a4bb
add docs
JoCa96 654332a
update related docs
JoCa96 300c138
add missing test fixture
JoCa96 c3e68ca
fix link
JoCa96 218a577
fix missing typedef for NameWithLoc
JoCa96 4e55123
lint issue: remove todo
JoCa96 ddfb904
fix lint issue: "space inside link text"
JoCa96 81ddf6a
remove unused options
JoCa96 7d47fac
replace array with Set
JoCa96 82123a3
add explanatory comments
JoCa96 c72133f
initial version
JoCa96 1c40d3b
added invalid tests
JoCa96 8e2cfd7
added valid tests cases
JoCa96 9d0e1c2
clean up
JoCa96 84b7b78
add docs
JoCa96 7bdf176
update related docs
JoCa96 b10bae2
add missing test fixture
JoCa96 2dc6949
fix link
JoCa96 9a8ccd7
fix missing typedef for NameWithLoc
JoCa96 dc011e0
lint issue: remove todo
JoCa96 8c71413
fix lint issue: "space inside link text"
JoCa96 f3ffb7d
remove unused options
JoCa96 066689b
replace array with Set
JoCa96 7941f9c
add explanatory comments
JoCa96 3901c99
review: execute "npm run update"
JoCa96 44f5eb4
Merge branch 'joca96/feat-no-shadow-native' of https://github.com/JoC…
JoCa96 b62c161
Update docs/rules/no-shadow-native-events.md
JoCa96 4feb834
Update docs/rules/no-shadow-native-events.md
JoCa96 3e9e020
review: revert accidental packageManager field in package.json
JoCa96 df3e87e
Merge branch 'joca96/feat-no-shadow-native' of https://github.com/JoC…
JoCa96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/no-shadow-native-events | ||
description: disallow `emits` which would shadow native html events | ||
--- | ||
# vue/no-shadow-native-events | ||
|
||
> disallow `emits` which would shadow native HTML events | ||
|
||
- :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 reports emits that shadow native HTML events. (The `emits` option is a new in Vue.js 3.0.0+) | ||
JoCa96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Using native event names for emits can lead to incorrect assumptions about an emit and cause confusion. This is caused by Vue emits behaving differently from native events. E.g. : | ||
|
||
- The payload of an emit can be chosen arbitrarily | ||
- Vue emits do not bubble, while most native events do | ||
- [Event modifiers](https://vuejs.org/guide/essentials/event-handling.html#event-modifiers) only work on HTML events or when the original event is re-emitted as emit payload. | ||
- When the native event is remitted the `event.target` might not match the actual event-listeners location. | ||
JoCa96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The rule is mostly aimed at developers of component libraries. | ||
|
||
<eslint-code-block :rules="{'vue/no-shadow-native-events': ['error']}"> | ||
|
||
```vue | ||
<template> | ||
<!-- ✓ GOOD --> | ||
<button @click="$emit('close')">Close</button> | ||
<!-- ✗ BAD --> | ||
<button @click="$emit('click')">Close</button> | ||
</template> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :couple: Related Rules | ||
|
||
- [vue/no-unused-emit-declarations](./no-unused-emit-declarations.md) | ||
- [vue/require-explicit-emits](./require-explicit-emits.md) | ||
|
||
## :books: Further Reading | ||
|
||
- [Components In-Depth - Events / Component Events](https://vuejs.org/guide/components/events.html#event-arguments) | ||
- [Vue RFCs - 0030-emits-option](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0030-emits-option.md) |
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.
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.