diff --git a/lib/rubocop/cop/lint/ambiguous_block_association.rb b/lib/rubocop/cop/lint/ambiguous_block_association.rb index ff2a97ce5db..30d12f184eb 100644 --- a/lib/rubocop/cop/lint/ambiguous_block_association.rb +++ b/lib/rubocop/cop/lint/ambiguous_block_association.rb @@ -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 # @@ -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 diff --git a/lib/rubocop/cop/lint/number_conversion.rb b/lib/rubocop/cop/lint/number_conversion.rb index 2e33d750385..59a068de5ac 100644 --- a/lib/rubocop/cop/lint/number_conversion.rb +++ b/lib/rubocop/cop/lint/number_conversion.rb @@ -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 @@ -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 diff --git a/lib/rubocop/cop/metrics/block_length.rb b/lib/rubocop/cop/metrics/block_length.rb index ab2e6499985..9ae7239e7ae 100644 --- a/lib/rubocop/cop/metrics/block_length.rb +++ b/lib/rubocop/cop/metrics/block_length.rb @@ -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'] # diff --git a/lib/rubocop/cop/metrics/method_length.rb b/lib/rubocop/cop/metrics/method_length.rb index 06ae6255bbe..205d2c24fd0 100644 --- a/lib/rubocop/cop/metrics/method_length.rb +++ b/lib/rubocop/cop/metrics/method_length.rb @@ -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'] # diff --git a/lib/rubocop/cop/style/class_equality_comparison.rb b/lib/rubocop/cop/style/class_equality_comparison.rb index 1a81e53ca67..6adfa0d70f8 100644 --- a/lib/rubocop/cop/style/class_equality_comparison.rb +++ b/lib/rubocop/cop/style/class_equality_comparison.rb @@ -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 @@ -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 diff --git a/lib/rubocop/cop/style/format_string_token.rb b/lib/rubocop/cop/style/format_string_token.rb index 62231058f3b..522f7f42329 100644 --- a/lib/rubocop/cop/style/format_string_token.rb +++ b/lib/rubocop/cop/style/format_string_token.rb @@ -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) # @@ -61,6 +62,11 @@ module Style # # good # format('%06d', 10) # + # @example IgnoredMethods: [] (default) + # + # # bad + # redirect('foo/%{bar_id}') + # # @example IgnoredMethods: [redirect] # # # good diff --git a/lib/rubocop/cop/style/method_call_without_args_parentheses.rb b/lib/rubocop/cop/style/method_call_without_args_parentheses.rb index 2c3bce22d58..d176baa990b 100644 --- a/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +++ b/lib/rubocop/cop/style/method_call_without_args_parentheses.rb @@ -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 diff --git a/lib/rubocop/cop/style/numeric_predicate.rb b/lib/rubocop/cop/style/numeric_predicate.rb index 30cdc03b2c0..a71b72c1735 100644 --- a/lib/rubocop/cop/style/numeric_predicate.rb +++ b/lib/rubocop/cop/style/numeric_predicate.rb @@ -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. # @@ -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 diff --git a/lib/rubocop/cop/style/symbol_proc.rb b/lib/rubocop/cop/style/symbol_proc.rb index dede2985255..5bd2f3a9ce0 100644 --- a/lib/rubocop/cop/style/symbol_proc.rb +++ b/lib/rubocop/cop/style/symbol_proc.rb @@ -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 @@ -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