Skip to content

Commit

Permalink
Enhanced documentation for "IgnoredMethods" option
Browse files Browse the repository at this point in the history
This PR is documentation was added according to the following policy
for "IgnoredMethods" option

- Add code examples for cop that don't have code examples
- Add default values for cop that don't have default values

The code example also clearly shows the difference in behavior from
the default when the default for "IgnoredMethods" is an empty array.
  • Loading branch information
ydah authored and bbatsov committed Jul 13, 2022
1 parent a206fcd commit 9808e96
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 7 deletions.
7 changes: 7 additions & 0 deletions lib/rubocop/cop/lint/ambiguous_block_association.rb
Expand Up @@ -7,6 +7,7 @@ module Lint
# when param passed without parentheses.
#
# This cop can customize ignored methods with `IgnoredMethods`.
# By default, there are no methods to ignored.
#
# @example
#
Expand All @@ -29,10 +30,16 @@ module Lint
# # Lambda arguments require no disambiguation
# foo = ->(bar) { bar.baz }
#
# @example IgnoredMethods: [] (default)
#
# # bad
# expect { do_something }.to change { object.attribute }
#
# @example IgnoredMethods: [change]
#
# # good
# expect { do_something }.to change { object.attribute }
#
class AmbiguousBlockAssociation < Base
include IgnoredMethods

Expand Down
8 changes: 7 additions & 1 deletion lib/rubocop/cop/lint/number_conversion.rb
Expand Up @@ -16,7 +16,8 @@ module Lint
# NOTE: Some values cannot be converted properly using one of the `Kernel`
# method (for instance, `Time` and `DateTime` values are allowed by this
# cop by default). Similarly, Rails' duration methods do not work well
# with `Integer()` and can be ignored with `IgnoredMethods`.
# with `Integer()` and can be ignored with `IgnoredMethods`. By default,
# there are no methods to ignored.
#
# @safety
# Autocorrection is unsafe because it is not guaranteed that the
Expand Down Expand Up @@ -45,6 +46,11 @@ module Lint
# foo.try { |i| Float(i) }
# bar.send { |i| Complex(i) }
#
# @example IgnoredMethods: [] (default)
#
# # bad
# 10.minutes.to_i
#
# @example IgnoredMethods: [minutes]
#
# # good
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/metrics/block_length.rb
Expand Up @@ -15,6 +15,7 @@ module Metrics
#
# NOTE: The `ExcludedMethods` configuration is deprecated and only kept
# for backwards compatibility. Please use `IgnoredMethods` instead.
# By default, there are no methods to ignored.
#
# @example CountAsOne: ['array', 'heredoc']
#
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/metrics/method_length.rb
Expand Up @@ -13,6 +13,7 @@ module Metrics
#
# NOTE: The `ExcludedMethods` configuration is deprecated and only kept
# for backwards compatibility. Please use `IgnoredMethods` instead.
# By default, there are no methods to ignored.
#
# @example CountAsOne: ['array', 'heredoc']
#
Expand Down
22 changes: 22 additions & 0 deletions lib/rubocop/cop/style/class_equality_comparison.rb
Expand Up @@ -5,6 +5,8 @@ module Cop
module Style
# Enforces the use of `Object#instance_of?` instead of class comparison
# for equality.
# `==`, `equal?`, and `eql?` methods are ignored by default.
# These are customizable with `IgnoredMethods` option.
#
# @example
# # bad
Expand All @@ -16,6 +18,26 @@ module Style
# # good
# var.instance_of?(Date)
#
# @example IgnoreMethods: [] (default)
# # good
# var.instance_of?(Date)
#
# # bad
# var.class == Date
# var.class.equal?(Date)
# var.class.eql?(Date)
# var.class.name == 'Date'
#
# @example IgnoreMethods: [`==`]
# # good
# var.instance_of?(Date)
# var.class == Date
# var.class.name == 'Date'
#
# # bad
# var.class.equal?(Date)
# var.class.eql?(Date)
#
class ClassEqualityComparison < Base
include RangeHelp
include IgnoredMethods
Expand Down
6 changes: 6 additions & 0 deletions lib/rubocop/cop/style/format_string_token.rb
Expand Up @@ -12,6 +12,7 @@ module Style
# to encoded URLs or Date/Time formatting strings.
#
# This cop can be customized ignored methods with `IgnoredMethods`.
# By default, there are no methods to ignored.
#
# @example EnforcedStyle: annotated (default)
#
Expand Down Expand Up @@ -61,6 +62,11 @@ module Style
# # good
# format('%06d', 10)
#
# @example IgnoredMethods: [] (default)
#
# # bad
# redirect('foo/%{bar_id}')
#
# @example IgnoredMethods: [redirect]
#
# # good
Expand Down
12 changes: 12 additions & 0 deletions lib/rubocop/cop/style/method_call_without_args_parentheses.rb
Expand Up @@ -5,12 +5,24 @@ module Cop
module Style
# Checks for unwanted parentheses in parameterless method calls.
#
# This cop can be customized ignored methods with `IgnoredMethods`.
# By default, there are no methods to ignored.
#
# @example
# # bad
# object.some_method()
#
# # good
# object.some_method
#
# @example IgnoredMethods: [] (default)
# # bad
# object.foo()
#
# @example IgnoredMethods: [foo]
# # good
# object.foo()
#
class MethodCallWithoutArgsParentheses < Base
include IgnoredMethods
extend AutoCorrector
Expand Down
26 changes: 20 additions & 6 deletions lib/rubocop/cop/style/numeric_predicate.rb
Expand Up @@ -6,13 +6,16 @@ module Style
# Checks for usage of comparison operators (`==`,
# `>`, `<`) to test numbers as zero, positive, or negative.
# These can be replaced by their respective predicate methods.
# The cop can also be configured to do the reverse.
# This cop can also be configured to do the reverse.
#
# The cop disregards `#nonzero?` as its value is truthy or falsey,
# This cop can be customized ignored methods with `IgnoredMethods`.
# By default, there are no methods to ignored.
#
# This cop disregards `#nonzero?` as its value is truthy or falsey,
# but not `true` and `false`, and thus not always interchangeable with
# `!= 0`.
#
# The cop ignores comparisons to global variables, since they are often
# This cop ignores comparisons to global variables, since they are often
# populated with objects which can be compared with integers, but are
# not themselves `Integer` polymorphic.
#
Expand All @@ -23,29 +26,40 @@ module Style
#
# @example EnforcedStyle: predicate (default)
# # bad
#
# foo == 0
# 0 > foo
# bar.baz > 0
#
# # good
#
# foo.zero?
# foo.negative?
# bar.baz.positive?
#
# @example EnforcedStyle: comparison
# # bad
#
# foo.zero?
# foo.negative?
# bar.baz.positive?
#
# # good
# foo == 0
# 0 > foo
# bar.baz > 0
#
# @example IgnoredMethods: [] (default) with EnforcedStyle: predicate
# # bad
# foo == 0
# 0 > foo
# bar.baz > 0
#
# @example IgnoredMethods: [==] with EnforcedStyle: predicate
# # good
# foo == 0
#
# # bad
# 0 > foo
# bar.baz > 0
#
class NumericPredicate < Base
include ConfigurableEnforcedStyle
include IgnoredMethods
Expand Down
8 changes: 8 additions & 0 deletions lib/rubocop/cop/style/symbol_proc.rb
Expand Up @@ -7,6 +7,8 @@ module Style
#
# If you prefer a style that allows block for method with arguments,
# please set `true` to `AllowMethodsWithArguments`.
# respond_to , and `define_method?` methods are ignored by default.
# These are customizable with `IgnoredMethods` option.
#
# @safety
# This cop is unsafe because `proc`s and blocks work differently
Expand Down Expand Up @@ -68,6 +70,12 @@ module Style
# s.upcase # some comment
# # some comment
# end
#
# @example IgnoredMethods: [respond_to, define_method] (default)
# # good
# respond_to { |foo| foo.bar }
# define_method(:foo) { |foo| foo.bar }
#
class SymbolProc < Base
include CommentsHelp
include RangeHelp
Expand Down

0 comments on commit 9808e96

Please sign in to comment.