Skip to content
Permalink
Browse files

Docs: clarify that space-unary-ops doesn't apply when space is requir…

…ed (#13767)

* Docs: clarify space-unary-ops doesn't apply when space is required

* Remove incorrect trailing space

* Remove ReferenceError examples to avoid confusion
  • Loading branch information
tmdesigned committed Oct 19, 2020
1 parent 67c0605 commit 1faeb84e663d88c5d85a3cb3f15cd224cc552c2d
Showing with 10 additions and 5 deletions.
  1. +10 −5 docs/rules/space-unary-ops.md
@@ -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
@@ -103,14 +105,17 @@ 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);
// Unary operator "++" is not followed by whitespace.
++foo;

0 comments on commit 1faeb84

Please sign in to comment.
You can’t perform that action at this time.