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

Refactor simpleArraySearchRule #2111

Merged
merged 4 commits into from
May 17, 2023
Merged

Refactor simpleArraySearchRule #2111

merged 4 commits into from
May 17, 2023

Conversation

fisker
Copy link
Collaborator

@fisker fisker commented May 16, 2023

  • Use simple CallExpression selector.

Since prefer-array-index-of listens two different cases, I don't want to merge listeners manually, so I added a .on method to context. ecf02e2

Feel it can be useful, we can

module.exports = {
	create(context) {
		context.on('CallExpression', node => {
			checkOneCaseWithCallExpression();
		})
		context.on('CallExpression', node => {
			checkAnotherCaseWithCallExpression();
		})
	}
}

instead of

module.exports = {
	create(context) {
		return {
			CallExpression(node) {
				checkOneCaseWithCallExpression();
				checkAnotherCaseWithCallExpression();
			}
		}
	}
}

Existing rule

https://github.com/fisker/eslint-plugin-unicorn/blob/c3a485ddb9521b66961c38709a31b9af92042b4f/rules/prefer-date-now.js#L35-L72

Can be separate into two listeners, we don't have to put two total different logic in one function

@fisker fisker marked this pull request as ready for review May 16, 2023 09:22
@fisker fisker requested a review from sindresorhus May 16, 2023 09:22
@sindresorhus
Copy link
Owner

Good idea

@sindresorhus
Copy link
Owner

Can you fix the conflict?

@fisker fisker merged commit 2bfc7c2 into sindresorhus:main May 17, 2023
20 checks passed
@fisker fisker deleted the context.on branch May 17, 2023 06:43
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.

None yet

2 participants