Skip to content

Commit

Permalink
Docs: clarify that space-unary-ops doesn't apply when space is requir…
Browse files Browse the repository at this point in the history
…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 1faeb84
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 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 @@ -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;
Expand Down

0 comments on commit 1faeb84

Please sign in to comment.