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

Space after function keyword in anonymous functions #3847

Closed
lydell opened this issue Jan 31, 2018 · 146 comments
Closed

Space after function keyword in anonymous functions #3847

lydell opened this issue Jan 31, 2018 · 146 comments
Labels
lang:flow Issues affecting Flow-specific constructs (not general JS issues) lang:javascript Issues affecting JS lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Milestone

Comments

@lydell
Copy link
Member

lydell commented Jan 31, 2018

NOTE: This issue is raised due to confusion in #1139.

This issue is only about anonymous functions:

const identity = function (value) {
  //                     ^ space here
  return value;
}

(Prettier currently does not put a space there.)

🗒 NOTE: This issue is not about having a space after the function name:

function identity (value) {
  //             ^ space here: SEE #3845!
  return value;
}

Space after function name is tracked in #3845!

The key argument is:
Consistency: This means that there's always a space after the function keyword.

@lydell lydell added status:needs discussion Issues needing discussion and a decision to be made before action can be taken lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) lang:javascript Issues affecting JS lang:flow Issues affecting Flow-specific constructs (not general JS issues) labels Jan 31, 2018
@allex
Copy link

allex commented Feb 5, 2018

why not provide a --space-before-function-paren option

@azz
Copy link
Member

azz commented Feb 5, 2018

@allex please read https://prettier.io/docs/en/option-philosophy.html

@alexburner
Copy link

+1 for space after function keyword. Crockford supports this:

If a function literal is anonymous, there should be one space between the word function and the ( left parenthesis. If the space is omitted, then it can appear that the function's name is function, which is an incorrect reading.

@allex
Copy link

allex commented Feb 6, 2018

y, For a generic tools, we need keep simple options as possible. but lots of project lint with standard with the space-before-fuction-paren enabled by the default.

@k15a
Copy link
Collaborator

k15a commented Feb 6, 2018

@allex Don't lint stylistic issues when you use Prettier and all the problems are gone.

If you say that generic tools should provide simple options why is standard not providing an option to turn stylistic linting off?

@j-f1
Copy link
Member

j-f1 commented Feb 6, 2018

How should a generator function be formatted?

const identity = function *(value) {
  //                     ^ space here
  return value;
}

// or:
const identity = function* (value) {
  //                      ^ space here
  return value;
}

// or:
const identity = function * (value) {
  //                     ^ ^ spaces here
  return value;
}

@lydell
Copy link
Member Author

lydell commented Feb 6, 2018

Since this is all about consistency with named functions, the spaces should be exactly like for a named generator function. function* gen() {} and function* () {}

@josephfrazier
Copy link
Collaborator

I agree with @lydell. In this case, I'd consider the keyword to be function*, not function.

@coolemur

This comment has been minimized.

@j-f1

This comment has been minimized.

@coolemur

This comment has been minimized.

@j-f1

This comment has been minimized.

@coolemur

This comment has been minimized.

@jameshhood

This comment has been minimized.

@suchipi suchipi changed the title Space after function keyword Space after function keyword in anonymous functions Feb 22, 2018
@coolemur

This comment has been minimized.

@duailibe

This comment has been minimized.

@jameshhood

This comment has been minimized.

@coolemur

This comment has been minimized.

@Smithx10

This comment has been minimized.

@lipis
Copy link
Member

lipis commented Nov 1, 2019

I'm down to have that as default without an option for Version 2.

@lipis lipis added this to the 2.0 milestone Nov 1, 2019
@friederbluemle

This comment has been minimized.

@lipis lipis added help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! and removed status:needs discussion Issues needing discussion and a decision to be made before action can be taken labels Nov 1, 2019
@lydell

This comment has been minimized.

@friederbluemle

This comment has been minimized.

@lydell

This comment has been minimized.

@sosukesuzuki
Copy link
Member

I think we should reopen #3903 and merge to next branch

@friederbluemle

This comment has been minimized.

@bzhang

This comment has been minimized.

@lydell
Copy link
Member Author

lydell commented Nov 3, 2019

Removing the “help wanted” label, because we already have #3903. Code is the easy part here. This requires some core coordination to get done.

@lydell lydell removed the help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! label Nov 3, 2019
@brainkim
Copy link
Contributor

See #7028 for a related discussion about generator stars. I think consideration of generator stars is the strongest argument for adding a space after the function keyword.

Also IMO having this done as an option is the worst of all possible choices.

@sosukesuzuki sosukesuzuki modified the milestones: 3.0, 2.0 Jan 6, 2020
@sosukesuzuki
Copy link
Member

I modified the milestone to 2.0. if there is problems please let me know

thorn0 pushed a commit to j-f1/forked-prettier that referenced this issue Jan 20, 2020
thorn0 added a commit that referenced this issue Jan 20, 2020
* Always add a space after the `function` keyword

* WIP update snapshots

* WIP put generator function asterisk before space

#3847 (comment)

* WIP update snapshots

* Add changelog

* Add tests for anonymouse generator function

* print space between `function` and generator star

* update changelog

* print space between yield and *

Co-authored-by: Joseph Frazier <1212jtraceur@gmail.com>
Co-authored-by: Sosuke Suzuki <aosukeke@gmail.com>
Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com>
@thorn0
Copy link
Member

thorn0 commented Jan 20, 2020

fixed by #3903

@thorn0 thorn0 closed this as completed Jan 20, 2020
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Apr 25, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:flow Issues affecting Flow-specific constructs (not general JS issues) lang:javascript Issues affecting JS lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests