rubocop 0.24.1 → 0.25.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 (128) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +12 -8
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +42 -0
  5. data/Gemfile +2 -0
  6. data/README.md +27 -6
  7. data/bin/rubocop +10 -15
  8. data/config/default.yml +72 -25
  9. data/config/enabled.yml +57 -25
  10. data/lib/rubocop.rb +15 -8
  11. data/lib/rubocop/config_loader.rb +11 -7
  12. data/lib/rubocop/cop/cop.rb +16 -16
  13. data/lib/rubocop/cop/ignored_node.rb +11 -4
  14. data/lib/rubocop/cop/lint/block_alignment.rb +29 -4
  15. data/lib/rubocop/cop/lint/debugger.rb +8 -1
  16. data/lib/rubocop/cop/lint/def_end_alignment.rb +5 -1
  17. data/lib/rubocop/cop/lint/end_alignment.rb +5 -5
  18. data/lib/rubocop/cop/lint/end_in_method.rb +2 -2
  19. data/lib/rubocop/cop/lint/useless_setter_call.rb +2 -2
  20. data/lib/rubocop/cop/{style → metrics}/block_nesting.rb +1 -1
  21. data/lib/rubocop/cop/{style → metrics}/class_length.rb +4 -4
  22. data/lib/rubocop/cop/{style → metrics}/cyclomatic_complexity.rb +5 -16
  23. data/lib/rubocop/cop/{style → metrics}/line_length.rb +1 -1
  24. data/lib/rubocop/cop/{style → metrics}/method_length.rb +8 -4
  25. data/lib/rubocop/cop/{style → metrics}/parameter_lists.rb +1 -1
  26. data/lib/rubocop/cop/metrics/perceived_complexity.rb +61 -0
  27. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +10 -2
  28. data/lib/rubocop/cop/mixin/code_length.rb +2 -3
  29. data/lib/rubocop/cop/mixin/configurable_naming.rb +6 -20
  30. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
  31. data/lib/rubocop/cop/mixin/if_node.rb +1 -1
  32. data/lib/rubocop/cop/mixin/method_complexity.rb +32 -0
  33. data/lib/rubocop/cop/mixin/negative_conditional.rb +1 -1
  34. data/lib/rubocop/cop/mixin/{check_methods.rb → on_method.rb} +3 -3
  35. data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +24 -0
  36. data/lib/rubocop/cop/mixin/percent_literal.rb +2 -1
  37. data/lib/rubocop/cop/mixin/space_inside.rb +33 -4
  38. data/lib/rubocop/cop/mixin/statement_modifier.rb +14 -14
  39. data/lib/rubocop/cop/mixin/string_help.rb +4 -0
  40. data/lib/rubocop/cop/mixin/surrounding_space.rb +1 -0
  41. data/lib/rubocop/cop/rails/delegate.rb +2 -2
  42. data/lib/rubocop/cop/rails/output.rb +4 -2
  43. data/lib/rubocop/cop/style/accessor_method_name.rb +2 -2
  44. data/lib/rubocop/cop/style/align_hash.rb +9 -1
  45. data/lib/rubocop/cop/style/and_or.rb +37 -3
  46. data/lib/rubocop/cop/style/bare_percent_literals.rb +46 -0
  47. data/lib/rubocop/cop/style/block_end_newline.rb +56 -0
  48. data/lib/rubocop/cop/style/character_literal.rb +1 -1
  49. data/lib/rubocop/cop/style/def_with_parentheses.rb +2 -2
  50. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +31 -3
  51. data/lib/rubocop/cop/style/empty_lines_around_body.rb +6 -2
  52. data/lib/rubocop/cop/style/end_of_line.rb +3 -14
  53. data/lib/rubocop/cop/style/if_unless_modifier.rb +3 -6
  54. data/lib/rubocop/cop/style/if_with_semicolon.rb +6 -7
  55. data/lib/rubocop/cop/style/indentation_width.rb +3 -8
  56. data/lib/rubocop/cop/style/method_def_parentheses.rb +2 -2
  57. data/lib/rubocop/cop/style/method_name.rb +4 -18
  58. data/lib/rubocop/cop/style/multiline_block_layout.rb +73 -0
  59. data/lib/rubocop/cop/style/multiline_if_then.rb +4 -4
  60. data/lib/rubocop/cop/style/negated_if.rb +1 -1
  61. data/lib/rubocop/cop/style/negated_while.rb +2 -2
  62. data/lib/rubocop/cop/style/next.rb +12 -0
  63. data/lib/rubocop/cop/style/one_line_conditional.rb +6 -6
  64. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +22 -8
  65. data/lib/rubocop/cop/style/percent_q_literals.rb +53 -0
  66. data/lib/rubocop/cop/style/predicate_name.rb +2 -2
  67. data/lib/rubocop/cop/style/redundant_begin.rb +2 -2
  68. data/lib/rubocop/cop/style/redundant_return.rb +2 -2
  69. data/lib/rubocop/cop/style/rescue_modifier.rb +7 -3
  70. data/lib/rubocop/cop/style/single_line_methods.rb +2 -2
  71. data/lib/rubocop/cop/style/space_after_method_name.rb +2 -2
  72. data/lib/rubocop/cop/style/space_inside_block_braces.rb +14 -10
  73. data/lib/rubocop/cop/style/space_inside_brackets.rb +5 -1
  74. data/lib/rubocop/cop/style/string_literals.rb +5 -8
  75. data/lib/rubocop/cop/style/trailing_comma.rb +15 -3
  76. data/lib/rubocop/cop/style/trivial_accessors.rb +2 -2
  77. data/lib/rubocop/cop/style/unneeded_capital_w.rb +2 -4
  78. data/lib/rubocop/cop/style/unneeded_percent_q.rb +13 -0
  79. data/lib/rubocop/cop/style/variable_interpolation.rb +14 -2
  80. data/lib/rubocop/cop/style/variable_name.rb +17 -17
  81. data/lib/rubocop/cop/style/while_until_modifier.rb +2 -5
  82. data/lib/rubocop/cop/util.rb +5 -0
  83. data/lib/rubocop/cop/variable_force.rb +7 -6
  84. data/lib/rubocop/formatter/base_formatter.rb +2 -2
  85. data/lib/rubocop/processed_source.rb +5 -22
  86. data/lib/rubocop/version.rb +1 -1
  87. data/relnotes/v0.25.0.md +91 -0
  88. data/rubocop.gemspec +2 -3
  89. data/spec/project_spec.rb +1 -1
  90. data/spec/rubocop/cli_spec.rb +70 -44
  91. data/spec/rubocop/comment_config_spec.rb +6 -6
  92. data/spec/rubocop/config_loader_spec.rb +19 -13
  93. data/spec/rubocop/config_spec.rb +3 -3
  94. data/spec/rubocop/cop/commissioner_spec.rb +1 -1
  95. data/spec/rubocop/cop/cop_spec.rb +3 -3
  96. data/spec/rubocop/cop/lint/block_alignment_spec.rb +113 -6
  97. data/spec/rubocop/cop/lint/debugger_spec.rb +10 -6
  98. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +12 -0
  99. data/spec/rubocop/cop/{style → metrics}/block_nesting_spec.rb +1 -1
  100. data/spec/rubocop/cop/{style → metrics}/class_length_spec.rb +1 -1
  101. data/spec/rubocop/cop/{style → metrics}/cyclomatic_complexity_spec.rb +1 -1
  102. data/spec/rubocop/cop/{style → metrics}/if_unless_modifier_spec.rb +2 -2
  103. data/spec/rubocop/cop/{style → metrics}/line_length_spec.rb +7 -7
  104. data/spec/rubocop/cop/{style → metrics}/method_length_spec.rb +1 -1
  105. data/spec/rubocop/cop/{style → metrics}/parameter_lists_spec.rb +1 -1
  106. data/spec/rubocop/cop/metrics/perceived_complexity_spec.rb +222 -0
  107. data/spec/rubocop/cop/{style → metrics}/while_until_modifier_spec.rb +2 -2
  108. data/spec/rubocop/cop/rails/output_spec.rb +8 -2
  109. data/spec/rubocop/cop/style/align_hash_spec.rb +7 -0
  110. data/spec/rubocop/cop/style/and_or_spec.rb +245 -43
  111. data/spec/rubocop/cop/style/bare_percent_literals_spec.rb +132 -0
  112. data/spec/rubocop/cop/style/block_end_newline_spec.rb +61 -0
  113. data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +34 -0
  114. data/spec/rubocop/cop/style/end_of_line_spec.rb +8 -0
  115. data/spec/rubocop/cop/style/guard_clause_spec.rb +1 -1
  116. data/spec/rubocop/cop/style/multiline_block_layout_spec.rb +138 -0
  117. data/spec/rubocop/cop/style/next_spec.rb +32 -3
  118. data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +34 -0
  119. data/spec/rubocop/cop/style/percent_q_literals_spec.rb +122 -0
  120. data/spec/rubocop/cop/style/space_inside_block_braces_spec.rb +20 -0
  121. data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +26 -2
  122. data/spec/rubocop/cop/style/trailing_comma_spec.rb +112 -0
  123. data/spec/rubocop/cop/style/unneeded_percent_q_spec.rb +86 -31
  124. data/spec/rubocop/cop/style/variable_interpolation_spec.rb +21 -1
  125. data/spec/rubocop/cop/team_spec.rb +14 -9
  126. data/spec/spec_helper.rb +1 -0
  127. metadata +47 -50
  128. data/lib/rubocop/cop/mixin/if_then_else.rb +0 -23
@@ -18,11 +18,11 @@ module RuboCop
18
18
  # # good
19
19
  # def attribute ...
20
20
  class AccessorMethodName < Cop
21
- include CheckMethods
21
+ include OnMethod
22
22
 
23
23
  private
24
24
 
25
- def check(node, method_name, args, _body)
25
+ def on_method(node, method_name, args, _body)
26
26
  if bad_reader_name?(method_name.to_s, args)
27
27
  add_offense(node, :name,
28
28
  'Do not prefix reader method names with `get_`.')
@@ -199,8 +199,16 @@ module RuboCop
199
199
  node.loc.begin
200
200
  end
201
201
 
202
+ # Returns true if the hash spans multiple lines, and each key-value
203
+ # pair following the first is on a new line.
202
204
  def multiline?(node)
203
- node.loc.expression.source.include?("\n")
205
+ return false unless node.loc.expression.source.include?("\n")
206
+
207
+ return false if node.children[1..-1].find do |child|
208
+ !begins_its_line?(child.loc.expression)
209
+ end
210
+
211
+ true
204
212
  end
205
213
 
206
214
  def alignment_for(pair)
@@ -6,21 +6,40 @@ module RuboCop
6
6
  # This cop checks for uses of *and* and *or*.
7
7
  class AndOr < Cop
8
8
  include AutocorrectUnlessChangingAST
9
+ include ConfigurableEnforcedStyle
9
10
 
10
11
  MSG = 'Use `%s` instead of `%s`.'
11
12
 
12
13
  OPS = { 'and' => '&&', 'or' => '||' }
13
14
 
14
15
  def on_and(node)
15
- process_logical_op(node)
16
+ process_logical_op(node) if style == :always
16
17
  end
17
18
 
18
19
  def on_or(node)
19
- process_logical_op(node)
20
+ process_logical_op(node) if style == :always
21
+ end
22
+
23
+ def on_if(node)
24
+ on_conditionals(node) if style == :conditionals
25
+ end
26
+
27
+ def on_while(node)
28
+ on_conditionals(node) if style == :conditionals
29
+ end
30
+
31
+ def on_until(node)
32
+ on_conditionals(node) if style == :conditionals
20
33
  end
21
34
 
22
35
  private
23
36
 
37
+ def on_conditionals(node)
38
+ on_node([:and, :or], node) do |my_node|
39
+ process_logical_op(my_node)
40
+ end
41
+ end
42
+
24
43
  def process_logical_op(node)
25
44
  op = node.loc.operator.source
26
45
  op_type = node.type.to_s
@@ -30,8 +49,23 @@ module RuboCop
30
49
  end
31
50
 
32
51
  def correction(node)
52
+ expr1, expr2 = *node
53
+ replacement = (node.type == :and ? '&&' : '||')
33
54
  lambda do |corrector|
34
- replacement = (node.type == :and ? '&&' : '||')
55
+ [expr1, expr2].each do |expr|
56
+ next unless expr.type == :send
57
+ _receiver, method_name, *args = *expr
58
+ # don't clobber if we already have a starting paren
59
+ next unless !expr.loc.begin || expr.loc.begin.source != '('
60
+ # don't touch anything unless we are sure it is a method call.
61
+ next unless args.last && method_name.to_s =~ /[a-z]/
62
+ sb = expr.loc.expression.source_buffer
63
+ begin_paren = expr.loc.selector.end_pos
64
+ end_paren = begin_paren + 1
65
+ range = Parser::Source::Range.new(sb, begin_paren, end_paren)
66
+ corrector.replace(range, '(')
67
+ corrector.insert_after(args.last.loc.expression, ')')
68
+ end
35
69
  corrector.replace(node.loc.operator, replacement)
36
70
  end
37
71
  end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ # This cop checks if usage of %() or %Q() matches configuration.
7
+ class BarePercentLiterals < Cop
8
+ include ConfigurableEnforcedStyle
9
+
10
+ MSG = 'Use `%%%s` instead of `%%%s`.'
11
+
12
+ def on_dstr(node)
13
+ check(node)
14
+ end
15
+
16
+ def on_str(node)
17
+ check(node)
18
+ end
19
+
20
+ private
21
+
22
+ def check(node)
23
+ return if node.loc.respond_to?(:heredoc_body)
24
+ return unless node.loc.respond_to?(:begin)
25
+ return unless node.loc.begin
26
+
27
+ msg = case node.loc.begin.source
28
+ when /^%[^\w]/
29
+ format(MSG, 'Q', '') if style == :percent_q
30
+ when /^%Q/
31
+ format(MSG, '', 'Q') if style == :bare_percent
32
+ end
33
+ add_offense(node, :begin, msg) if msg
34
+ end
35
+
36
+ def autocorrect(node)
37
+ src = node.loc.begin.source
38
+ replacement = src.start_with?('%Q') ? '%' : '%Q'
39
+ @corrections << lambda do |corrector|
40
+ corrector.replace(node.loc.begin, src.sub(/%Q?/, replacement))
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ # This cop checks whether the end statement of a do end blocks
7
+ # is on its own line.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # blah do |i|
12
+ # foo(i) end
13
+ #
14
+ # # good
15
+ # blah do |i|
16
+ # foo(i)
17
+ # end
18
+ #
19
+ # # bad
20
+ # blah { |i|
21
+ # foo(i) }
22
+ #
23
+ # # good
24
+ # blah { |i|
25
+ # foo(i)
26
+ # }
27
+ class BlockEndNewline < Cop
28
+ MSG = 'Expression at %d, %d should be on its own line.'
29
+
30
+ def on_block(node)
31
+ end_loc = node.loc.end
32
+ do_loc = node.loc.begin # Actually it's either do or {.
33
+ return if do_loc.line == end_loc.line # Ignore one-liners.
34
+
35
+ # If the end is on its own line, there is no offense
36
+ return if /^\s*#{end_loc.source}/.match(end_loc.source_line)
37
+
38
+ msg = format(MSG, end_loc.line, end_loc.column + 1)
39
+ add_offense(node, end_loc, msg)
40
+ end
41
+
42
+ def autocorrect(node)
43
+ @corrections << lambda do |corrector|
44
+ indentation = indentation_of_block_start_line(node)
45
+ corrector.insert_before(node.loc.end, "\n" + (' ' * indentation))
46
+ end
47
+ end
48
+
49
+ def indentation_of_block_start_line(node)
50
+ match = /\S.*/.match(node.loc.begin.source_line)
51
+ match.begin(0)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -22,7 +22,7 @@ module RuboCop
22
22
  if string.length == 1 # normal character
23
23
  corrector.replace(node.loc.expression, "'#{string}'")
24
24
  elsif string.length == 2 # special character like \n
25
- corrector.replace(node.loc.expression, %Q("#{string}"))
25
+ corrector.replace(node.loc.expression, %("#{string}"))
26
26
  end
27
27
  end
28
28
  end
@@ -7,12 +7,12 @@ module RuboCop
7
7
  # that does not take any arguments. Both instance and
8
8
  # class/singleton methods are checked.
9
9
  class DefWithParentheses < Cop
10
- include CheckMethods
10
+ include OnMethod
11
11
 
12
12
  MSG = "Omit the parentheses in defs when the method doesn't accept " \
13
13
  'any arguments.'
14
14
 
15
- def check(node, _method_name, args, _body)
15
+ def on_method(node, _method_name, args, _body)
16
16
  start_line = node.loc.keyword.line
17
17
  end_line = node.loc.end.line
18
18
 
@@ -17,16 +17,44 @@ module RuboCop
17
17
  add_offense(node, :expression)
18
18
  end
19
19
 
20
+ def autocorrect(node)
21
+ @corrections << lambda do |corrector|
22
+ send_line = node.loc.line
23
+ previous_line = processed_source[send_line - 2]
24
+ next_line = processed_source[send_line]
25
+
26
+ line = Parser::Source::Range.new(
27
+ processed_source.buffer,
28
+ node.loc.expression.begin_pos - node.loc.column,
29
+ node.loc.expression.end_pos
30
+ )
31
+
32
+ unless previous_line_empty?(previous_line)
33
+ corrector.insert_before(line, "\n")
34
+ end
35
+
36
+ unless next_line_empty?(next_line)
37
+ corrector.insert_after(line, "\n")
38
+ end
39
+ end
40
+ end
41
+
20
42
  private
21
43
 
44
+ def previous_line_empty?(previous_line)
45
+ class_def?(previous_line.lstrip) || previous_line.blank?
46
+ end
47
+
48
+ def next_line_empty?(next_line)
49
+ next_line.blank?
50
+ end
51
+
22
52
  def empty_lines_around?(node)
23
53
  send_line = node.loc.line
24
54
  previous_line = processed_source[send_line - 2]
25
55
  next_line = processed_source[send_line]
26
56
 
27
- (class_def?(previous_line.lstrip) ||
28
- previous_line.blank?) &&
29
- next_line.blank?
57
+ previous_line_empty?(previous_line) && next_line_empty?(next_line)
30
58
  end
31
59
 
32
60
  def class_def?(line)
@@ -22,7 +22,7 @@ module RuboCop
22
22
  # end
23
23
  #
24
24
  class EmptyLinesAroundBody < Cop
25
- include CheckMethods
25
+ include OnMethod
26
26
 
27
27
  MSG_BEG = 'Extra empty line detected at body beginning.'
28
28
  MSG_END = 'Extra empty line detected at body end.'
@@ -45,7 +45,11 @@ module RuboCop
45
45
 
46
46
  private
47
47
 
48
- def check(node, *_)
48
+ def on_method(node, _method_name, _args, _body)
49
+ check(node)
50
+ end
51
+
52
+ def check(node)
49
53
  start_line = node.loc.keyword.line
50
54
  end_line = node.loc.end.line
51
55
 
@@ -8,28 +8,17 @@ module RuboCop
8
8
  MSG = 'Carriage return character detected.'
9
9
 
10
10
  def investigate(processed_source)
11
- buffer = processed_source.buffer
12
- original_source = IO.read(buffer.name, encoding: 'ascii-8bit')
13
- change_encoding(original_source)
14
-
15
- original_source.lines.each_with_index do |line, index|
11
+ processed_source.raw_source.each_line.with_index do |line, index|
16
12
  next unless line =~ /\r$/
17
13
 
18
- range = source_range(buffer, index + 1, 0, line.length)
14
+ range =
15
+ source_range(processed_source.buffer, index + 1, 0, line.length)
19
16
  add_offense(nil, range, MSG)
20
17
  # Usually there will be carriage return characters on all or none
21
18
  # of the lines in a file, so we report only one offense.
22
19
  break
23
20
  end
24
21
  end
25
-
26
- private
27
-
28
- def change_encoding(string)
29
- recognized_encoding =
30
- Parser::Source::Buffer.recognize_encoding(string)
31
- string.force_encoding(recognized_encoding) if recognized_encoding
32
- end
33
22
  end
34
23
  end
35
24
  end
@@ -9,7 +9,7 @@ module RuboCop
9
9
  class IfUnlessModifier < Cop
10
10
  include StatementModifier
11
11
 
12
- def error_message(keyword)
12
+ def message(keyword)
13
13
  "Favor modifier `#{keyword}` usage when having a single-line body." \
14
14
  ' Another good alternative is the usage of control flow `&&`/`||`.'
15
15
  end
@@ -22,11 +22,8 @@ module RuboCop
22
22
  next if modifier_if?(node)
23
23
  next if elsif?(node)
24
24
  next if if_else?(node)
25
-
26
- if check(node, processed_source.comments)
27
- add_offense(node, :keyword,
28
- error_message(node.loc.keyword.source))
29
- end
25
+ next unless fit_within_line_as_modifier_form?(node)
26
+ add_offense(node, :keyword, message(node.loc.keyword.source))
30
27
  end
31
28
  end
32
29
  end
@@ -5,15 +5,14 @@ module RuboCop
5
5
  module Style
6
6
  # Checks for uses of semicolon in if statements.
7
7
  class IfWithSemicolon < Cop
8
- include IfThenElse
8
+ include OnNormalIfUnless
9
9
 
10
- def offending_line(node)
11
- b = node.loc.begin
12
- b.line if b && b.is?(';')
13
- end
10
+ MSG = 'Never use if x; Use the ternary operator instead.'
14
11
 
15
- def error_message(_node)
16
- 'Never use if x; Use the ternary operator instead.'
12
+ def on_normal_if_unless(node)
13
+ beginning = node.loc.begin
14
+ return unless beginning && beginning.is?(';')
15
+ add_offense(node, :expression, MSG)
17
16
  end
18
17
  end
19
18
  end
@@ -12,9 +12,9 @@ module RuboCop
12
12
  # puts 'hello'
13
13
  # end
14
14
  # end
15
- class IndentationWidth < Cop # rubocop:disable Style/ClassLength
15
+ class IndentationWidth < Cop # rubocop:disable Metrics/ClassLength
16
16
  include AutocorrectAlignment
17
- include CheckMethods
17
+ include OnMethod
18
18
  include CheckAssignment
19
19
  include IfNode
20
20
  include AccessModifierNode
@@ -72,7 +72,7 @@ module RuboCop
72
72
  ignore_node(args.first)
73
73
  end
74
74
 
75
- def check(node, _method_name, _args, body)
75
+ def on_method(node, _method_name, _args, body)
76
76
  check_indentation(node.loc.keyword, body) unless ignored_node?(node)
77
77
  end
78
78
 
@@ -140,11 +140,6 @@ module RuboCop
140
140
 
141
141
  private
142
142
 
143
- def begins_its_line?(range)
144
- source_before_end = range.source_buffer.source[0...range.begin_pos]
145
- source_before_end =~ /\n\s*\Z/
146
- end
147
-
148
143
  def check_assignment(node, rhs)
149
144
  # If there are method calls chained to the right hand side of the
150
145
  # assignment, we let rhs be the receiver of those method calls before
@@ -6,10 +6,10 @@ module RuboCop
6
6
  # This cops checks for parentheses around the arguments in method
7
7
  # definitions. Both instance and class/singleton methods are checked.
8
8
  class MethodDefParentheses < Cop
9
- include CheckMethods
9
+ include OnMethod
10
10
  include ConfigurableEnforcedStyle
11
11
 
12
- def check(node, _method_name, args, _body)
12
+ def on_method(node, _method_name, args, _body)
13
13
  if style == :require_parentheses
14
14
  if arguments?(args) && !parentheses?(args)
15
15
  add_offense(node,
@@ -10,27 +10,13 @@ module RuboCop
10
10
  include ConfigurableNaming
11
11
 
12
12
  def on_def(node)
13
- check(node, name_of_instance_method(node))
13
+ name, = *node
14
+ check_name(node, name, node.loc.name)
14
15
  end
15
16
 
16
17
  def on_defs(node)
17
- check(node, name_of_singleton_method(node))
18
- end
19
-
20
- def name_of_instance_method(def_node)
21
- expr = def_node.loc.expression
22
- match = /^def(\s+)([\w]+[!?=]?\b)/.match(expr.source)
23
- return unless match
24
- space, method_name = match.captures
25
- begin_pos = expr.begin_pos + 'def'.length + space.length
26
- Parser::Source::Range.new(expr.source_buffer, begin_pos,
27
- begin_pos + method_name.length)
28
- end
29
-
30
- def name_of_singleton_method(defs_node)
31
- scope, method_name, _args, _body = *defs_node
32
- after_dot(defs_node, method_name.length,
33
- "def\s+" + Regexp.escape(scope.loc.expression.source))
18
+ _object, name, = *node
19
+ check_name(node, name, node.loc.name)
34
20
  end
35
21
 
36
22
  def message(style)