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 prefer-event-target rule #1792

Merged
merged 14 commits into from May 8, 2022

Conversation

jopemachine
Copy link
Contributor

@jopemachine jopemachine commented Apr 9, 2022

Thanks for this awesome lib!

Added prefer-event-target rule, Fixes #1740.

rules/prefer-event-target.js Outdated Show resolved Hide resolved
rules/prefer-event-target.js Show resolved Hide resolved
rules/prefer-event-target.js Outdated Show resolved Hide resolved
test/prefer-event-target.mjs Outdated Show resolved Hide resolved
const eventEmitterClassSelector = [
':matches(ClassDeclaration, ClassExpression)',
'[superClass.name="EventEmitter"]',
'[body.type="ClassBody"]',
Copy link
Collaborator

Choose a reason for hiding this comment

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

You added this body type check, but not tests covers this, is it possible to have different body here? Maybe in TypeScript? Please test it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You added this body type check, but not tests covers this, is it possible to have different body here? Maybe in TypeScript? Please test it.

I'm sorry, but I think I actually don't understand this feedback.

Is it possible to handle typescript with this lib?
I tried to insert a simple typescript statement (let a: number = 3;) and tested, but it seems like parsing error occurs.

I think class declaration's with other body type seems not possible, according to this ECMA document in Javascript,
In case of Typescript, this specification's 117 page

And FYI, when I added this selector, I referenced to /rules/no-static-only-class.js's selector.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know if it's possible to have different body in TS, I guess it's fine to keep this just in case.

If you find anything want test, you can use

test.typescript();
// OR
test.snapshot({
	valid: [
		{
			code: '',
			parser: parsers.typescript,
		}
	],
});

There are examples in other rules.

docs/rules/prefer-event-target.md Outdated Show resolved Hide resolved
docs/rules/prefer-event-target.md Outdated Show resolved Hide resolved
docs/rules/prefer-event-target.md Outdated Show resolved Hide resolved
docs/rules/prefer-event-target.md Outdated Show resolved Hide resolved
docs/rules/prefer-event-target.md Outdated Show resolved Hide resolved
docs/rules/prefer-event-target.md Outdated Show resolved Hide resolved
@jopemachine jopemachine requested a review from fisker April 13, 2022 03:27
rules/prefer-event-target.js Outdated Show resolved Hide resolved
rules/prefer-event-target.js Outdated Show resolved Hide resolved
test/prefer-event-target.mjs Show resolved Hide resolved
test/prefer-event-target.mjs Show resolved Hide resolved
test/prefer-event-target.mjs Show resolved Hide resolved
@jopemachine jopemachine requested a review from fisker April 16, 2022 06:15
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.

Two comments, otherwise looks good to me. Thanks!

@fisker
Copy link
Collaborator

fisker commented Apr 28, 2022

@jopemachine Can you fix the snapshot? npx ava test/prefer-event-target.mjs -u should work.

@sindresorhus sindresorhus merged commit 166524a into sindresorhus:main May 8, 2022
@jimmywarting
Copy link

Woho! thank you for this! 🎉

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: prefer EventTarget instead of EventEmitter
4 participants