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鈥檒l 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

Comments

@lydell
Copy link
Member

@lydell 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.

@allex
Copy link

@allex allex commented Feb 5, 2018

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

@azz
Copy link
Member

@azz azz commented Feb 5, 2018

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

@alexburner
Copy link

@alexburner alexburner commented Feb 6, 2018

+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 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 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 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 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

@josephfrazier josephfrazier commented Feb 6, 2018

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

@coolemur

This comment was marked as off-topic.

@j-f1

This comment was marked as off-topic.

@coolemur

This comment was marked as off-topic.

@j-f1

This comment was marked as off-topic.

@coolemur

This comment was marked as off-topic.

@jameshhood

This comment was marked as off-topic.

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

This comment was marked as off-topic.

@duailibe

This comment was marked as off-topic.

@jameshhood

This comment was marked as off-topic.

@coolemur

This comment was marked as off-topic.

@Smithx10

This comment was marked as off-topic.

@lipis
Copy link
Member

@lipis 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 was marked as off-topic.

@lydell

This comment was marked as off-topic.

@friederbluemle

This comment was marked as off-topic.

@lydell

This comment was marked as off-topic.

@sosukesuzuki
Copy link
Member

@sosukesuzuki sosukesuzuki commented Nov 2, 2019

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

@friederbluemle

This comment was marked as off-topic.

@bzhang

This comment was marked as off-topic.

@lydell
Copy link
Member Author

@lydell lydell commented Nov 3, 2019

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

@brainkim
Copy link
Contributor

@brainkim brainkim commented Nov 22, 2019

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

@sosukesuzuki sosukesuzuki commented Jan 6, 2020

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

thorn0 added 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
Collaborator

@thorn0 thorn0 commented Jan 20, 2020

fixed by #3903

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet