-
-
Notifications
You must be signed in to change notification settings - Fork 681
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
Rule Proposal: Warn on emitting camelCase events #356
Comments
Thank you for the proposal. Sounds good to me! |
I agree this would be good to add to Also, this will provide new alerts for some users, for code that may not have been causing a problem before, so I think the message will be especially important. Perhaps something like:
Of course, we'll replace |
We were bitten by this silent error today. 😞 The PR that @chrisvfritz referenced as a blocker was merged back in December so it shouldn't be a blocker anymore. 😁 |
I'd also like this. |
Please describe what the rule should do:
Ensure that developers emit events that are compatible with specifying listeners in a DOM-based template.
What category of rule is this? (place an "X" next to just one item)
[ ] Enforces code style
[x] Warns about a potential error
[ ] Suggests an alternate way of doing something
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
...
Why should this rule be included in ESLint (instead of a plugin)?
If a component emits an event that includes a capital letter and you instantiate that component within an SFC or string template, you can use the
@eventName
/v-on:eventName
attribute successfully to capture that event.However, if you instantiate the component from within a DOM-based template, there is no way to capture the event. For props, Vue translates automatically between pascalCase and kebab-case, but it doesn't do so for events. Events simply won't be captured unless the listener attribute matches the emitted event string exactly.
As a result, component authors should be warned when they are creating events that can't be listened for from a DOM-based template. While I don't use DOM templates (I use SFCs almost exclusively), they are used quite often by new Vue developers, or developers just trying to play with a component.
Since this falls under the "silent failure" category, it's pretty frustrating both for the user and the component developer, but a rule to flag it during linting would be fairly simple to create.
The text was updated successfully, but these errors were encountered: