question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unnecessary event args due to unicorn/prevent-abbreviations

See original GitHub issue

More 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sindresorhuscommented, Jul 17, 2021

I disagree. Even if there’s a global with the same name, it’s clearer to use the shadowing local variable.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found