From 586855060afb3201f4752be8820dc85703b523a6 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Tue, 5 Nov 2019 08:49:37 +0800 Subject: [PATCH] Docs: add notice about `function` keyword in keyword-spacing (#12524) * Docs: add notice about `function` keyword in keyword-spacing * Docs: publish Co-Authored-By: Kai Cataldo <7041728+kaicataldo@users.noreply.github.com> --- docs/rules/keyword-spacing.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/rules/keyword-spacing.md b/docs/rules/keyword-spacing.md index becc9ef323a..ecc6bb0a49a 100644 --- a/docs/rules/keyword-spacing.md +++ b/docs/rules/keyword-spacing.md @@ -1,7 +1,7 @@ # enforce consistent spacing before and after keywords (keyword-spacing) -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. +Keywords are syntax elements of JavaScript, such as `try` and `if`. +These keywords 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 surrounded by spaces, which would mean `if-else` statements must look like this: @@ -15,6 +15,8 @@ if (foo) { Of course, you could also have a style guide that disallows spaces around keywords. +However, if you want to enforce the style of spacing between the `function` keyword and the following opening parenthesis, please refer to [space-before-function-paren](space-before-function-paren.md). + ## Rule Details This rule enforces consistent spacing around keywords and keyword-like tokens: `as` (in module declarations), `async` (of async functions), `await` (of await expressions), `break`, `case`, `catch`, `class`, `const`, `continue`, `debugger`, `default`, `delete`, `do`, `else`, `export`, `extends`, `finally`, `for`, `from` (in module declarations), `function`, `get` (of getters), `if`, `import`, `in`, `instanceof`, `let`, `new`, `of` (in for-of statements), `return`, `set` (of setters), `static`, `super`, `switch`, `this`, `throw`, `try`, `typeof`, `var`, `void`, `while`, `with`, and `yield`. This rule is designed carefully not to conflict with other spacing rules: it does not apply to spacing where other rules report problems.