Skip to content
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

Add no-invalid-remove-event-listener rule #1216

Merged
merged 16 commits into from Aug 8, 2021
Merged

Add no-invalid-remove-event-listener rule #1216

merged 16 commits into from Aug 8, 2021

Conversation

bschlenk
Copy link
Contributor

Closes #682

docs/rules/no-invalid-remove-event-listener.md Outdated Show resolved Hide resolved
docs/rules/no-invalid-remove-event-listener.md Outdated Show resolved Hide resolved
docs/rules/no-invalid-remove-event-listener.md Outdated Show resolved Hide resolved
docs/rules/no-invalid-remove-event-listener.md Outdated Show resolved Hide resolved
rules/no-invalid-remove-event-listener.js Outdated Show resolved Hide resolved
test/no-invalid-remove-event-listener.mjs Show resolved Hide resolved
@sindresorhus
Copy link
Owner

@bschlenk Friendly bump :)

rules/no-invalid-remove-event-listener.js Outdated Show resolved Hide resolved
const MESSAGE_ID = 'no-invalid-remove-event-listener';
const messages = {
[MESSAGE_ID]:
'Store the result of this expression in a variable that is passed to both `removeEventListener` the corresponding `addEventListener`.'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about The listener agument should be a function reference.?

@fisker

This comment has been minimized.

@fisker fisker changed the title Add no-invalid-event-listener rule Add no-invalid-remove-event-listener rule Jun 3, 2021
@bmish
Copy link
Sponsor Collaborator

bmish commented Jun 3, 2021

Maybe we can name it valid-remove-event-listener instead of no-invalid-remove-event-listener? @bmish ?

I commonly use no-invalid- as a rule name prefix (require-valid- could also work).

@fisker
Copy link
Collaborator

fisker commented Jun 4, 2021

Looks good, I'll make some adjustment.

@fisker
Copy link
Collaborator

fisker commented Jun 4, 2021

@bschlenk I can't push to your fork, please merge this https://github.com/bschlenk/eslint-plugin-unicorn/pull/1.

Next time try not to use the main branch.

@fisker
Copy link
Collaborator

fisker commented Jun 4, 2021

Can you improve the report location a little bit, if it's a function, use getFunctionHeadLocation, otherwise, report on the bind. I think it will be better if the function is really long.

Comment on lines 10 to 14
const isBindCall = node =>
node.type === 'CallExpression' &&
node.callee.type === 'MemberExpression' &&
node.callee.property.name === 'bind' &&
!node.callee.computed;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function isn't used anymore. Do the below matchers handle when the callee is computed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, remove it, all tested.

@bschlenk
Copy link
Contributor Author

bschlenk commented Jun 4, 2021

I can't push to your fork

I didn't realize GitHub let you do that. When can you push to someone else's fork?

@fisker
Copy link
Collaborator

fisker commented Jun 4, 2021

Yes, people do this all the time. There is checkbox "allow maintainer edit"(something like that) on right side of this page, it should be checked. I'm not sure if it because you used default branch.

@bschlenk
Copy link
Contributor Author

bschlenk commented Jun 4, 2021

That's cool! It does say you should be able to push to the main branch

If checked, users with write access to sindresorhus/eslint-plugin-unicorn can add new commits to your main branch. You can always change this setting later.

Copy link
Collaborator

@fisker fisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@fisker
Copy link
Collaborator

fisker commented Jun 4, 2021

Need fix style npx xo --fix

@fisker
Copy link
Collaborator

fisker commented Jul 13, 2021

@bschlenk Can you rebase this and run npx xo --fix? We recently enabled trailing comma.

@bschlenk
Copy link
Contributor Author

Running npx xo --fix didn't change any of the files I added, but it changed almost every other file in the repo...

@sindresorhus
Copy link
Owner

You probably need to rebase from the main branch first.

@bschlenk
Copy link
Contributor Author

I forgot to npm install, I had an outdated xo 🤦‍♂️

@sindresorhus
Copy link
Owner

@bschlenk Can you ensure the tests are passing?

readme.md Outdated
@@ -167,6 +168,7 @@ Each rule has emojis denoting:
| [no-for-loop](docs/rules/no-for-loop.md) | Do not use a `for` loop that can be replaced with a `for-of` loop. | ✅ | 🔧 | |
| [no-hex-escape](docs/rules/no-hex-escape.md) | Enforce the use of Unicode escapes instead of hexadecimal escapes. | ✅ | 🔧 | |
| [no-instanceof-array](docs/rules/no-instanceof-array.md) | Require `Array.isArray()` instead of `instanceof Array`. | ✅ | 🔧 | |
| [no-invalid-remove-event-listener](docs/rules/no-invalid-remove-event-listener.md) | Prevent calling removeEventListener with the result of an expression | ✅ | | |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description here needs to be regenerated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what you mean? Make this description match the one from docs/rules/no-invalid-remove-event-listener.md?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run npm run generate-rules-table and npm run generate-usage-example

@bschlenk
Copy link
Contributor Author

bschlenk commented Aug 4, 2021

Thanks for helping, it's hard to keep up with all the changes in this repo.

@fisker
Copy link
Collaborator

fisker commented Aug 7, 2021

@sindresorhus I think this rule is ready for review, the code part looks good to me.

@sindresorhus sindresorhus merged commit f0ff04d into sindresorhus:main Aug 8, 2021
@sindresorhus
Copy link
Owner

Looks good :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: Disallow calling add/removeEventListener with the result of a bound function call
4 participants