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

Docs: clarify that space-unary-ops doesn't apply when space is required #13767

Merged
merged 3 commits into from Oct 19, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions docs/rules/space-unary-ops.md
Expand Up @@ -6,6 +6,8 @@ Some style guides require or disallow spaces before or after unary operators. Th

This rule enforces consistency regarding the spaces after `words` unary operators and after/before `nonwords` unary operators.

For `words` operators, this rule only applies when a space is not syntactically required. For instance, `delete obj.foo` requires the space and will not be considered by this rule. The equivalent `delete(obj.foo)` has an optional space (`delete (obj.foo)`), therefore this rule will apply to it.

Examples of unary `words` operators:

```js
Expand Down Expand Up @@ -72,6 +74,9 @@ new[foo][0];

delete(foo.bar);

// ReferenceError: "deletefoo" is not defined (space is required here for correct syntax)
deletefoo.bar;

tmdesigned marked this conversation as resolved.
Show resolved Hide resolved
++ foo;

foo --;
Expand Down Expand Up @@ -103,14 +108,20 @@ Examples of **correct** code for this rule with the `{"words": true, "nonwords":
```js
/*eslint space-unary-ops: "error"*/

// Word unary operator "delete" is followed by a whitespace.
delete foo.bar;
// Word unary operator "typeof" is followed by a whitespace.
typeof !foo;

// Word unary operator "void" is followed by a whitespace.
void {foo:0};

// Word unary operator "new" is followed by a whitespace.
new Foo;
new [foo][0];

// Word unary operator "void" is followed by a whitespace.
void 0;
// Word unary operator "delete" is followed by a whitespace.
delete (foo.bar);

// Word unary operator "delete" is followed by a whitespace.
delete foo.bar;

// Unary operator "++" is not followed by whitespace.
++foo;
Expand Down