Unnecessary event args due to unicorn/prevent-abbreviations
See original GitHub issueMore a side-effect than a bug of unicorn/prevent-abbreviations. Due to this rule, lots of devs just changed the e in an eventlistener to the (global) event variable.
This rule or a separate rule should check to avoid unnecessary passing of the global event variable in an eventlistener.
unicorn/prevent-abbreviations
document.body.addEventListener( 'mousedown', ( event ) => {
if ( event.target.indexOf( 'giraffe' ) ) {
alert( 'It's a giraffe!' );
}
}, { passive: true });
The ( event )
is unnecessary, since event is a globally available variable with the event details, so just ()
would suffice here.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Rule proposal: Prevent abbreviations · Issue #169 - GitHub
args => arguments is almost necessary, since arguments is reserved. ... is raising a "unicorn/prevent-abbreviations" warning.
Read more >Unnecessary event args due to unicorn/prevent-abbreviations #1430
This rule or a separate rule should check to avoid unnecessary passing of the global event variable in an eventlistener. <!-- 2️⃣ Specify...
Read more >eslint-plugin-unicorn/readme.md - UNPKG
The CDN for eslint-plugin-unicorn. ... -invalid-remove-event-listener](docs/rules/no-invalid-remove-event-listener.md) | Prevent ... Prevent abbreviations.
Read more >Codiga Analysis JavaScript Rules
unicorn /prevent-abbreviations. Best practice. Informational. Using complete words results in more readable code. Not everyone knows all your abbreviations ...
Read more >UNICORN 5.0 User Reference Manual
A framework Method with default parameters can be changed to create ... Backup copies should be taken regularly to avoid data loss in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I disagree. Even if there’s a global with the same name, it’s clearer to use the shadowing local variable.
We already did,
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/2d052526d2f8e926487a957bb27e8a88e95b96a5/test/prevent-abbreviations.mjs#L1809-L1831
You must use
event
somewhere else.