From b037f6dfc1083f17bdb457d5f12de0d0f315b466 Mon Sep 17 00:00:00 2001 From: Taylor Morgan Date: Sat, 17 Oct 2020 07:02:18 -0400 Subject: [PATCH 1/3] Docs: clarify space-unary-ops doesn't apply when space is required --- docs/rules/space-unary-ops.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/rules/space-unary-ops.md b/docs/rules/space-unary-ops.md index d04bd4a4561..4486fd4a32f 100644 --- a/docs/rules/space-unary-ops.md +++ b/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 @@ -72,6 +74,9 @@ new[foo][0]; delete(foo.bar); +// ReferenceError: "deletefoo" is not defined (space is required here for correct syntax) +deletefoo.bar; + ++ foo; foo --; @@ -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; From c401f5bae0580b48d9ea20ddfacf655d796089a0 Mon Sep 17 00:00:00 2001 From: Taylor Morgan Date: Sat, 17 Oct 2020 07:09:02 -0400 Subject: [PATCH 2/3] Remove incorrect trailing space --- docs/rules/space-unary-ops.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/space-unary-ops.md b/docs/rules/space-unary-ops.md index 4486fd4a32f..5df44997914 100644 --- a/docs/rules/space-unary-ops.md +++ b/docs/rules/space-unary-ops.md @@ -75,7 +75,7 @@ new[foo][0]; delete(foo.bar); // ReferenceError: "deletefoo" is not defined (space is required here for correct syntax) -deletefoo.bar; +deletefoo.bar; ++ foo; From 49f19561a7ddbbbe29c43ae5e4d83275c529e6d0 Mon Sep 17 00:00:00 2001 From: Taylor Morgan Date: Mon, 19 Oct 2020 08:49:02 -0400 Subject: [PATCH 3/3] Remove ReferenceError examples to avoid confusion --- docs/rules/space-unary-ops.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/rules/space-unary-ops.md b/docs/rules/space-unary-ops.md index 5df44997914..676a921bf63 100644 --- a/docs/rules/space-unary-ops.md +++ b/docs/rules/space-unary-ops.md @@ -74,9 +74,6 @@ new[foo][0]; delete(foo.bar); -// ReferenceError: "deletefoo" is not defined (space is required here for correct syntax) -deletefoo.bar; - ++ foo; foo --; @@ -120,9 +117,6 @@ new [foo][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;