1 # space-before-function-parentheses: enforce consistent spacing before opening parenthesis in function definitions
3 (removed) This rule was **removed** in ESLint v1.0 and **replaced** by the [space-before-function-paren](space-before-function-paren.md) rule. The name of the rule changed from "parentheses" to "paren" for consistency with the names of other rules.
5 When formatting a function, whitespace is allowed between the function name or `function` keyword and the opening paren. Named functions also require a space between the `function` keyword and the function name, but anonymous functions require no whitespace. For example:
8 function withoutSpace(x) {
12 function withSpace (x) {
16 var anonymousWithoutSpace = function() {};
18 var anonymousWithSpace = function () {};
21 Style guides may require a space after the `function` keyword for anonymous functions, while others specify no whitespace. Similarly, the space after a function name may or may not be required.
25 This rule aims to enforce consistent spacing before function parentheses and as such, will warn whenever whitespace doesn't match the preferences specified.
27 This rule takes one argument. If it is `"always"`, which is the default option, all named functions and anonymous functions must have space before function parentheses. If `"never"` then all named functions and anonymous functions must not have space before function parentheses. If you want different spacing for named and anonymous functions you can pass a configuration object as the rule argument to configure those separately (e. g. `{"anonymous": "always", "named": "never"}`).
29 Examples of **incorrect** code for this rule with the default `"always"` option:
38 var bar = function() {
42 var bar = function foo() {
59 Examples of **correct** code for this rule with the default `"always"` option:
68 var bar = function () {
72 var bar = function foo () {
89 Examples of **incorrect** code for this rule with the `"never"` option:
98 var bar = function () {
102 var bar = function foo () {
119 Examples of **correct** code for this rule with the `"never"` option:
128 var bar = function() {
132 var bar = function foo() {
149 Examples of **incorrect** code for this rule with the `{"anonymous": "always", "named": "never"}` option:
158 var bar = function() {
175 Examples of **correct** code for this rule with the `{"anonymous": "always", "named": "never"}` option:
184 var bar = function () {
201 Examples of **incorrect** code for this rule with the `{"anonymous": "never", "named": "always"}` option:
210 var bar = function () {
227 Examples of **correct** code for this rule with the `{"anonymous": "never", "named": "always"}` option:
236 var bar = function() {
253 ## When Not To Use It
255 You can turn this rule off if you are not concerned with the consistency of spacing before function parenthesis.
259 * [space-after-keywords](space-after-keywords.md)
260 * [space-return-throw-case](space-return-throw-case.md)