Skip to content

Space after function name in declarations #3845

@justrhysism

Description

@justrhysism

NOTE: This issue is raised due to confusion in #1139.
NOTE: Feel free to use the 👍 and 👎 buttons to indicate your preferences, but please refrain from commenting unless you’ve read every comment and made sure yours says something that has not been said before.

This issue is only about outputting these spaces:

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

function identity <T>(value: T): T {
  //             ^ space here
  return value;
}

class A {
  method () {
    //  ^ space here
  }
}

const obj = {
  method () {
    //  ^ space here
  }
}

(Prettier currently does not put spaces in those positions.)

🗒 NOTE: This issue is not about anonymous functions:

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

Anonymous functions are tracked in #3847!

The key arguments is:
Searchability: You can find any function or method declaration my searching for e.g. method ( or identity <, or even just name[space] (mostly).

It also provides a clear and immediate difference between declaration and invocation.

(There are many existing comments in favour of this style, notably: #1139 (comment) and the majority of the discussion from #1139 (comment) onwards.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:flowIssues affecting Flow-specific constructs (not general JS issues)lang:javascriptIssues affecting JSlang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)status:wontfixThis will not be worked ontype:option requestIssues requesting a new option. We generally don’t accept these unless there is technical necessity.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions