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-reflect-apply rule #239

Merged
merged 10 commits into from
Sep 16, 2019

Conversation

alexzherdev
Copy link
Contributor

Fixes #142

@futpib
Copy link
Contributor

futpib commented Apr 9, 2019

👍 This looks good so far, except, if we consider discussion in #142 settled, it should also handle this and arguments.

rules/prefer-reflect-apply.js Outdated Show resolved Hide resolved
@alexzherdev
Copy link
Contributor Author

alexzherdev commented Apr 17, 2019

Something's wrong with p-queue in the integration test, including on master.
ETA: fixed in c7a062e

if (fix) {
context.report({
node,
message: 'Prefer Reflect.apply over Function.prototype.apply.',
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
message: 'Prefer Reflect.apply over Function.prototype.apply.',
message: 'Prefer `Reflect.apply()` over `Function#apply()`.',

invalid: [
{
code: 'foo.apply(null, [42]);',
errors: [error],
Copy link
Owner

Choose a reason for hiding this comment

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

errors should be below output.

invalid: [
{
code: 'foo.apply(null, [42]);',
errors: [error],
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
errors: [error],
errors,

const error = {
ruleId: 'prefer-reflect-apply',
message: 'Prefer Reflect.apply over Function.prototype.apply.'
};
Copy link
Owner

Choose a reason for hiding this comment

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

Can just be:

const errors = [
	{
		ruleId: 'prefer-reflect-apply'
	}
];

const fixFunctionPrototypeCall = (node, sourceCode) => {
if (
astUtils.getPropertyName(node.callee) === 'call' &&
sourceCode.getText(node.callee.object) === 'Function.prototype.apply' &&
Copy link
Owner

Choose a reason for hiding this comment

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

I think it would be better to check the method chain in the actual AST, than comparing string representation of the resulting code.

@sindresorhus
Copy link
Owner

@alexzherdev Ping :)

@alexzherdev
Copy link
Contributor Author

@sindresorhus updated!

@sindresorhus sindresorhus merged commit 0b9c0fe into sindresorhus:master Sep 16, 2019
@sindresorhus
Copy link
Owner

🙌 Thanks for working on 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-reflect-apply
3 participants