rubocop 0.40.0 → 0.41.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -1014
  3. data/config/default.yml +61 -5
  4. data/config/disabled.yml +6 -0
  5. data/config/enabled.yml +63 -4
  6. data/lib/rubocop.rb +17 -1
  7. data/lib/rubocop/ast_node.rb +56 -42
  8. data/lib/rubocop/ast_node/traversal.rb +3 -3
  9. data/lib/rubocop/cli.rb +14 -9
  10. data/lib/rubocop/comment_config.rb +85 -32
  11. data/lib/rubocop/config.rb +29 -8
  12. data/lib/rubocop/config_loader.rb +1 -1
  13. data/lib/rubocop/cop/cop.rb +1 -1
  14. data/lib/rubocop/cop/corrector.rb +13 -0
  15. data/lib/rubocop/cop/lint/block_alignment.rb +25 -11
  16. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +5 -2
  17. data/lib/rubocop/cop/lint/inherit_exception.rb +69 -0
  18. data/lib/rubocop/cop/lint/percent_string_array.rb +60 -0
  19. data/lib/rubocop/cop/lint/percent_symbol_array.rb +57 -0
  20. data/lib/rubocop/cop/lint/shadowed_exception.rb +95 -0
  21. data/lib/rubocop/cop/lint/useless_access_modifier.rb +28 -13
  22. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +25 -19
  23. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +16 -8
  24. data/lib/rubocop/cop/mixin/if_node.rb +1 -2
  25. data/lib/rubocop/cop/mixin/integer_node.rb +13 -0
  26. data/lib/rubocop/cop/mixin/match_range.rb +26 -0
  27. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +16 -7
  28. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +18 -1
  29. data/lib/rubocop/cop/mixin/negative_conditional.rb +6 -4
  30. data/lib/rubocop/cop/mixin/percent_literal.rb +10 -0
  31. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +24 -6
  32. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +20 -7
  33. data/lib/rubocop/cop/mixin/string_literals_help.rb +2 -2
  34. data/lib/rubocop/cop/mixin/trailing_comma.rb +34 -20
  35. data/lib/rubocop/cop/performance/flat_map.rb +23 -10
  36. data/lib/rubocop/cop/performance/push_splat.rb +47 -0
  37. data/lib/rubocop/cop/performance/redundant_block_call.rb +24 -1
  38. data/lib/rubocop/cop/performance/redundant_merge.rb +3 -5
  39. data/lib/rubocop/cop/performance/sample.rb +15 -11
  40. data/lib/rubocop/cop/rails/exit.rb +62 -0
  41. data/lib/rubocop/cop/rails/output_safety.rb +45 -0
  42. data/lib/rubocop/cop/rails/pluralization_grammar.rb +12 -4
  43. data/lib/rubocop/cop/rails/request_referer.rb +40 -0
  44. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +63 -28
  45. data/lib/rubocop/cop/rails/validation.rb +37 -23
  46. data/lib/rubocop/cop/style/alias.rb +10 -6
  47. data/lib/rubocop/cop/style/bare_percent_literals.rb +18 -7
  48. data/lib/rubocop/cop/style/block_delimiters.rb +15 -22
  49. data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +19 -8
  50. data/lib/rubocop/cop/style/comment_indentation.rb +13 -5
  51. data/lib/rubocop/cop/style/conditional_assignment.rb +111 -59
  52. data/lib/rubocop/cop/style/documentation.rb +7 -1
  53. data/lib/rubocop/cop/style/each_for_simple_loop.rb +43 -0
  54. data/lib/rubocop/cop/style/each_with_object.rb +25 -14
  55. data/lib/rubocop/cop/style/empty_else.rb +6 -10
  56. data/lib/rubocop/cop/style/extra_spacing.rb +20 -3
  57. data/lib/rubocop/cop/style/file_name.rb +16 -4
  58. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  59. data/lib/rubocop/cop/style/hash_syntax.rb +9 -2
  60. data/lib/rubocop/cop/style/if_unless_modifier.rb +20 -13
  61. data/lib/rubocop/cop/style/implicit_runtime_error.rb +32 -0
  62. data/lib/rubocop/cop/style/infinite_loop.rb +42 -5
  63. data/lib/rubocop/cop/style/lambda.rb +22 -0
  64. data/lib/rubocop/cop/style/method_def_parentheses.rb +12 -4
  65. data/lib/rubocop/cop/style/module_function.rb +28 -6
  66. data/lib/rubocop/cop/style/multiline_method_call_indentation.rb +49 -12
  67. data/lib/rubocop/cop/style/mutable_constant.rb +8 -1
  68. data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
  69. data/lib/rubocop/cop/style/next.rb +43 -31
  70. data/lib/rubocop/cop/style/not.rb +33 -13
  71. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +92 -0
  72. data/lib/rubocop/cop/style/numeric_literals.rb +1 -4
  73. data/lib/rubocop/cop/style/parallel_assignment.rb +26 -8
  74. data/lib/rubocop/cop/style/{deprecated_hash_methods.rb → preferred_hash_methods.rb} +8 -8
  75. data/lib/rubocop/cop/style/redundant_parentheses.rb +29 -19
  76. data/lib/rubocop/cop/style/redundant_self.rb +13 -6
  77. data/lib/rubocop/cop/style/space_after_not.rb +7 -5
  78. data/lib/rubocop/cop/style/space_around_keyword.rb +6 -0
  79. data/lib/rubocop/cop/style/space_around_operators.rb +5 -1
  80. data/lib/rubocop/cop/style/space_before_first_arg.rb +21 -9
  81. data/lib/rubocop/cop/style/space_inside_array_percent_literal.rb +53 -0
  82. data/lib/rubocop/cop/style/space_inside_block_braces.rb +2 -2
  83. data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +26 -6
  84. data/lib/rubocop/cop/style/space_inside_percent_literal_delimiters.rb +64 -0
  85. data/lib/rubocop/cop/style/string_literals.rb +37 -8
  86. data/lib/rubocop/cop/style/symbol_array.rb +21 -12
  87. data/lib/rubocop/cop/style/symbol_proc.rb +26 -19
  88. data/lib/rubocop/cop/style/word_array.rb +1 -5
  89. data/lib/rubocop/cop/style/zero_length_predicate.rb +6 -6
  90. data/lib/rubocop/cop/team.rb +40 -27
  91. data/lib/rubocop/cop/util.rb +13 -42
  92. data/lib/rubocop/formatter/disabled_config_formatter.rb +37 -14
  93. data/lib/rubocop/formatter/html_formatter.rb +3 -7
  94. data/lib/rubocop/result_cache.rb +18 -4
  95. data/{spec/support → lib/rubocop/rspec}/cop_helper.rb +3 -0
  96. data/lib/rubocop/rspec/host_environment_simulation_helper.rb +33 -0
  97. data/lib/rubocop/rspec/shared_contexts.rb +75 -0
  98. data/lib/rubocop/rspec/shared_examples.rb +101 -0
  99. data/lib/rubocop/rspec/support.rb +9 -0
  100. data/lib/rubocop/runner.rb +2 -2
  101. data/lib/rubocop/string_interpreter.rb +58 -0
  102. data/lib/rubocop/version.rb +1 -1
  103. metadata +27 -7
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module RuboCop
5
+ module Cop
6
+ module Rails
7
+ # This cop enforces that 'exit' calls are not used within a rails app.
8
+ # Valid options are instead to raise an error, break, return or some
9
+ # other form of stopping execution of current request.
10
+ #
11
+ # There are two obvious cases where 'exit' is particularly harmful:
12
+ #
13
+ # - Usage in library code for your application. Even though rails will
14
+ # rescue from a SystemExit and continue on, unit testing that library
15
+ # code will result in specs exiting (potentially silently if exit(0)
16
+ # is used.)
17
+ # - Usage in application code outside of the web process could result in
18
+ # the program exiting, which could result in the code failing to run and
19
+ # do its job.
20
+ class Exit < Cop
21
+ include ConfigurableEnforcedStyle
22
+
23
+ MSG = 'Do not use `exit` in Rails applications.'.freeze
24
+ TARGET_METHODS = [:exit, :exit!].freeze
25
+ EXPLICIT_RECEIVERS = [:Kernel, :Process].freeze
26
+
27
+ def on_send(node)
28
+ add_offense(node, :selector) if offending_node?(node)
29
+ end
30
+
31
+ private
32
+
33
+ def offending_node?(node)
34
+ receiver_node, method_name, *arg_nodes = *node
35
+
36
+ right_method_name?(method_name) &&
37
+ right_argument_count?(arg_nodes) &&
38
+ right_receiver?(receiver_node)
39
+ end
40
+
41
+ def right_method_name?(method_name)
42
+ TARGET_METHODS.include?(method_name)
43
+ end
44
+
45
+ # More than 1 argument likely means it is a different
46
+ # `exit` implementation than the one we are preventing.
47
+ def right_argument_count?(arg_nodes)
48
+ arg_nodes.length <= 1
49
+ end
50
+
51
+ # Only register if exit is being called explicitly on
52
+ # Kernel or Process or if receiver node is nil for plain
53
+ # `exit` calls.
54
+ def right_receiver?(receiver_node)
55
+ return true if receiver_node.nil?
56
+ _a, receiver_node_class, _c = *receiver_node
57
+ EXPLICIT_RECEIVERS.include?(receiver_node_class)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module RuboCop
5
+ module Cop
6
+ module Rails
7
+ # This cop checks for the use of output safety calls like html_safe and
8
+ # raw.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # "<p>#{text}</p>".html_safe
13
+ #
14
+ # # good
15
+ # content_tag(:p, text)
16
+ #
17
+ # # bad
18
+ # out = ""
19
+ # out << content_tag(:li, "one")
20
+ # out << content_tag(:li, "two")
21
+ # out.html_safe
22
+ #
23
+ # # good
24
+ # out = []
25
+ # out << content_tag(:li, "one")
26
+ # out << content_tag(:li, "two")
27
+ # safe_join(out)
28
+ #
29
+ class OutputSafety < Cop
30
+ MSG = 'Tagging a string as html safe may be a security risk, \
31
+ prefer `safe_join` or other Rails tag helpers instead'.freeze
32
+
33
+ def on_send(node)
34
+ receiver, method_name, *_args = *node
35
+
36
+ if receiver && method_name == :html_safe
37
+ add_offense(node, :selector)
38
+ elsif receiver.nil? && method_name == :raw
39
+ add_offense(node, :selector)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -31,15 +31,15 @@ module RuboCop
31
31
 
32
32
  def on_send(node)
33
33
  receiver, method_name, *_args = *node
34
- return if receiver.nil?
35
34
  return unless duration_method?(method_name)
36
35
  return unless literal_number?(receiver)
36
+
37
37
  number, = *receiver
38
- if singular_receiver?(number) && plural_method?(method_name)
38
+ if expect_singular_method?(number, method_name)
39
39
  add_offense(node,
40
40
  :expression,
41
41
  format(MSG, number, singularize(method_name)))
42
- elsif plural_receiver?(number) && singular_method?(method_name)
42
+ elsif expect_plural_method?(number, method_name)
43
43
  add_offense(node,
44
44
  :expression,
45
45
  format(MSG, number, pluralize(method_name)))
@@ -60,6 +60,14 @@ module RuboCop
60
60
  end
61
61
  end
62
62
 
63
+ def expect_singular_method?(number, method_name)
64
+ singular_receiver?(number) && plural_method?(method_name)
65
+ end
66
+
67
+ def expect_plural_method?(number, method_name)
68
+ plural_receiver?(number) && singular_method?(method_name)
69
+ end
70
+
63
71
  def plural_method?(method_name)
64
72
  method_name.to_s.end_with?('s')
65
73
  end
@@ -77,7 +85,7 @@ module RuboCop
77
85
  end
78
86
 
79
87
  def literal_number?(node)
80
- node.int_type? || node.float_type?
88
+ node && (node.int_type? || node.float_type?)
81
89
  end
82
90
 
83
91
  def pluralize(method_name)
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module RuboCop
5
+ module Cop
6
+ module Rails
7
+ # This cop checks for consistent uses of request.referrer or
8
+ # request.referrer, depending on configuration.
9
+ class RequestReferer < Cop
10
+ include ConfigurableEnforcedStyle
11
+
12
+ def on_send(node)
13
+ if offense?(node)
14
+ add_offense(node.source_range, node.source_range, message)
15
+ end
16
+ end
17
+
18
+ def autocorrect(node)
19
+ ->(corrector) { corrector.replace(node, "request.#{style}") }
20
+ end
21
+
22
+ private
23
+
24
+ def offense?(node)
25
+ return false unless node.receiver
26
+ receiver_name = node.receiver.method_name
27
+ receiver_name == :request && node.method_name == wrong_method_name
28
+ end
29
+
30
+ def message
31
+ "Use `request.#{style}` instead of `request.#{wrong_method_name}`."
32
+ end
33
+
34
+ def wrong_method_name
35
+ style == :referer ? :referrer : :referer
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -4,51 +4,86 @@
4
4
  module RuboCop
5
5
  module Cop
6
6
  module Rails
7
- # Prefer the use of uniq before pluck instead of after.
7
+ # Prefer the use of uniq (or distinct), before pluck instead of after.
8
8
  #
9
- # The use of uniq before pluck is preferred because it executes
10
- # within the database.
9
+ # The use of uniq before pluck is preferred because it executes within
10
+ # the database.
11
11
  #
12
12
  # @example
13
13
  # # bad
14
- # Model.where(...).pluck(:id).uniq
14
+ # Model.pluck(:id).uniq
15
15
  #
16
16
  # # good
17
- # Model.where(...).uniq.pluck(:id)
17
+ # Model.uniq.pluck(:id)
18
+ #
19
+ # This cop has two different enforcement modes. When the EnforcementMode
20
+ # is conservative (the default) then only calls to pluck on a constant
21
+ # (i.e. a model class) before uniq are added as offenses.
22
+ #
23
+ # When the EnforcementMode is aggressive then all calls to pluck before
24
+ # uniq are added as offenses. This may lead to false positives as the cop
25
+ # cannot distinguish between calls to pluck on an ActiveRecord::Relation
26
+ # vs a call to pluck on an ActiveRecord::Associations::CollectionProxy.
27
+ #
28
+ # @example
29
+ # # this will return a Relation that pluck is called on
30
+ # Model.where(...).pluck(:id).uniq
31
+ #
32
+ # # an association on an instance will return a CollectionProxy
33
+ # instance.assoc.pluck(:id).uniq
34
+ #
35
+ # Autocorrect is disabled by default for this cop since it may generate
36
+ # false positives.
18
37
  #
19
38
  class UniqBeforePluck < RuboCop::Cop::Cop
20
- MSG = 'Use uniq before pluck'.freeze
21
- DOT_UNIQ = '.uniq'.freeze
39
+ MSG = 'Use `%s` before `pluck`'.freeze
22
40
  NEWLINE = "\n".freeze
41
+ PATTERN = '[!^block (send (send %s :pluck ...) ${:uniq :distinct} ...)]'
42
+ .freeze
43
+
44
+ def_node_matcher :conservative_node_match,
45
+ format(PATTERN, 'const')
46
+
47
+ def_node_matcher :aggressive_node_match,
48
+ format(PATTERN, '_')
23
49
 
24
50
  def on_send(node)
25
- receiver, method_name, *_args = *node
51
+ method = if mode == :conservative
52
+ conservative_node_match(node)
53
+ else
54
+ aggressive_node_match(node)
55
+ end
26
56
 
27
- unless method_name == :uniq &&
28
- !receiver.nil? &&
29
- receiver.send_type? &&
30
- receiver.children[1] == :pluck
31
- return
32
- end
33
- add_offense(node, :selector, MSG)
57
+ add_offense(node, :selector, format(MSG, method)) if method
34
58
  end
35
59
 
36
60
  def autocorrect(node)
61
+ send_pluck, method, *_args = *node
62
+ lambda do |corrector|
63
+ corrector.remove(dot_method_with_whitespace(method, node))
64
+ corrector.insert_before(send_pluck.loc.dot.begin, ".#{method}")
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def mode
71
+ @mode ||= cop_config['EnforcedMode'].to_sym
72
+ end
73
+
74
+ def dot_method_with_whitespace(method, node)
75
+ Parser::Source::Range.new(node.loc.expression.source_buffer,
76
+ dot_method_begin_pos(method, node),
77
+ node.loc.selector.end_pos)
78
+ end
79
+
80
+ def dot_method_begin_pos(method, node)
37
81
  lines = node.source.split(NEWLINE)
38
- begin_remove_pos = if lines.last.strip == DOT_UNIQ
39
- node.source.rindex(NEWLINE)
40
- else
41
- node.loc.dot.begin_pos
42
- end
43
- receiver = node.children.first
44
82
 
45
- lambda do |corrector|
46
- corrector.remove(
47
- Parser::Source::Range.new(node.loc.expression.source_buffer,
48
- begin_remove_pos,
49
- node.loc.selector.end_pos)
50
- )
51
- corrector.insert_before(receiver.loc.dot.begin, DOT_UNIQ)
83
+ if lines.last.strip == ".#{method}"
84
+ node.source.rindex(NEWLINE)
85
+ else
86
+ node.loc.dot.begin_pos
52
87
  end
53
88
  end
54
89
  end
@@ -8,29 +8,22 @@ module RuboCop
8
8
  class Validation < Cop
9
9
  MSG = 'Prefer the new style validations `%s` over `%s`.'.freeze
10
10
 
11
- BLACKLIST = [:validates_acceptance_of,
12
- :validates_confirmation_of,
13
- :validates_exclusion_of,
14
- :validates_format_of,
15
- :validates_inclusion_of,
16
- :validates_length_of,
17
- :validates_numericality_of,
18
- :validates_presence_of,
19
- :validates_size_of,
20
- :validates_uniqueness_of].freeze
21
-
22
- WHITELIST = [
23
- 'validates :column, acceptance: value',
24
- 'validates :column, confirmation: value',
25
- 'validates :column, exclusion: value',
26
- 'validates :column, format: value',
27
- 'validates :column, inclusion: value',
28
- 'validates :column, length: value',
29
- 'validates :column, numericality: value',
30
- 'validates :column, presence: value',
31
- 'validates :column, size: value',
32
- 'validates :column, uniqueness: value'
33
- ].freeze
11
+ TYPES = %w(
12
+ acceptance
13
+ confirmation
14
+ exclusion
15
+ format
16
+ inclusion
17
+ length
18
+ numericality
19
+ presence
20
+ size
21
+ uniqueness
22
+ ).freeze
23
+
24
+ BLACKLIST = TYPES.map { |p| "validates_#{p}_of".to_sym }.freeze
25
+
26
+ WHITELIST = TYPES.map { |p| "validates :column, #{p}: value" }.freeze
34
27
 
35
28
  def on_send(node)
36
29
  receiver, method_name, *_args = *node
@@ -48,6 +41,27 @@ module RuboCop
48
41
  def preferred_method(method)
49
42
  WHITELIST[BLACKLIST.index(method.to_sym)]
50
43
  end
44
+
45
+ def autocorrect(node)
46
+ _receiver, method_name, *args = *node
47
+ options = args.find { |arg| arg.type != :sym }
48
+ lambda do |corrector|
49
+ validate_type = method_name.to_s.split('_')[1]
50
+ corrector.replace(node.loc.selector, 'validates')
51
+ cop_config['AllowUnusedKeywordArguments']
52
+ if options
53
+ corrector.replace(
54
+ options.loc.expression,
55
+ "#{validate_type}: { #{options.source} }"
56
+ )
57
+ else
58
+ corrector.insert_after(
59
+ node.loc.expression,
60
+ ", #{validate_type}: true"
61
+ )
62
+ end
63
+ end
64
+ end
51
65
  end
52
66
  end
53
67
  end
@@ -34,15 +34,19 @@ module RuboCop
34
34
  if scope_type == :dynamic || style == :prefer_alias_method
35
35
  add_offense(node, :keyword, MSG_ALIAS)
36
36
  elsif node.children.none? { |arg| bareword?(arg) }
37
- existing_args = node.children.map(&:source).join(' ')
38
- preferred_args = node.children.map { |a| a.source[1..-1] }.join(' ')
39
- arg_ranges = node.children.map(&:source_range)
40
- msg = format(MSG_SYMBOL_ARGS, preferred_args,
41
- existing_args)
42
- add_offense(node, arg_ranges.reduce(&:join), msg)
37
+ add_offense_for_args(node)
43
38
  end
44
39
  end
45
40
 
41
+ def add_offense_for_args(node)
42
+ existing_args = node.children.map(&:source).join(' ')
43
+ preferred_args = node.children.map { |a| a.source[1..-1] }.join(' ')
44
+ arg_ranges = node.children.map(&:source_range)
45
+ msg = format(MSG_SYMBOL_ARGS, preferred_args,
46
+ existing_args)
47
+ add_offense(node, arg_ranges.reduce(&:join), msg)
48
+ end
49
+
46
50
  def autocorrect(node)
47
51
  if node.send_type?
48
52
  correct_alias_method_to_alias(node)
@@ -25,13 +25,24 @@ module RuboCop
25
25
  return unless node.loc.respond_to?(:begin)
26
26
  return unless node.loc.begin
27
27
 
28
- msg = case node.loc.begin.source
29
- when /^%[^\w]/
30
- format(MSG, 'Q', '') if style == :percent_q
31
- when /^%Q/
32
- format(MSG, '', 'Q') if style == :bare_percent
33
- end
34
- add_offense(node, :begin, msg) if msg
28
+ source = node.loc.begin.source
29
+ if requires_percent_q?(source)
30
+ add_offense_for_wrong_style(node, 'Q', '')
31
+ elsif requires_bare_percent?(source)
32
+ add_offense_for_wrong_style(node, '', 'Q')
33
+ end
34
+ end
35
+
36
+ def requires_percent_q?(source)
37
+ style == :percent_q && source =~ /^%[^\w]/
38
+ end
39
+
40
+ def requires_bare_percent?(source)
41
+ style == :bare_percent && source =~ /^%Q/
42
+ end
43
+
44
+ def add_offense_for_wrong_style(node, good, bad)
45
+ add_offense(node, :begin, format(MSG, good, bad))
35
46
  end
36
47
 
37
48
  def autocorrect(node)
@@ -9,26 +9,25 @@ module RuboCop
9
9
  class BlockDelimiters < Cop
10
10
  include ConfigurableEnforcedStyle
11
11
 
12
- def_node_matcher :block_method_name, '(block (send _ $_ ...) ...)'
13
-
14
12
  def on_send(node)
15
13
  _receiver, method_name, *args = *node
16
14
  return if args.empty?
17
15
  return if parentheses?(node) || operator?(method_name)
18
16
 
19
- get_blocks(args.last) do |block|
20
- # If there are no parentheses around the arguments, then braces and
21
- # do-end have different meaning due to how they bind, so we allow
22
- # either.
23
- ignore_node(block)
17
+ args.each do |arg|
18
+ get_blocks(arg) do |block|
19
+ # If there are no parentheses around the arguments, then braces
20
+ # and do-end have different meaning due to how they bind, so we
21
+ # allow either.
22
+ ignore_node(block)
23
+ end
24
24
  end
25
25
  end
26
26
 
27
27
  def on_block(node)
28
28
  return if ignored_node?(node)
29
- return if proper_block_style?(node)
30
29
 
31
- add_offense(node, :begin)
30
+ add_offense(node, :begin) unless proper_block_style?(node)
32
31
  end
33
32
 
34
33
  private
@@ -65,12 +64,9 @@ module RuboCop
65
64
 
66
65
  def message(node)
67
66
  case style
68
- when :line_count_based
69
- line_count_based_message(node)
70
- when :semantic
71
- semantic_message(node)
72
- when :braces_for_chaining
73
- braces_for_chaining_message(node)
67
+ when :line_count_based then line_count_based_message(node)
68
+ when :semantic then semantic_message(node)
69
+ when :braces_for_chaining then braces_for_chaining_message(node)
74
70
  end
75
71
  end
76
72
 
@@ -117,12 +113,9 @@ module RuboCop
117
113
 
118
114
  def proper_block_style?(node)
119
115
  case style
120
- when :line_count_based
121
- line_count_based_block_style?(node)
122
- when :semantic
123
- semantic_block_style?(node)
124
- when :braces_for_chaining
125
- braces_for_chaining_style?(node)
116
+ when :line_count_based then line_count_based_block_style?(node)
117
+ when :semantic then semantic_block_style?(node)
118
+ when :braces_for_chaining then braces_for_chaining_style?(node)
126
119
  end
127
120
  end
128
121
 
@@ -133,7 +126,7 @@ module RuboCop
133
126
  end
134
127
 
135
128
  def semantic_block_style?(node)
136
- method_name = block_method_name(node)
129
+ method_name = node.method_name
137
130
  return true if ignored_method?(method_name)
138
131
 
139
132
  block_begin = node.loc.begin.source