Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gem "activesupport", require: false
gem "mry", require: false
gem "parser"
gem "pry", require: false
gem "rubocop", "0.78.0", require: false
gem "rubocop", "0.79.0", require: false
gem "rubocop-i18n", require: false
gem "rubocop-migrations", require: false
gem "rubocop-minitest", require: false
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.0)
rubocop (0.78.0)
rubocop (0.79.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.6)
parser (>= 2.7.0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
Expand Down Expand Up @@ -81,7 +81,7 @@ DEPENDENCIES
pry
rake
rspec
rubocop (= 0.78.0)
rubocop (= 0.79.0)
rubocop-i18n
rubocop-migrations
rubocop-minitest
Expand Down
140 changes: 140 additions & 0 deletions config/contents/style/method_call_with_args_parentheses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
This cop enforces the presence (default) or absence of parentheses in
method calls containing parameters.

In the default style (require_parentheses), macro methods are ignored.
Additional methods can be added to the `IgnoredMethods`
or `IgnoredPatterns` list. These options are
valid only in the default style. Macros can be included by
either setting `IgnoreMacros` to false or adding specific macros to
the `IncludedMacros` list.

Precedence of options is all follows:

1. `IgnoredMethods`
2. `IgnoredPatterns`
3. `IncludedMacros`

eg. If a method is listed in both
`IncludedMacros` and `IgnoredMethods`, then the latter takes
precedence (that is, the method is ignored).

In the alternative style (omit_parentheses), there are three additional
options.

1. `AllowParenthesesInChaining` is `false` by default. Setting it to
`true` allows the presence of parentheses in the last call during
method chaining.

2. `AllowParenthesesInMultilineCall` is `false` by default. Setting it
to `true` allows the presence of parentheses in multi-line method
calls.

3. `AllowParenthesesInCamelCaseMethod` is `false` by default. This
allows the presence of parentheses when calling a method whose name
begins with a capital letter and which has no arguments. Setting it
to `true` allows the presence of parentheses in such a method call
even with arguments.

### Example: EnforcedStyle: require_parentheses (default)

# bad
array.delete e

# good
array.delete(e)

# good
# Operators don't need parens
foo == bar

# good
# Setter methods don't need parens
foo.bar = baz

# okay with `puts` listed in `IgnoredMethods`
puts 'test'

# okay with `^assert` listed in `IgnoredPatterns`
assert_equal 'test', x

### Example: EnforcedStyle: omit_parentheses

# bad
array.delete(e)

# good
array.delete e

# bad
foo.enforce(strict: true)

# good
foo.enforce strict: true

### Example: IgnoreMacros: true (default)

# good
class Foo
bar :baz
end

### Example: IgnoreMacros: false

# bad
class Foo
bar :baz
end

### Example: AllowParenthesesInMultilineCall: false (default)

# bad
foo.enforce(
strict: true
)

# good
foo.enforce \
strict: true

### Example: AllowParenthesesInMultilineCall: true

# good
foo.enforce(
strict: true
)

# good
foo.enforce \
strict: true

### Example: AllowParenthesesInChaining: false (default)

# bad
foo().bar(1)

# good
foo().bar 1

### Example: AllowParenthesesInChaining: true

# good
foo().bar(1)

# good
foo().bar 1

### Example: AllowParenthesesInCamelCaseMethod: false (default)

# bad
Array(1)

# good
Array 1

### Example: AllowParenthesesInCamelCaseMethod: true

# good
Array(1)

# good
Array 1
1 change: 0 additions & 1 deletion spec/support/currently_undocumented_cops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ RuboCop::Cop::Metrics::LineLength
RuboCop::Cop::Migration::DepartmentName
RuboCop::Cop::Style::ConditionalAssignment
RuboCop::Cop::Style::DoubleCopDisableDirective
RuboCop::Cop::Style::MethodCallWithArgsParentheses