From 7675375df988f4de5962fa8753f0df2e13309206 Mon Sep 17 00:00:00 2001 From: Jonas Arvidsson Date: Sat, 11 Jan 2014 16:08:57 +0100 Subject: [PATCH] Add rules about trailing commas. Can occur in literals and method definitions/calls. These rules were discussed in https://github.com/bbatsov/rubocop/issues/713 --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index 6722a0d48..2d879ba09 100644 --- a/README.md +++ b/README.md @@ -350,6 +350,24 @@ Translations of the guide are available in the following languages: end ``` +* Avoid comma after the last parameter in a method definition or call, + especially when the parameters are not on separate lines. + + ```Ruby + # bad - easier to move/add/remove parameters, but still not preferred + def some_method( + size, + count, + color, + ) + + # bad + def some_method(size, count, color, ) + + # good + def some_method(size, count, color) + ``` + * Use spaces around the `=` operator when assigning default values to method parameters: ```Ruby @@ -2104,6 +2122,24 @@ this rule only to arrays with two or more elements. STATES = %i(draft open closed) ``` +* Avoid comma after the last item of an `Array` or `Hash` literal, especially + when the items are not on separate lines. + + ```Ruby + # bad - easier to move/add/remove items, but still not preferred + VALUES = [ + 1001, + 2020, + 3333, + ] + + # bad + VALUES = [1001, 2020, 3333, ] + + # good + VALUES = [1001, 2020, 3333] + ``` + * Avoid the creation of huge gaps in arrays. ```Ruby