2 title: space-before-keywords
7 - space-return-throw-case
12 Enforces consistent spacing before keywords.
14 (removed) This rule was **removed** in ESLint v2.0 and **replaced** by the [keyword-spacing](keyword-spacing) rule.
16 (fixable) The `--fix` option on the [command line](../use/command-line-interface#--fix) automatically fixed problems reported by this rule.
18 Keywords are syntax elements of JavaScript, such as `function` and `if`. These identifiers have special meaning to the language and so often appear in a different color in code editors. As an important part of the language, style guides often refer to the spacing that should be used around keywords. For example, you might have a style guide that says keywords should be always be preceded by spaces, which would mean `if-else` statements must look like this:
28 Of course, you could also have a style guide that disallows spaces before keywords.
32 This rule will enforce consistency of spacing before the keywords `if`, `else`, `for`,
33 `while`, `do`, `switch`, `throw`, `try`, `catch`, `finally`, `with`, `break`, `continue`,
34 `return`, `function`, `yield`, `class` and variable declarations (`let`, `const`, `var`)
37 This rule takes one argument: `"always"` or `"never"`. If `"always"` then the keywords
38 must be preceded by at least one space. If `"never"` then no spaces will be allowed before
39 the keywords `else`, `while` (do...while), `finally` and `catch`. The default value is `"always"`.
41 This rule will allow keywords to be preceded by an opening curly brace (`{`). If you wish to alter
42 this behavior, consider using the [block-spacing](block-spacing) rule.
44 Examples of **incorrect** code for this rule with the default `"always"` option:
49 /*eslint space-before-keywords: ["error", "always"]*/
56 const foo = 'bar';let baz = 'qux';
58 var foo =function bar () {}
67 Examples of **correct** code for this rule with the default `"always"` option:
72 /*eslint space-before-keywords: ["error", "always"]*/
81 <Foo onClick={function bar() {}} />
83 for (let foo of ['bar', 'baz', 'qux']) {}
88 Examples of **incorrect** code for this rule with the `"never"` option:
93 /*eslint space-before-keywords: ["error", "never"]*/
111 Examples of **correct** code for this rule with the `"never"` option:
116 /*eslint space-before-keywords: ["error", "never"]*/
131 ## When Not To Use It
133 If you do not wish to enforce consistency on keyword spacing.