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

Should => { return be bad text? #790

Closed
zepumph opened this issue Sep 12, 2019 · 7 comments
Closed

Should => { return be bad text? #790

zepumph opened this issue Sep 12, 2019 · 7 comments
Assignees

Comments

@zepumph
Copy link
Member

zepumph commented Sep 12, 2019

IMO one lined arrow functions that return something should not use the curly braces and return keyword, because it is simpler to just have arg => arg === 3 instead of arg => { return arg === 3; }.

If it is a more complex arrow function, then perhaps it can be on more than one line, and then include those pieces. There are currently 33 usages of => { return.

Marking for developer meeting.

@samreid
Copy link
Member

samreid commented Sep 19, 2019

All of the existing 33 cases should be converted, they will be more readable without the {return ;}. I also think the lint rule would be a good idea, thanks!

@jonathanolson
Copy link
Contributor

I could imagine having a filter arrow function where it's one expression to return BUT really needs to take up multiple lines. I find the braces to be helpful for multi-line arrow functions, but I would prefer the one-liners (brace, space, return) to be converted.

@pixelzoom
Copy link
Contributor

Should arg => also be preferred over ( arg ) => ?

@pixelzoom pixelzoom changed the title Should => { return be bad text? Should => { return be bad text? Sep 19, 2019
@pixelzoom pixelzoom changed the title Should => { return be bad text? Should => { return be bad text? Sep 19, 2019
@samreid
Copy link
Member

samreid commented Sep 19, 2019

@pixelzoom
Copy link
Contributor

pixelzoom commented Sep 19, 2019

@jonathanolson said:

I could imagine having a filter arrow function where it's one expression to return BUT really needs to take up multiple lines. I find the braces to be helpful for multi-line ...

Something like this:

arg => {
  return expression1 && expression2 && expression3 && .... && expressionN;
} 

can be written without curly braces as:

arg => ( expression1 && expression2 && expression3 && .... && expressionN )

@zepumph
Copy link
Member Author

zepumph commented Sep 19, 2019

From this issue will investigate two lint rules:

zepumph added a commit to phetsims/number-line-integers that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/gravity-and-orbits that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/natural-selection that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/energy-skate-park that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/fractions-common that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/build-a-molecule that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/vector-addition that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/gas-properties that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/scenery-phet that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/perennial that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/molarity that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/friction that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/john-travoltage that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/collision-lab that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/simula-rasa that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/masses-and-springs-basics that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/fluid-pressure-and-flow that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/number-line-integers that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/charges-and-fields that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/energy-skate-park that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/a11y-research that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/perennial that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/tambo that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/axon that referenced this issue Sep 19, 2019
zepumph added a commit to phetsims/vector-addition that referenced this issue Sep 19, 2019
@zepumph
Copy link
Member Author

zepumph commented Sep 19, 2019

There were ~160 issues with arrow-parens "as-needed". The fixes are above, lint rule commit coming in shortly.

I looked into using arrow-body-style "as-needed" but it trying to convert too many arrow functions into complicated one-liners that were 160+ chars long (about 150 of them). So instead I just manually added the namesake of this issue as bad text. There were 30 usages of that.

The rules are now committed and lint is passing. Closing

@zepumph zepumph closed this as completed Sep 19, 2019
zepumph added a commit to phetsims/utterance-queue that referenced this issue Oct 22, 2019
zepumph added a commit to phetsims/utterance-queue that referenced this issue Oct 22, 2019
zepumph added a commit to phetsims/perennial that referenced this issue Jul 21, 2022
samreid pushed a commit to phetsims/perennial that referenced this issue Oct 17, 2024
zepumph added a commit to phetsims/perennial that referenced this issue Oct 22, 2024
zepumph added a commit to phetsims/perennial that referenced this issue Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants