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

[Fix] destructuring-assignment: fix a false prositive for local prop named context in SFC #2912

Closed
wants to merge 1 commit into from

Conversation

SyMind
Copy link
Contributor

@SyMind SyMind commented Jan 29, 2021

Fixes #2911.

Comment on lines +23 to +40
get propsName() {
for (const params of queue) {
const props = params[0];
if (props && !props.destructuring && props.name) {
return props.name;
}
}
return null;
},
get contextName() {
for (const params of queue) {
const context = params[1];
if (context && !context.destructuring && context.name) {
return context.name;
}
}
return null;
}
Copy link
Member

Choose a reason for hiding this comment

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

getters are slow and the indirection is less maintainable; let's just make these functions.

Suggested change
get propsName() {
for (const params of queue) {
const props = params[0];
if (props && !props.destructuring && props.name) {
return props.name;
}
}
return null;
},
get contextName() {
for (const params of queue) {
const context = params[1];
if (context && !context.destructuring && context.name) {
return context.name;
}
}
return null;
}
propsName() {
for (const params of queue) {
const props = params[0];
if (props && !props.destructuring && props.name) {
return props.name;
}
}
return null;
},
contextName() {
for (const params of queue) {
const context = params[1];
if (context && !context.destructuring && context.name) {
return context.name;
}
}
return null;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, but why getters are slow and the indirection is less maintainable, please tell me more detail. please do tell me!

Copy link
Member

Choose a reason for hiding this comment

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

They’re slow because it takes more effort for the engine to use them; they’re less maintainable because it looks like a property at the usage site, but it’s actually invoking a function. Making it a real function means you add () and suddenly everything is faster and more obvious. Getters and setters are bad and should be avoided.

Copy link

@cha0s cha0s Feb 10, 2021

Choose a reason for hiding this comment

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

I haven't contributed code to this issue I originally reported (thanks @SyMind), but I am just reviewing what has been done so far and I feel compelled to say: that's a bad take. Getters and setters are quite a bit more performant than you might think (I use them in real-time applications even with emitters/streams to great effect), but I can respect that since you maintain this project you may have a different opinion and be within your rights to enforce your opinion.

@@ -38,21 +76,22 @@ module.exports = {
create: Components.detect((context, components, utils) => {
const configuration = context.options[0] || DEFAULT_OPTION;
const ignoreClassFields = (context.options[1] && (context.options[1].ignoreClassFields === true)) || false;
const sfcParams = createSFCParams();
Copy link
Member

Choose a reason for hiding this comment

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

hm, does eslint itself not have utilities for determining the relationship to function params?

@SyMind SyMind closed this Feb 19, 2021
@ljharb
Copy link
Member

ljharb commented Feb 19, 2021

@SyMind are you no longer interested in completing this PR? it's just awaiting some tweaks.

@ljharb
Copy link
Member

ljharb commented Feb 19, 2021

Although it looks like you deleted your fork, which is very sad, because I think that's an unrecoverable state.

@SyMind
Copy link
Contributor Author

SyMind commented Feb 19, 2021

@ljharb Sorry, I did a stupid git push --force. I will pull request again.

@ljharb
Copy link
Member

ljharb commented Feb 19, 2021

ok, thanks

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

Successfully merging this pull request may close these issues.

Local prop named context erroneously handled as this.context
3 participants