From 53b30c99d527f5f7a8a5fdec5fa1dcd9cca37d0c Mon Sep 17 00:00:00 2001 From: Tyler Porter Date: Tue, 14 Jan 2020 19:59:10 -0500 Subject: [PATCH 1/4] Add style guide fr useless block arg commas --- README.adoc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.adoc b/README.adoc index bad270a7a..47baaa074 100644 --- a/README.adoc +++ b/README.adoc @@ -2194,6 +2194,32 @@ with_tmp_dir do |dir| end ---- +=== No Trailing Argument Comma [[no-trailing-argument-comma]] + +Avoid comma after the last argument in a block, except in cases where only a single argument is present and its removal would affect functionality. + +[source,ruby] +---- +# bad - easier to move/add/remove parameters, but still not preferred +[[1, 2, 3], [4, 5, 6]].each do |a, b, c,| + a + b + c +end + +# good +[[1, 2, 3], [4, 5, 6]].each do |a, b, c| + a + b + c +end + +# bad +[[1, 2, 3], [4, 5, 6]].each do { |a, b, c| a + b + c } + +# good +[[1, 2, 3], [4, 5, 6]].each do { |a, b, c| a + b + c } + +# good - removing the comma here would give a different output +[[1, 2, 3], [4, 5, 6]].map do { |a,| a } +---- + === No Nested Methods [[no-nested-methods]] From 1e3162aa4dfdb429cb1cc603b64f7ea0ff8d31a3 Mon Sep 17 00:00:00 2001 From: Tyler Porter Date: Tue, 14 Jan 2020 20:04:25 -0500 Subject: [PATCH 2/4] Fix typo in curly brace format block examples --- README.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.adoc b/README.adoc index 47baaa074..866f408a2 100644 --- a/README.adoc +++ b/README.adoc @@ -2211,13 +2211,13 @@ end end # bad -[[1, 2, 3], [4, 5, 6]].each do { |a, b, c| a + b + c } +[[1, 2, 3], [4, 5, 6]].each { |a, b, c| a + b + c } # good -[[1, 2, 3], [4, 5, 6]].each do { |a, b, c| a + b + c } +[[1, 2, 3], [4, 5, 6]].each { |a, b, c| a + b + c } # good - removing the comma here would give a different output -[[1, 2, 3], [4, 5, 6]].map do { |a,| a } +[[1, 2, 3], [4, 5, 6]].map { |a,| a } ---- From c92033717503d8d5f9c0ce13b73f242562133131 Mon Sep 17 00:00:00 2001 From: Tyler Porter <46663285+pawptart@users.noreply.github.com> Date: Wed, 15 Jan 2020 09:35:18 -0500 Subject: [PATCH 3/4] Reference array destructuring for single comma --- README.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index 866f408a2..2eeab7019 100644 --- a/README.adoc +++ b/README.adoc @@ -2196,7 +2196,7 @@ end === No Trailing Argument Comma [[no-trailing-argument-comma]] -Avoid comma after the last argument in a block, except in cases where only a single argument is present and its removal would affect functionality. +Avoid comma after the last argument in a block, except in cases where only a single argument is present and its removal would affect functionality (for instance, array destructuring). [source,ruby] ---- @@ -2216,7 +2216,7 @@ end # good [[1, 2, 3], [4, 5, 6]].each { |a, b, c| a + b + c } -# good - removing the comma here would give a different output +# good - this comma is meaningful for array destructuring [[1, 2, 3], [4, 5, 6]].map { |a,| a } ---- From b8441a9ce5a8c2a19d46a2a1094008b45dee3e68 Mon Sep 17 00:00:00 2001 From: Tyler Porter <46663285+pawptart@users.noreply.github.com> Date: Wed, 15 Jan 2020 11:05:29 -0500 Subject: [PATCH 4/4] Fix typo in bad example for curly braces --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 2eeab7019..fbd2d5998 100644 --- a/README.adoc +++ b/README.adoc @@ -2211,7 +2211,7 @@ end end # bad -[[1, 2, 3], [4, 5, 6]].each { |a, b, c| a + b + c } +[[1, 2, 3], [4, 5, 6]].each { |a, b, c,| a + b + c } # good [[1, 2, 3], [4, 5, 6]].each { |a, b, c| a + b + c }