-
Notifications
You must be signed in to change notification settings - Fork 207
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
style: prefer arrow functions #4608
Conversation
@@ -1,3 +1,4 @@ | |||
/* global solo */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solo
is not a global. It's defined in this file.
Somehow the conversion to arrow functions changed export default async function solo() { ... }
to an anonymous export default const async () => { ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes much more sense. Seems like a bug in the transformer, not considering that a default export may have its name used locally. We can work around it by defining const solo =
and export default solo
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can work around it by defining
const solo =
andexport default solo
.
That would make me sad as a pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want that! Any alternative solutions you would recommend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The playground at https://astexplorer.net/#/gist/7c36fe8c604945df27df210cf79dcc3c/12f01bed4dcf08f32a85f72db0851440b7e45cdd shows that classPropertiesAllowed: true
rewrites
class MyClass {
render(a, b) {
console.log(3);
}
}
to
class MyClass {
render = (a, b) => {
console.log(3);
};
}
This is not semantics preserving, or even close. Therefore, let's decide false
.
That is the setting in the PR, so not requesting any changes for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decide on https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions#disallowprototype
I can't figure out what is this, from either the description or the playground. First, do no harm. Let's decide on false
to minimize unintended damage.
That's current setting in this PR, so no change requested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decide on https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions#returnstyle
The current setting on this PR is "unchanged"
. Both @dtribble and I would prefer "implicit"
. But a brief experiment showed it rewriting
const coerceLR = (h, leftAmount, rightAmount) => {
// @ts-ignore cast (ignore b/c erroring in CI but not my IDE)
return [h.doCoerce(leftAmount.value), h.doCoerce(rightAmount.value)];
};
to
const coerceLR = (h, leftAmount, rightAmount) => [
h.doCoerce(leftAmount.value),
h.doCoerce(rightAmount.value),
];
which is not semantics preserving, because we put some semantics in comments. But even if we didn't, deleting user-written comments is unacceptable.
Let's decide to keep this PR's current setting of "unchanged"
.
Not requesting any changes for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decide on https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions#singlereturnonly
This one should obviously be false
, as it is in this PR. No change requested.
I corrected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decide on whether to include arrowParens in Prettier (we punted at the last upgrade because of the churn, but these are all about to be churned)
We actually argued this one out long ago and decided on the current behavior: that a parameter list containing only a single identifier must not have parens. I didn't inject this in the recent churn because we arrived at the same conclusion anyway.
It seems this is the meaning of the "avoid"
setting, which is the current setting of this PR. No change requested.
I propose we have agreement, pending only more eyes on the actual code to see if there is any unexpected damage with these settings. We still need to do some of that before we can approve and merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just doing a yarn lint
at the top of a fresh checkout of this PR, I found much damage. I commented on the first, in bundle.js . This seems like a show stopping degree of damage. I'm marking this "request changes" to block merging. But I expect the changes we need is to the rewriter itself. Otherwise we should just close this PR but leave corresponding bugs open.
const { hasBundle, getBundle, getNamedBundleID } = endowments; | ||
const { syscall } = tools; | ||
const dtools = buildSerializationTools(syscall, 'bundle'); | ||
const { unserialize, returnFromInvoke, deviceNodeForSlot } = dtools; | ||
|
||
const ROOT = 'd+0'; | ||
const bundleIDRE = new RegExp('^b1-[0-9a-f]{128}$'); | ||
const bundleIDRE = new RegExp('^b1-[0-9a-f]{128}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WTF It removed the terminating $'
from the literal string. If this transformation is this buggy, I don't think we can use it.
transformation too buggy to use |
Description
Our coding style is to use arrow functions but much code remains from before that decision.
https://github.com/JamieMason/eslint-plugin-prefer-arrow-functions provides a dandy way to automatically fix over the repo.
Before merging:
I propose this as the path to transforming the whole codebase
Security Considerations
-->
Documentation Considerations
Testing Considerations