Skip to content

Commit

Permalink
Update uses of IgnoredPatterns to AllowedPatterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvandersluis authored and bbatsov committed Apr 20, 2022
1 parent 8ac5b59 commit e491166
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Layout/HashAlignment:

Layout/LineLength:
Max: 100
IgnoredPatterns:
AllowedPatterns:
- !ruby/regexp /\A +(it|describe|context|shared_examples|include_examples|it_behaves_like) ["']/

Lint/InterpolationCheck:
Expand Down
19 changes: 12 additions & 7 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,8 @@ Layout/IndentationWidth:
VersionAdded: '0.49'
# Number of spaces for each indentation level.
Width: 2
IgnoredPatterns: []
AllowedPatterns: []
IgnoredPatterns: [] # deprecated

Layout/InitialIndentation:
Description: >-
Expand Down Expand Up @@ -985,10 +986,11 @@ Layout/LineLength:
# The IgnoreCopDirectives option causes the LineLength rule to ignore cop
# directives like '# rubocop: enable ...' when calculating a line's length.
IgnoreCopDirectives: true
# The IgnoredPatterns option is a list of !ruby/regexp and/or string
# The AllowedPatterns option is a list of !ruby/regexp and/or string
# elements. Strings will be converted to Regexp objects. A line that matches
# any regular expression listed in this option will be ignored by LineLength.
IgnoredPatterns: []
AllowedPatterns: []
IgnoredPatterns: [] # deprecated

Layout/MultilineArrayBraceLayout:
Description: >-
Expand Down Expand Up @@ -2272,10 +2274,11 @@ Lint/UnreachableLoop:
Enabled: true
VersionAdded: '0.89'
VersionChanged: '1.7'
IgnoredPatterns:
AllowedPatterns:
# RSpec uses `times` in its message expectations
# eg. `exactly(2).times`
- !ruby/regexp /(exactly|at_least|at_most)\(\d+\)\.times/
IgnoredPatterns: [] # deprecated

Lint/UnusedBlockArgument:
Description: 'Checks for unused block arguments.'
Expand Down Expand Up @@ -2688,11 +2691,12 @@ Naming/MethodName:
- camelCase
# Method names matching patterns are always allowed.
#
# IgnoredPatterns:
# AllowedPatterns:
# - '\A\s*onSelectionBulkChange\s*'
# - '\A\s*onSelectionCleared\s*'
#
IgnoredPatterns: []
AllowedPatterns: []
IgnoredPatterns: [] # deprecated

Naming/MethodParameterName:
Description: >-
Expand Down Expand Up @@ -3920,7 +3924,8 @@ Style/MethodCallWithArgsParentheses:
VersionChanged: '1.7'
IgnoreMacros: true
IgnoredMethods: []
IgnoredPatterns: []
AllowedPatterns: []
IgnoredPatterns: [] # deprecated
IncludedMacros: []
AllowParenthesesInMultilineCall: false
AllowParenthesesInChaining: false
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/layout/indentation_width.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Layout
# end
# end
#
# @example IgnoredPatterns: ['^\s*module']
# @example AllowedPatterns: ['^\s*module']
# # bad
# module A
# class B
Expand All @@ -46,7 +46,7 @@ class IndentationWidth < Base # rubocop:disable Metrics/ClassLength
include EndKeywordAlignment
include Alignment
include CheckAssignment
include IgnoredPattern
include AllowedPattern
include RangeHelp
extend AutoCorrector

Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/cop/layout/line_length.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module Layout
# }
class LineLength < Base
include CheckLineBreakable
include IgnoredPattern
include AllowedPattern
include RangeHelp
include LineLengthHelp
extend AutoCorrector
Expand Down Expand Up @@ -163,7 +163,7 @@ def highlight_start(line)

def check_line(line, line_index)
return if line_length(line) <= max
return if ignored_line?(line, line_index)
return if allowed_line?(line, line_index)

if ignore_cop_directives? && directive_on_source_line?(line_index)
return check_directive_line(line, line_index)
Expand All @@ -173,8 +173,8 @@ def check_line(line, line_index)
register_offense(excess_range(nil, line, line_index), line, line_index)
end

def ignored_line?(line, line_index)
matches_ignored_pattern?(line) ||
def allowed_line?(line, line_index)
matches_allowed_pattern?(line) ||
shebang?(line, line_index) ||
(heredocs && line_in_permitted_heredoc?(line_index.succ))
end
Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/cop/lint/unreachable_loop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Lint
#
# NOTE: Block methods that are used with `Enumerable`s are considered to be loops.
#
# `IgnoredPatterns` can be used to match against the block receiver in order to allow
# `AllowedPatterns` can be used to match against the block receiver in order to allow
# code that would otherwise be registered as an offense (eg. `times` used not in an
# `Enumerable` context).
#
Expand Down Expand Up @@ -79,12 +79,12 @@ module Lint
# # bad
# 2.times { raise ArgumentError }
#
# @example IgnoredPatterns: [/(exactly|at_least|at_most)\(\d+\)\.times/] (default)
# @example AllowedPatterns: [/(exactly|at_least|at_most)\(\d+\)\.times/] (default)
#
# # good
# exactly(2).times { raise StandardError }
class UnreachableLoop < Base
include IgnoredPattern
include AllowedPattern

MSG = 'This loop will have at most one iteration.'
CONTINUE_KEYWORDS = %i[next redo].freeze
Expand All @@ -107,7 +107,7 @@ def loop_method?(node)
return false unless node.block_type?

send_node = node.send_node
return false if matches_ignored_pattern?(send_node.source)
return false if matches_allowed_pattern?(send_node.source)

send_node.enumerable_method? || send_node.enumerator_method? || send_node.method?(:loop)
end
Expand Down
10 changes: 5 additions & 5 deletions lib/rubocop/cop/naming/method_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module Naming
# This cop makes sure that all methods use the configured style,
# snake_case or camelCase, for their names.
#
# This cop has `IgnoredPatterns` configuration option.
# This cop has `AllowedPatterns` configuration option.
#
# Naming/MethodName:
# IgnoredPatterns:
# AllowedPatterns:
# - '\A\s*onSelectionBulkChange\s*'
# - '\A\s*onSelectionCleared\s*'
#
Expand All @@ -30,7 +30,7 @@ module Naming
# def fooBar; end
class MethodName < Base
include ConfigurableNaming
include IgnoredPattern
include AllowedPattern
include RangeHelp

MSG = 'Use %<style>s for method names.'
Expand All @@ -46,14 +46,14 @@ def on_send(node)

attrs.last.each do |name_item|
name = attr_name(name_item)
next if !name || matches_ignored_pattern?(name)
next if !name || matches_allowed_pattern?(name)

check_name(node, name, range_position(node))
end
end

def on_def(node)
return if node.operator_method? || matches_ignored_pattern?(node.method_name)
return if node.operator_method? || matches_allowed_pattern?(node.method_name)

check_name(node, node.method_name, node.loc.name)
end
Expand Down
9 changes: 5 additions & 4 deletions lib/rubocop/cop/style/if_unless_modifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Style
class IfUnlessModifier < Base
include StatementModifier
include LineLengthHelp
include IgnoredPattern
include AllowedPattern
include RangeHelp
extend AutoCorrector

Expand Down Expand Up @@ -87,8 +87,9 @@ def too_long_due_to_modifier?(node)
!another_statement_on_same_line?(node)
end

def ignored_patterns
config.for_cop('Layout/LineLength')['IgnoredPatterns'] || []
def allowed_patterns
line_length_config = config.for_cop('Layout/LineLength')
line_length_config['AllowedPatterns'] || line_length_config['IgnoredPatterns'] || []
end

def too_long_single_line?(node)
Expand All @@ -105,7 +106,7 @@ def too_long_single_line?(node)
end

def too_long_line_based_on_config?(range, line)
return false if matches_ignored_pattern?(line)
return false if matches_allowed_pattern?(line)

too_long = too_long_line_based_on_ignore_cop_directives?(range, line)
return too_long unless too_long == :undetermined
Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/cop/style/method_call_with_args_parentheses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ module Style
#
# In the default style (require_parentheses), macro methods are ignored.
# Additional methods can be added to the `IgnoredMethods`
# or `IgnoredPatterns` list. These options are
# or `AllowedPatterns` 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`
# 2. `AllowedPatterns`
# 3. `IncludedMacros`
#
# eg. If a method is listed in both
Expand Down Expand Up @@ -68,7 +68,7 @@ module Style
# # okay with `puts` listed in `IgnoredMethods`
# puts 'test'
#
# # okay with `^assert` listed in `IgnoredPatterns`
# # okay with `^assert` listed in `AllowedPatterns`
# assert_equal 'test', x
#
# @example EnforcedStyle: omit_parentheses
Expand Down Expand Up @@ -198,7 +198,7 @@ class MethodCallWithArgsParentheses < Base

include ConfigurableEnforcedStyle
include IgnoredMethods
include IgnoredPattern
include AllowedPattern
include RequireParentheses
include OmitParentheses
extend AutoCorrector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module RequireParentheses

def require_parentheses(node)
return if ignored_method?(node.method_name)
return if matches_ignored_pattern?(node.method_name)
return if matches_allowed_pattern?(node.method_name)
return if eligible_for_parentheses_omission?(node)
return unless node.arguments? && !node.parenthesized?

Expand Down
16 changes: 8 additions & 8 deletions spec/rubocop/cli/auto_gen_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def f
# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 138
Expand Down Expand Up @@ -166,7 +166,7 @@ def f
# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 99
Expand Down Expand Up @@ -334,7 +334,7 @@ def f
'# This cop supports safe auto-correction (--auto-correct).',
'# Configuration parameters: AllowHeredoc, ' \
'AllowURI, URISchemes, IgnoreCopDirectives, ' \
'IgnoredPatterns.',
'AllowedPatterns, IgnoredPatterns.',
'# URISchemes: http, https',
'Layout/LineLength:',
' Max: 125'])
Expand Down Expand Up @@ -387,7 +387,7 @@ def f
'# This cop supports safe auto-correction (--auto-correct).',
'# Configuration parameters: AllowHeredoc, ' \
'AllowURI, URISchemes, IgnoreCopDirectives, ' \
'IgnoredPatterns.',
'AllowedPatterns, IgnoredPatterns.',
'# URISchemes: http, https',
'Layout/LineLength:',
' Max: 121',
Expand Down Expand Up @@ -449,7 +449,7 @@ def fooBar; end
todo_contents = File.read('.rubocop_todo.yml').lines[8..-1].join
expect(todo_contents).to eq(<<~YAML)
# Offense count: 1
# Configuration parameters: IgnoredPatterns.
# Configuration parameters: AllowedPatterns, IgnoredPatterns.
# SupportedStyles: snake_case, camelCase
Naming/MethodName:
EnforcedStyle: camelCase
Expand Down Expand Up @@ -730,7 +730,7 @@ def a; end
'# This cop supports safe auto-correction (--auto-correct).',
'# Configuration parameters: AllowHeredoc, ' \
'AllowURI, URISchemes, IgnoreCopDirectives, ' \
'IgnoredPatterns.',
'AllowedPatterns, IgnoredPatterns.',
'# URISchemes: http, https',
'Layout/LineLength:',
' Max: 130']
Expand Down Expand Up @@ -823,7 +823,7 @@ def a; end
'# This cop supports safe auto-correction (--auto-correct).',
'# Configuration parameters: AllowHeredoc, ' \
'AllowURI, URISchemes, IgnoreCopDirectives, ' \
'IgnoredPatterns.',
'AllowedPatterns, IgnoredPatterns.',
'# URISchemes: http, https',
'Layout/LineLength:',
' Max: 130']
Expand Down Expand Up @@ -1092,7 +1092,7 @@ def a; end
'# This cop supports safe auto-correction (--auto-correct).',
'# Configuration parameters: AllowHeredoc, ' \
'AllowURI, URISchemes, IgnoreCopDirectives, ' \
'IgnoredPatterns.',
'AllowedPatterns, IgnoredPatterns.',
'# URISchemes: http, https',
'Layout/LineLength:',
' Max: 130']
Expand Down
1 change: 1 addition & 0 deletions spec/rubocop/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,7 @@ def meow_at_4am?
| - AllowURI
| - URISchemes
| - IgnoreCopDirectives
| - AllowedPatterns
| - IgnoredPatterns
RESULT
end
Expand Down
2 changes: 2 additions & 0 deletions spec/rubocop/config_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ class Loop < Base
'AllowURI' => true,
'URISchemes' => %w[http https],
'IgnoreCopDirectives' => true,
'AllowedPatterns' => [],
'IgnoredPatterns' => []
},
'Metrics/MethodLength' => {
Expand Down Expand Up @@ -910,6 +911,7 @@ class Loop < Base
'AllowURI' => true,
'URISchemes' => %w[http https],
'IgnoreCopDirectives' => true,
'AllowedPatterns' => [],
'IgnoredPatterns' => []
}
)
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/layout/indentation_width_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def method
let(:cop_config) do
{
'Width' => 4,
'IgnoredPatterns' => ['^\s*module', '^\s*(els)?if.*[A-Z][a-z]+']
'AllowedPatterns' => ['^\s*module', '^\s*(els)?if.*[A-Z][a-z]+']
}
end

Expand Down
Loading

0 comments on commit e491166

Please sign in to comment.