rbhint 0.85.1.rc2 → 0.87.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -1
  3. data/bin/rubocop-profile +16 -0
  4. data/config/default.yml +118 -10
  5. data/lib/rbhint/version.rb +1 -1
  6. data/lib/rubocop.rb +15 -1
  7. data/lib/rubocop/cli.rb +0 -2
  8. data/lib/rubocop/cli/command/auto_genenerate_config.rb +40 -5
  9. data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
  10. data/lib/rubocop/cli/command/show_cops.rb +1 -1
  11. data/lib/rubocop/config_loader.rb +24 -66
  12. data/lib/rubocop/config_obsoletion.rb +0 -1
  13. data/lib/rubocop/cop/autocorrect_logic.rb +14 -24
  14. data/lib/rubocop/cop/badge.rb +1 -1
  15. data/lib/rubocop/cop/base.rb +407 -0
  16. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
  17. data/lib/rubocop/cop/commissioner.rb +48 -50
  18. data/lib/rubocop/cop/cop.rb +85 -236
  19. data/lib/rubocop/cop/corrector.rb +38 -115
  20. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +26 -0
  21. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +6 -1
  22. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
  23. data/lib/rubocop/cop/generator.rb +1 -1
  24. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
  25. data/lib/rubocop/cop/layout/case_indentation.rb +18 -19
  26. data/lib/rubocop/cop/layout/class_structure.rb +2 -37
  27. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -0
  28. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -8
  29. data/lib/rubocop/cop/layout/end_alignment.rb +3 -2
  30. data/lib/rubocop/cop/layout/first_argument_indentation.rb +4 -0
  31. data/lib/rubocop/cop/layout/hash_alignment.rb +1 -2
  32. data/lib/rubocop/cop/layout/multiline_block_layout.rb +17 -7
  33. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +22 -27
  34. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +27 -68
  35. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +3 -2
  36. data/lib/rubocop/cop/legacy/corrections_proxy.rb +49 -0
  37. data/lib/rubocop/cop/legacy/corrector.rb +29 -0
  38. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +4 -4
  39. data/lib/rubocop/cop/lint/duplicate_elsif_condition.rb +39 -0
  40. data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -2
  41. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +3 -2
  42. data/lib/rubocop/cop/lint/interpolation_check.rb +13 -0
  43. data/lib/rubocop/cop/lint/literal_as_condition.rb +11 -1
  44. data/lib/rubocop/cop/lint/nested_method_definition.rb +14 -20
  45. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
  46. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +8 -3
  47. data/lib/rubocop/cop/lint/raise_exception.rb +8 -0
  48. data/lib/rubocop/cop/lint/rand_one.rb +1 -1
  49. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +27 -23
  50. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
  51. data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
  52. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +8 -0
  53. data/lib/rubocop/cop/lint/syntax.rb +11 -26
  54. data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
  55. data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -1
  56. data/lib/rubocop/cop/metrics/block_length.rb +24 -2
  57. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  58. data/lib/rubocop/cop/metrics/class_length.rb +26 -3
  59. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
  60. data/lib/rubocop/cop/metrics/method_length.rb +24 -1
  61. data/lib/rubocop/cop/metrics/module_length.rb +26 -3
  62. data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
  63. data/lib/rubocop/cop/metrics/perceived_complexity.rb +3 -3
  64. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +129 -0
  65. data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
  66. data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
  67. data/lib/rubocop/cop/mixin/code_length.rb +4 -0
  68. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -1
  69. data/lib/rubocop/cop/mixin/enforce_superclass.rb +3 -1
  70. data/lib/rubocop/cop/mixin/nil_methods.rb +3 -5
  71. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +6 -1
  72. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -3
  73. data/lib/rubocop/cop/mixin/surrounding_space.rb +7 -2
  74. data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -13
  75. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +4 -2
  76. data/lib/rubocop/cop/mixin/visibility_help.rb +50 -0
  77. data/lib/rubocop/cop/naming/ascii_identifiers.rb +27 -4
  78. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +2 -2
  79. data/lib/rubocop/cop/naming/method_name.rb +1 -1
  80. data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
  81. data/lib/rubocop/cop/naming/predicate_name.rb +3 -5
  82. data/lib/rubocop/cop/naming/variable_name.rb +1 -1
  83. data/lib/rubocop/cop/naming/variable_number.rb +1 -1
  84. data/lib/rubocop/cop/offense.rb +16 -2
  85. data/lib/rubocop/cop/style/accessor_grouping.rb +147 -0
  86. data/lib/rubocop/cop/style/array_coercion.rb +63 -0
  87. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +3 -2
  88. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +146 -0
  89. data/lib/rubocop/cop/style/case_like_if.rb +217 -0
  90. data/lib/rubocop/cop/style/class_vars.rb +21 -0
  91. data/lib/rubocop/cop/style/commented_keyword.rb +5 -2
  92. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  93. data/lib/rubocop/cop/style/date_time.rb +1 -1
  94. data/lib/rubocop/cop/style/dir.rb +2 -2
  95. data/lib/rubocop/cop/style/empty_literal.rb +5 -5
  96. data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
  97. data/lib/rubocop/cop/style/exponential_notation.rb +6 -8
  98. data/lib/rubocop/cop/style/float_division.rb +7 -10
  99. data/lib/rubocop/cop/style/format_string_token.rb +5 -5
  100. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +62 -0
  101. data/lib/rubocop/cop/style/hash_like_case.rb +76 -0
  102. data/lib/rubocop/cop/style/if_unless_modifier.rb +11 -11
  103. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -0
  104. data/lib/rubocop/cop/style/missing_else.rb +1 -11
  105. data/lib/rubocop/cop/style/multiline_block_chain.rb +10 -1
  106. data/lib/rubocop/cop/style/mutable_constant.rb +4 -4
  107. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -5
  108. data/lib/rubocop/cop/style/numeric_predicate.rb +3 -4
  109. data/lib/rubocop/cop/style/parallel_assignment.rb +3 -3
  110. data/lib/rubocop/cop/style/proc.rb +1 -1
  111. data/lib/rubocop/cop/style/random_with_offset.rb +4 -10
  112. data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
  113. data/lib/rubocop/cop/style/redundant_exception.rb +14 -10
  114. data/lib/rubocop/cop/style/redundant_fetch_block.rb +122 -0
  115. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +50 -0
  116. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  117. data/lib/rubocop/cop/style/redundant_parentheses.rb +7 -1
  118. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -1
  119. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +2 -2
  120. data/lib/rubocop/cop/style/redundant_sort.rb +3 -2
  121. data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
  122. data/lib/rubocop/cop/style/signal_exception.rb +1 -1
  123. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +3 -2
  124. data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
  125. data/lib/rubocop/cop/style/struct_inheritance.rb +2 -2
  126. data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
  127. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +9 -32
  128. data/lib/rubocop/cop/style/trivial_accessors.rb +8 -7
  129. data/lib/rubocop/cop/style/yoda_condition.rb +18 -1
  130. data/lib/rubocop/cop/style/zero_length_predicate.rb +2 -2
  131. data/lib/rubocop/cop/team.rb +97 -81
  132. data/lib/rubocop/cop/utils/format_string.rb +1 -2
  133. data/lib/rubocop/cop/variable_force/variable.rb +5 -3
  134. data/lib/rubocop/file_finder.rb +4 -4
  135. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  136. data/lib/rubocop/name_similarity.rb +1 -3
  137. data/lib/rubocop/options.rb +15 -8
  138. data/lib/rubocop/path_util.rb +2 -17
  139. data/lib/rubocop/rake_task.rb +6 -9
  140. data/lib/rubocop/result_cache.rb +9 -5
  141. data/lib/rubocop/rspec/cop_helper.rb +4 -4
  142. data/lib/rubocop/rspec/expect_offense.rb +52 -22
  143. data/lib/rubocop/rspec/shared_contexts.rb +8 -8
  144. data/lib/rubocop/runner.rb +33 -32
  145. data/lib/rubocop/target_ruby.rb +1 -1
  146. data/lib/rubocop/version.rb +1 -1
  147. metadata +25 -8
  148. data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Lint
6
+ # This cop checks that there are no repeated conditions used in if 'elsif'.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # if x == 1
11
+ # do_something
12
+ # elsif x == 1
13
+ # do_something_else
14
+ # end
15
+ #
16
+ # # good
17
+ # if x == 1
18
+ # do_something
19
+ # elsif x == 2
20
+ # do_something_else
21
+ # end
22
+ #
23
+ class DuplicateElsifCondition < Base
24
+ MSG = 'Duplicate `elsif` condition detected.'
25
+
26
+ def on_if(node)
27
+ previous = []
28
+ while node.if? || node.elsif?
29
+ condition = node.condition
30
+ add_offense(condition) if previous.include?(condition)
31
+ previous << condition
32
+ node = node.else_branch
33
+ break unless node&.if_type?
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -126,7 +126,7 @@ module RuboCop
126
126
  end
127
127
 
128
128
  def message_for_dup(node, method_name)
129
- format(MSG, method: method_name, defined: @definitions[method_name],
129
+ format(MSG, method: method_name, defined: source_location(@definitions[method_name]),
130
130
  current: source_location(node))
131
131
  end
132
132
 
@@ -152,7 +152,7 @@ module RuboCop
152
152
 
153
153
  add_offense(node, location: loc, message: message)
154
154
  else
155
- @definitions[method_name] = source_location(node)
155
+ @definitions[method_name] = node
156
156
  end
157
157
  end
158
158
 
@@ -64,9 +64,10 @@ module RuboCop
64
64
 
65
65
  def ending_delimiter(str)
66
66
  # implicit string concatenation does not work with %{}, etc.
67
- if str.source[0] == "'"
67
+ case str.source[0]
68
+ when "'"
68
69
  "'"
69
- elsif str.source[0] == '"'
70
+ when '"'
70
71
  '"'
71
72
  end
72
73
  end
@@ -30,6 +30,19 @@ module RuboCop
30
30
  add_offense(node)
31
31
  end
32
32
 
33
+ def autocorrect(node)
34
+ lambda do |corrector|
35
+ starting_token, ending_token = if node.source.include?('"')
36
+ ['%{', '}']
37
+ else
38
+ ['"', '"']
39
+ end
40
+
41
+ corrector.replace(node.loc.begin, starting_token)
42
+ corrector.replace(node.loc.end, ending_token)
43
+ end
44
+ end
45
+
33
46
  def heredoc?(node)
34
47
  node.loc.is_a?(Parser::Source::Map::Heredoc) ||
35
48
  (node.parent && heredoc?(node.parent))
@@ -30,6 +30,8 @@ module RuboCop
30
30
  # break if condition
31
31
  # end
32
32
  class LiteralAsCondition < Cop
33
+ include RangeHelp
34
+
33
35
  MSG = 'Literal `%<literal>s` appeared as a condition.'
34
36
 
35
37
  def on_if(node)
@@ -57,7 +59,8 @@ module RuboCop
57
59
  case_node.each_when do |when_node|
58
60
  next unless when_node.conditions.all?(&:literal?)
59
61
 
60
- add_offense(when_node)
62
+ range = when_conditions_range(when_node)
63
+ add_offense(when_node, location: range, message: message(range))
61
64
  end
62
65
  end
63
66
  end
@@ -129,6 +132,13 @@ module RuboCop
129
132
  node.condition
130
133
  end
131
134
  end
135
+
136
+ def when_conditions_range(when_node)
137
+ range_between(
138
+ when_node.conditions.first.source_range.begin_pos,
139
+ when_node.conditions.last.source_range.end_pos
140
+ )
141
+ end
132
142
  end
133
143
  end
134
144
  end
@@ -59,31 +59,25 @@ module RuboCop
59
59
  'Use `lambda` instead.'
60
60
 
61
61
  def on_def(node)
62
- find_nested_defs(node) do |nested_def_node|
63
- add_offense(nested_def_node)
64
- end
65
- end
66
- alias on_defs on_def
67
-
68
- private
62
+ subject, = *node
63
+ return if node.defs_type? && subject.lvar_type?
69
64
 
70
- def find_nested_defs(node, &block)
71
- node.each_child_node do |child|
72
- if child.def_type?
73
- yield child
74
- elsif child.defs_type?
75
- subject, = *child
76
- next if subject.lvar_type?
65
+ def_ancestor = node.each_ancestor(:def, :defs).first
66
+ return unless def_ancestor
77
67
 
78
- yield child
79
- elsif !scoping_method_call?(child)
80
- find_nested_defs(child, &block)
68
+ within_scoping_def =
69
+ node.each_ancestor(:block, :sclass).any? do |ancestor|
70
+ scoping_method_call?(ancestor)
81
71
  end
82
- end
72
+
73
+ add_offense(node) if def_ancestor && !within_scoping_def
83
74
  end
75
+ alias on_defs on_def
76
+
77
+ private
84
78
 
85
79
  def scoping_method_call?(child)
86
- eval_call?(child) || exec_call?(child) || child.sclass_type? ||
80
+ child.sclass_type? || eval_call?(child) || exec_call?(child) ||
87
81
  class_or_module_or_struct_new_call?(child)
88
82
  end
89
83
 
@@ -96,7 +90,7 @@ module RuboCop
96
90
  PATTERN
97
91
 
98
92
  def_node_matcher :class_or_module_or_struct_new_call?, <<~PATTERN
99
- (block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
93
+ (block (send (const {nil? cbase} {:Class :Module :Struct}) :new ...) ...)
100
94
  PATTERN
101
95
  end
102
96
  end
@@ -69,11 +69,11 @@ module RuboCop
69
69
  end
70
70
 
71
71
  def_node_matcher :unsorted_dir_block?, <<~PATTERN
72
- (send (const nil? :Dir) :glob ...)
72
+ (send (const {nil? cbase} :Dir) :glob ...)
73
73
  PATTERN
74
74
 
75
75
  def_node_matcher :unsorted_dir_each?, <<~PATTERN
76
- (send (send (const nil? :Dir) {:[] :glob} ...) :each)
76
+ (send (send (const {nil? cbase} :Dir) {:[] :glob} ...) :each)
77
77
  PATTERN
78
78
 
79
79
  def_node_matcher :loop_variable, <<~PATTERN
@@ -48,17 +48,22 @@ module RuboCop
48
48
  return true
49
49
  end
50
50
 
51
- node.operator_method? || node.setter_method? || grouped_parentheses?(node)
51
+ node.operator_method? || node.setter_method? || chained_calls?(node) ||
52
+ operator_keyword?(node)
52
53
  end
53
54
 
54
55
  def first_argument_starts_with_left_parenthesis?(node)
55
56
  node.first_argument.source.start_with?('(')
56
57
  end
57
58
 
58
- def grouped_parentheses?(node)
59
+ def chained_calls?(node)
59
60
  first_argument = node.first_argument
61
+ first_argument.send_type? && (node.children.last&.children&.count || 0) > 1
62
+ end
60
63
 
61
- first_argument.send_type? && first_argument.receiver&.begin_type?
64
+ def operator_keyword?(node)
65
+ first_argument = node.first_argument
66
+ first_argument.operator_keyword?
62
67
  end
63
68
 
64
69
  def spaces_before_left_parenthesis(node)
@@ -44,6 +44,14 @@ module RuboCop
44
44
  exception_new_with_message?(node, &check(node))
45
45
  end
46
46
 
47
+ def autocorrect(node)
48
+ lambda do |corrector|
49
+ exception_class = node.children.first&.cbase_type? ? '::StandardError' : 'StandardError'
50
+
51
+ corrector.replace(node, exception_class)
52
+ end
53
+ end
54
+
47
55
  private
48
56
 
49
57
  def check(node)
@@ -25,7 +25,7 @@ module RuboCop
25
25
  'Perhaps you meant `rand(2)` or `rand`?'
26
26
 
27
27
  def_node_matcher :rand_one?, <<~PATTERN
28
- (send {(const nil? :Kernel) nil?} :rand {(int {-1 1}) (float {-1.0 1.0})})
28
+ (send {(const {nil? cbase} :Kernel) nil?} :rand {(int {-1 1}) (float {-1.0 1.0})})
29
29
  PATTERN
30
30
 
31
31
  def on_send(node)
@@ -25,34 +25,34 @@ module RuboCop
25
25
  #
26
26
  # # good
27
27
  # x += 1
28
- class RedundantCopDisableDirective < Cop
28
+ class RedundantCopDisableDirective < Base
29
29
  include RangeHelp
30
+ extend AutoCorrector
30
31
 
31
32
  COP_NAME = 'Lint/RedundantCopDisableDirective'
32
33
 
33
- def check(offenses, cop_disabled_line_ranges, comments)
34
+ attr_accessor :offenses_to_check
35
+
36
+ def initialize(config = nil, options = nil, offenses = nil)
37
+ @offenses_to_check = offenses
38
+ super(config, options)
39
+ end
40
+
41
+ def on_new_investigation
42
+ return unless offenses_to_check
43
+
44
+ comments = processed_source.comments
45
+ cop_disabled_line_ranges = processed_source.disabled_line_ranges
46
+
34
47
  redundant_cops = Hash.new { |h, k| h[k] = Set.new }
35
48
 
36
49
  each_redundant_disable(cop_disabled_line_ranges,
37
- offenses, comments) do |comment, redundant_cop|
50
+ offenses_to_check, comments) do |comment, redundant_cop|
38
51
  redundant_cops[comment].add(redundant_cop)
39
52
  end
40
53
 
41
54
  add_offenses(redundant_cops)
42
- end
43
-
44
- def autocorrect(args)
45
- lambda do |corrector|
46
- ranges, range = *args # Ranges are sorted by position.
47
-
48
- range = if range.source.start_with?('#')
49
- comment_range_with_surrounding_space(range)
50
- else
51
- directive_range_in_list(range, ranges)
52
- end
53
-
54
- corrector.remove(range)
55
- end
55
+ super
56
56
  end
57
57
 
58
58
  private
@@ -187,10 +187,12 @@ module RuboCop
187
187
  cop_list = cops.sort.map { |c| describe(c) }
188
188
 
189
189
  add_offense(
190
- [[location], location],
191
- location: location,
190
+ location,
192
191
  message: "Unnecessary disabling of #{cop_list.join(', ')}."
193
- )
192
+ ) do |corrector|
193
+ range = comment_range_with_surrounding_space(location)
194
+ corrector.remove(range)
195
+ end
194
196
  end
195
197
 
196
198
  def add_offense_for_some_cops(comment, cops)
@@ -200,10 +202,12 @@ module RuboCop
200
202
 
201
203
  cop_ranges.each do |cop, range|
202
204
  add_offense(
203
- [ranges, range],
204
- location: range,
205
+ range,
205
206
  message: "Unnecessary disabling of #{describe(cop)}."
206
- )
207
+ ) do |corrector|
208
+ range = directive_range_in_list(range, ranges)
209
+ corrector.remove(range)
210
+ end
207
211
  end
208
212
  end
209
213
 
@@ -60,8 +60,8 @@ module RuboCop
60
60
 
61
61
  def_node_matcher :array_new?, <<~PATTERN
62
62
  {
63
- $(send (const nil? :Array) :new ...)
64
- $(block (send (const nil? :Array) :new ...) ...)
63
+ $(send (const {nil? cbase} :Array) :new ...)
64
+ $(block (send (const {nil? cbase} :Array) :new ...) ...)
65
65
  }
66
66
  PATTERN
67
67
 
@@ -23,6 +23,12 @@ module RuboCop
23
23
  def on_match_current_line(node)
24
24
  add_offense(node)
25
25
  end
26
+
27
+ def autocorrect(node)
28
+ lambda do |corrector|
29
+ corrector.replace(node, "#{node.source} =~ $_")
30
+ end
31
+ end
26
32
  end
27
33
  end
28
34
  end
@@ -32,6 +32,14 @@ module RuboCop
32
32
 
33
33
  add_offense(node.condition)
34
34
  end
35
+
36
+ def autocorrect(node)
37
+ lambda do |corrector|
38
+ receiver = node.receiver.source
39
+
40
+ corrector.replace(node, "#{receiver} && #{receiver}.#{node.method_name}")
41
+ end
42
+ end
35
43
  end
36
44
  end
37
45
  end
@@ -3,49 +3,34 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Lint
6
- # This is not actually a cop. It does not inspect anything. It just
7
- # provides methods to repack Parser's diagnostics/errors
6
+ # This cop repacks Parser's diagnostics/errors
8
7
  # into RuboCop's offenses.
9
- class Syntax < Cop
10
- PseudoSourceRange = Struct.new(:line, :column, :source_line, :begin_pos,
11
- :end_pos)
12
-
13
- ERROR_SOURCE_RANGE = PseudoSourceRange.new(1, 0, '', 0, 1).freeze
14
-
15
- def self.offenses_from_processed_source(processed_source,
16
- config, options)
17
- cop = new(config, options)
18
-
19
- cop.add_offense_from_error(processed_source.parser_error) if processed_source.parser_error
20
-
8
+ class Syntax < Base
9
+ def on_other_file
10
+ add_offense_from_error(processed_source.parser_error) if processed_source.parser_error
21
11
  processed_source.diagnostics.each do |diagnostic|
22
- cop.add_offense_from_diagnostic(diagnostic,
23
- processed_source.ruby_version)
12
+ add_offense_from_diagnostic(diagnostic,
13
+ processed_source.ruby_version)
24
14
  end
25
-
26
- cop.offenses
15
+ super
27
16
  end
28
17
 
18
+ private
19
+
29
20
  def add_offense_from_diagnostic(diagnostic, ruby_version)
30
21
  message =
31
22
  "#{diagnostic.message}\n(Using Ruby #{ruby_version} parser; " \
32
23
  'configure using `TargetRubyVersion` parameter, under `AllCops`)'
33
- add_offense(nil,
34
- location: diagnostic.location,
24
+ add_offense(diagnostic.location,
35
25
  message: message,
36
26
  severity: diagnostic.level)
37
27
  end
38
28
 
39
29
  def add_offense_from_error(error)
40
30
  message = beautify_message(error.message)
41
- add_offense(nil,
42
- location: ERROR_SOURCE_RANGE,
43
- message: message,
44
- severity: :fatal)
31
+ add_global_offense(message, severity: :fatal)
45
32
  end
46
33
 
47
- private
48
-
49
34
  def beautify_message(message)
50
35
  message = message.capitalize
51
36
  message << '.' unless message.end_with?('.')
@@ -62,7 +62,7 @@ module RuboCop
62
62
  include UnusedArgument
63
63
 
64
64
  def_node_matcher :not_implemented?, <<~PATTERN
65
- {(send nil? :raise (const nil? :NotImplementedError))
65
+ {(send nil? :raise (const {nil? cbase} :NotImplementedError))
66
66
  (send nil? :fail ...)}
67
67
  PATTERN
68
68
 
@@ -172,7 +172,7 @@ module RuboCop
172
172
  PATTERN
173
173
 
174
174
  def_node_matcher :class_or_module_or_struct_new_call?, <<~PATTERN
175
- (block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
175
+ (block (send (const {nil? cbase} {:Class :Module :Struct}) :new ...) ...)
176
176
  PATTERN
177
177
 
178
178
  def check_node(node)