Skip to content

Require a space between function and (.#605

Merged
ljharb merged 1 commit into
masterfrom
ljharb/fix_function_spacing
Dec 3, 2015
Merged

Require a space between function and (.#605
ljharb merged 1 commit into
masterfrom
ljharb/fix_function_spacing

Conversation

@ljharb
Copy link
Copy Markdown
Collaborator

@ljharb ljharb commented Dec 3, 2015

The guide was inconsistent in its use of spacing, and the most common convention both inside Airbnb and in community JS is to require this space. This both adds a section on it, and enables the linting rule.

…nction's name, and disallow spaces between the function's name and `(`.
@goatslacker
Copy link
Copy Markdown
Collaborator

Yes please 👍

@wyattdanger
Copy link
Copy Markdown
Collaborator

👍

@jimrhoskins
Copy link
Copy Markdown

So much 👍

Comment thread README.md
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the guide (https://github.com/eslint/eslint/blob/master/docs/rules/space-before-function-paren.md) this should be const y = function a () {}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, i think i want {"anonymous": "always", "named": "never"} as a config then.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway there's another rule that says anonymous function should be named (or use arrow functions)

@jimrhoskins
Copy link
Copy Markdown

I like this rule, but for a reason different than the explanation submitted. It reserves parentheses touching the word before them strictly for function invocations. Then other parenthesis uses are spaced (e.g. if/while/for and func definitions). It makes for a simple rule to remember "put a space before ( unless you are invoking a method".

To that end, this would also apply to method definitions and named functions. See the "always" examples for the rule https://github.com/eslint/eslint/blob/master/docs/rules/space-before-function-paren.md

@ljharb ljharb force-pushed the ljharb/fix_function_spacing branch from 2e60adf to 599ca4f Compare December 3, 2015 18:57
@ljharb
Copy link
Copy Markdown
Collaborator Author

ljharb commented Dec 3, 2015

Sorry about that - I've fixed the eslint rules to match what I typed in the guide itself. There must never be a space between a function's name and the (, and there must always be precisely one space after function.

@jimrhoskins
Copy link
Copy Markdown

Ah, darn. I like "always", but understand not everyone agrees 😞

ljharb added a commit that referenced this pull request Dec 3, 2015
[breaking] Require function spacing: `function <optional name>(`
@ljharb ljharb merged commit 326100a into master Dec 3, 2015
@ljharb ljharb deleted the ljharb/fix_function_spacing branch December 3, 2015 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants