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

Require a space between function and (. #605

Merged
merged 1 commit into from
Dec 3, 2015

Conversation

ljharb
Copy link
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
Collaborator

Yes please 👍

@wyattdanger
Copy link
Collaborator

👍

@jimrhoskins
Copy link

So much 👍


// good
const x = function () {};
const y = function a() {};

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

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

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

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