rubocop 0.85.0 → 0.88.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -17
  3. data/bin/rubocop-profile +31 -0
  4. data/config/default.yml +132 -11
  5. data/lib/rubocop.rb +17 -1
  6. data/lib/rubocop/cli.rb +2 -4
  7. data/lib/rubocop/cli/command/auto_genenerate_config.rb +42 -7
  8. data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
  9. data/lib/rubocop/cli/command/show_cops.rb +1 -1
  10. data/lib/rubocop/config.rb +1 -1
  11. data/lib/rubocop/config_loader.rb +39 -67
  12. data/lib/rubocop/config_loader_resolver.rb +1 -1
  13. data/lib/rubocop/config_obsoletion.rb +0 -1
  14. data/lib/rubocop/config_store.rb +4 -0
  15. data/lib/rubocop/cop/autocorrect_logic.rb +14 -24
  16. data/lib/rubocop/cop/badge.rb +1 -1
  17. data/lib/rubocop/cop/base.rb +407 -0
  18. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
  19. data/lib/rubocop/cop/commissioner.rb +48 -50
  20. data/lib/rubocop/cop/cop.rb +91 -235
  21. data/lib/rubocop/cop/corrector.rb +38 -115
  22. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +26 -0
  23. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +7 -2
  24. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
  25. data/lib/rubocop/cop/generator.rb +1 -1
  26. data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
  27. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
  28. data/lib/rubocop/cop/layout/case_indentation.rb +18 -19
  29. data/lib/rubocop/cop/layout/class_structure.rb +2 -37
  30. data/lib/rubocop/cop/layout/comment_indentation.rb +3 -3
  31. data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
  32. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -0
  33. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +3 -8
  34. data/lib/rubocop/cop/layout/end_alignment.rb +3 -2
  35. data/lib/rubocop/cop/layout/end_of_line.rb +1 -1
  36. data/lib/rubocop/cop/layout/first_argument_indentation.rb +5 -1
  37. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
  38. data/lib/rubocop/cop/layout/hash_alignment.rb +2 -3
  39. data/lib/rubocop/cop/layout/heredoc_indentation.rb +1 -1
  40. data/lib/rubocop/cop/layout/multiline_block_layout.rb +17 -7
  41. data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
  42. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +22 -27
  43. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  44. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +27 -68
  45. data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
  46. data/lib/rubocop/cop/layout/space_before_block_braces.rb +14 -0
  47. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +4 -3
  48. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
  49. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
  50. data/lib/rubocop/cop/legacy/corrections_proxy.rb +49 -0
  51. data/lib/rubocop/cop/legacy/corrector.rb +29 -0
  52. data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
  53. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +4 -4
  54. data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +8 -2
  55. data/lib/rubocop/cop/lint/duplicate_elsif_condition.rb +39 -0
  56. data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -2
  57. data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
  58. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +38 -2
  59. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +3 -2
  60. data/lib/rubocop/cop/lint/interpolation_check.rb +13 -0
  61. data/lib/rubocop/cop/lint/literal_as_condition.rb +11 -1
  62. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +8 -1
  63. data/lib/rubocop/cop/lint/nested_method_definition.rb +14 -20
  64. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +69 -2
  65. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +8 -3
  66. data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
  67. data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
  68. data/lib/rubocop/cop/lint/raise_exception.rb +12 -4
  69. data/lib/rubocop/cop/lint/rand_one.rb +1 -1
  70. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +31 -25
  71. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
  72. data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
  73. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +9 -1
  74. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  75. data/lib/rubocop/cop/lint/syntax.rb +11 -26
  76. data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
  77. data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -1
  78. data/lib/rubocop/cop/metrics/block_length.rb +22 -0
  79. data/lib/rubocop/cop/metrics/class_length.rb +25 -2
  80. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +35 -3
  81. data/lib/rubocop/cop/metrics/method_length.rb +23 -0
  82. data/lib/rubocop/cop/metrics/module_length.rb +25 -2
  83. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
  84. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +129 -0
  85. data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
  86. data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
  87. data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
  88. data/lib/rubocop/cop/mixin/code_length.rb +4 -0
  89. data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -1
  90. data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
  91. data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
  92. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
  93. data/lib/rubocop/cop/mixin/enforce_superclass.rb +3 -1
  94. data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
  95. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  96. data/lib/rubocop/cop/mixin/nil_methods.rb +3 -5
  97. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +6 -1
  98. data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
  99. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
  100. data/lib/rubocop/cop/mixin/range_help.rb +1 -1
  101. data/lib/rubocop/cop/mixin/regexp_literal_help.rb +27 -0
  102. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -3
  103. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
  104. data/lib/rubocop/cop/mixin/surrounding_space.rb +10 -5
  105. data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -13
  106. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  107. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +6 -4
  108. data/lib/rubocop/cop/mixin/visibility_help.rb +50 -0
  109. data/lib/rubocop/cop/naming/ascii_identifiers.rb +27 -4
  110. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +3 -3
  111. data/lib/rubocop/cop/naming/file_name.rb +1 -3
  112. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
  113. data/lib/rubocop/cop/naming/method_name.rb +1 -1
  114. data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
  115. data/lib/rubocop/cop/naming/predicate_name.rb +3 -5
  116. data/lib/rubocop/cop/naming/variable_name.rb +1 -1
  117. data/lib/rubocop/cop/naming/variable_number.rb +1 -1
  118. data/lib/rubocop/cop/offense.rb +16 -2
  119. data/lib/rubocop/cop/registry.rb +62 -7
  120. data/lib/rubocop/cop/style/accessor_grouping.rb +147 -0
  121. data/lib/rubocop/cop/style/array_coercion.rb +63 -0
  122. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +3 -2
  123. data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
  124. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +146 -0
  125. data/lib/rubocop/cop/style/block_delimiters.rb +2 -4
  126. data/lib/rubocop/cop/style/case_like_if.rb +217 -0
  127. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  128. data/lib/rubocop/cop/style/class_vars.rb +21 -0
  129. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  130. data/lib/rubocop/cop/style/commented_keyword.rb +5 -2
  131. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
  132. data/lib/rubocop/cop/style/copyright.rb +3 -3
  133. data/lib/rubocop/cop/style/date_time.rb +1 -1
  134. data/lib/rubocop/cop/style/dir.rb +2 -2
  135. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
  136. data/lib/rubocop/cop/style/documentation.rb +2 -2
  137. data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
  138. data/lib/rubocop/cop/style/empty_literal.rb +5 -5
  139. data/lib/rubocop/cop/style/encoding.rb +1 -1
  140. data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
  141. data/lib/rubocop/cop/style/exponential_notation.rb +8 -10
  142. data/lib/rubocop/cop/style/float_division.rb +7 -10
  143. data/lib/rubocop/cop/style/format_string_token.rb +5 -5
  144. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  145. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +62 -0
  146. data/lib/rubocop/cop/style/hash_like_case.rb +76 -0
  147. data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
  148. data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
  149. data/lib/rubocop/cop/style/if_unless_modifier.rb +11 -11
  150. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -0
  151. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  152. data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
  153. data/lib/rubocop/cop/style/missing_else.rb +1 -11
  154. data/lib/rubocop/cop/style/multiline_block_chain.rb +10 -1
  155. data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
  156. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +17 -6
  157. data/lib/rubocop/cop/style/mutable_constant.rb +4 -4
  158. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -5
  159. data/lib/rubocop/cop/style/nested_ternary_operator.rb +27 -0
  160. data/lib/rubocop/cop/style/next.rb +2 -2
  161. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
  162. data/lib/rubocop/cop/style/numeric_predicate.rb +3 -4
  163. data/lib/rubocop/cop/style/parallel_assignment.rb +3 -3
  164. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
  165. data/lib/rubocop/cop/style/proc.rb +1 -1
  166. data/lib/rubocop/cop/style/random_with_offset.rb +4 -10
  167. data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
  168. data/lib/rubocop/cop/style/redundant_conditional.rb +4 -3
  169. data/lib/rubocop/cop/style/redundant_exception.rb +14 -10
  170. data/lib/rubocop/cop/style/redundant_fetch_block.rb +122 -0
  171. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +50 -0
  172. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  173. data/lib/rubocop/cop/style/redundant_parentheses.rb +8 -2
  174. data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
  175. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +4 -3
  176. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +14 -23
  177. data/lib/rubocop/cop/style/redundant_self.rb +6 -9
  178. data/lib/rubocop/cop/style/redundant_sort.rb +3 -2
  179. data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
  180. data/lib/rubocop/cop/style/sample.rb +1 -1
  181. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  182. data/lib/rubocop/cop/style/signal_exception.rb +1 -1
  183. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +3 -2
  184. data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
  185. data/lib/rubocop/cop/style/struct_inheritance.rb +23 -2
  186. data/lib/rubocop/cop/style/symbol_array.rb +5 -5
  187. data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
  188. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  189. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +9 -32
  190. data/lib/rubocop/cop/style/trivial_accessors.rb +8 -7
  191. data/lib/rubocop/cop/style/word_array.rb +1 -1
  192. data/lib/rubocop/cop/style/yoda_condition.rb +18 -1
  193. data/lib/rubocop/cop/style/zero_length_predicate.rb +2 -2
  194. data/lib/rubocop/cop/team.rb +105 -81
  195. data/lib/rubocop/cop/util.rb +2 -2
  196. data/lib/rubocop/cop/utils/format_string.rb +19 -2
  197. data/lib/rubocop/cop/variable_force/variable.rb +5 -3
  198. data/lib/rubocop/file_finder.rb +12 -12
  199. data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -2
  200. data/lib/rubocop/formatter/formatter_set.rb +1 -1
  201. data/lib/rubocop/name_similarity.rb +7 -3
  202. data/lib/rubocop/options.rb +15 -8
  203. data/lib/rubocop/path_util.rb +4 -19
  204. data/lib/rubocop/platform.rb +1 -1
  205. data/lib/rubocop/rake_task.rb +6 -9
  206. data/lib/rubocop/result_cache.rb +12 -8
  207. data/lib/rubocop/rspec/cop_helper.rb +4 -4
  208. data/lib/rubocop/rspec/expect_offense.rb +65 -21
  209. data/lib/rubocop/rspec/shared_contexts.rb +19 -16
  210. data/lib/rubocop/runner.rb +34 -33
  211. data/lib/rubocop/target_finder.rb +3 -3
  212. data/lib/rubocop/target_ruby.rb +2 -2
  213. data/lib/rubocop/version.rb +1 -1
  214. metadata +34 -9
  215. data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'tmpdir'
4
- require 'fileutils'
5
4
 
6
5
  RSpec.shared_context 'isolated environment', :isolated_environment do
7
6
  around do |example|
@@ -13,19 +12,22 @@ RSpec.shared_context 'isolated environment', :isolated_environment do
13
12
  # get mismatched pathnames when loading config files later on.
14
13
  tmpdir = File.realpath(tmpdir)
15
14
 
15
+ virtual_home = File.expand_path(File.join(tmpdir, 'home'))
16
+ Dir.mkdir(virtual_home)
17
+ ENV['HOME'] = virtual_home
18
+ ENV.delete('XDG_CONFIG_HOME')
19
+
20
+ base_dir = example.metadata[:project_inside_home] ? virtual_home : tmpdir
21
+ root = example.metadata[:root]
22
+ working_dir = root ? File.join(base_dir, 'work', root) : File.join(base_dir, 'work')
23
+
16
24
  # Make upwards search for .rubocop.yml files stop at this directory.
17
- RuboCop::FileFinder.root_level = tmpdir
25
+ RuboCop::FileFinder.root_level = working_dir
18
26
 
19
27
  begin
20
- virtual_home = File.expand_path(File.join(tmpdir, 'home'))
21
- Dir.mkdir(virtual_home)
22
- ENV['HOME'] = virtual_home
23
- ENV.delete('XDG_CONFIG_HOME')
28
+ FileUtils.mkdir_p(working_dir)
24
29
 
25
- working_dir = File.join(tmpdir, 'work')
26
- Dir.mkdir(working_dir)
27
-
28
- RuboCop::PathUtil.chdir(working_dir) do
30
+ Dir.chdir(working_dir) do
29
31
  example.run
30
32
  end
31
33
  ensure
@@ -45,11 +47,11 @@ RSpec.shared_context 'config', :config do # rubocop:disable Metrics/BlockLength
45
47
  let(:source) { 'code = {some: :ruby}' }
46
48
 
47
49
  let(:cop_class) do
48
- if described_class.is_a?(Class) && described_class < RuboCop::Cop::Cop
49
- described_class
50
- else
51
- RuboCop::Cop::Cop
50
+ unless described_class.is_a?(Class) && described_class < RuboCop::Cop::Base
51
+ raise 'Specify which cop class to use (e.g `let(:cop_class) { RuboCop::Cop::Base }`, ' \
52
+ 'or RuboCop::Cop::Cop for legacy)'
52
53
  end
54
+ described_class
53
55
  end
54
56
 
55
57
  let(:cop_config) { {} }
@@ -95,8 +97,9 @@ RSpec.shared_context 'config', :config do # rubocop:disable Metrics/BlockLength
95
97
  end
96
98
 
97
99
  let(:cop) do
98
- cop_class.new(config, cop_options)
99
- .tap { |cop| cop.processed_source = processed_source }
100
+ cop_class.new(config, cop_options).tap do |cop|
101
+ cop.send :begin_investigation, processed_source
102
+ end
100
103
  end
101
104
  end
102
105
 
@@ -118,9 +118,9 @@ module RuboCop
118
118
 
119
119
  def file_offenses(file)
120
120
  file_offense_cache(file) do
121
- source = get_processed_source(file)
122
- source, offenses = do_inspection_loop(file, source)
123
- add_redundant_disables(file, offenses.compact.sort, source)
121
+ source, offenses = do_inspection_loop(file)
122
+ offenses = add_redundant_disables(file, offenses.compact.sort, source)
123
+ offenses.sort.reject(&:disabled?).freeze
124
124
  end
125
125
  end
126
126
 
@@ -151,16 +151,29 @@ module RuboCop
151
151
  end
152
152
 
153
153
  def add_redundant_disables(file, offenses, source)
154
- if check_for_redundant_disables?(source)
155
- redundant_cop_disable_directive(file) do |cop|
156
- cop.check(offenses, source.disabled_line_ranges, source.comments)
157
- offenses += cop.offenses
158
- offenses += autocorrect_redundant_disables(file, source, cop,
159
- offenses)
154
+ team_for_redundant_disables(file, offenses, source) do |team|
155
+ new_offenses, redundant_updated = inspect_file(source, team)
156
+ offenses += new_offenses
157
+ if redundant_updated
158
+ # Do one extra inspection loop if any redundant disables were
159
+ # removed. This is done in order to find rubocop:enable directives that
160
+ # have now become useless.
161
+ _source, new_offenses = do_inspection_loop(file)
162
+ offenses |= new_offenses
160
163
  end
161
164
  end
165
+ offenses
166
+ end
162
167
 
163
- offenses.sort.reject(&:disabled?).freeze
168
+ def team_for_redundant_disables(file, offenses, source)
169
+ return unless check_for_redundant_disables?(source)
170
+
171
+ config = @config_store.for_file(file)
172
+ team = Cop::Team.mobilize([Cop::Lint::RedundantCopDisableDirective], config, @options)
173
+ return if team.cops.empty?
174
+
175
+ team.cops.first.offenses_to_check = offenses
176
+ yield team
164
177
  end
165
178
 
166
179
  def check_for_redundant_disables?(source)
@@ -180,22 +193,6 @@ module RuboCop
180
193
  @options[:except] || @options[:only]
181
194
  end
182
195
 
183
- def autocorrect_redundant_disables(file, source, cop, offenses)
184
- cop.processed_source = source
185
-
186
- team = Cop::Team.mobilize(RuboCop::Cop::Registry.new, nil, @options)
187
- team.autocorrect(source.buffer, [cop])
188
-
189
- return [] unless team.updated_source_file?
190
-
191
- # Do one extra inspection loop if any redundant disables were
192
- # removed. This is done in order to find rubocop:enable directives that
193
- # have now become useless.
194
- _source, new_offenses = do_inspection_loop(file,
195
- get_processed_source(file))
196
- new_offenses - offenses
197
- end
198
-
199
196
  def file_started(file)
200
197
  puts "Scanning #{file}" if @options[:debug]
201
198
  formatter_set.file_started(file,
@@ -214,7 +211,7 @@ module RuboCop
214
211
  @cached_run ||=
215
212
  (@options[:cache] == 'true' ||
216
213
  @options[:cache] != 'false' &&
217
- @config_store.for_dir(Dir.pwd).for_all_cops['UseCache']) &&
214
+ @config_store.for_pwd.for_all_cops['UseCache']) &&
218
215
  # When running --auto-gen-config, there's some processing done in the
219
216
  # cops related to calculating the Max parameters for Metrics cops. We
220
217
  # need to do that processing and cannot use caching.
@@ -233,7 +230,8 @@ module RuboCop
233
230
  cache.save(offenses)
234
231
  end
235
232
 
236
- def do_inspection_loop(file, processed_source)
233
+ def do_inspection_loop(file)
234
+ processed_source = get_processed_source(file)
237
235
  offenses = []
238
236
 
239
237
  # When running with --auto-correct, we need to inspect the file (which
@@ -293,13 +291,16 @@ module RuboCop
293
291
  @processed_sources << checksum
294
292
  end
295
293
 
296
- def inspect_file(processed_source)
297
- config = @config_store.for_file(processed_source.path)
298
- team = Cop::Team.mobilize(mobilized_cop_classes(config), config, @options)
299
- offenses = team.inspect_file(processed_source)
294
+ def inspect_file(processed_source, team = mobilize_team(processed_source))
295
+ report = team.investigate(processed_source)
300
296
  @errors.concat(team.errors)
301
297
  @warnings.concat(team.warnings)
302
- [offenses, team.updated_source_file?]
298
+ [report.offenses, team.updated_source_file?]
299
+ end
300
+
301
+ def mobilize_team(processed_source)
302
+ config = @config_store.for_file(processed_source.path)
303
+ Cop::Team.mobilize(mobilized_cop_classes(config), config, @options)
303
304
  end
304
305
 
305
306
  def mobilized_cop_classes(config)
@@ -132,14 +132,14 @@ module RuboCop
132
132
  end
133
133
 
134
134
  def all_cops_include
135
- @config_store.for('.').for_all_cops['Include'].map(&:to_s)
135
+ @config_store.for_pwd.for_all_cops['Include'].map(&:to_s)
136
136
  end
137
137
 
138
138
  def ruby_executable?(file)
139
139
  return false unless File.extname(file).empty? && File.exist?(file)
140
140
 
141
141
  first_line = File.open(file, &:readline)
142
- !(first_line =~ /#!.*(#{ruby_interpreters(file).join('|')})/).nil?
142
+ /#!.*(#{ruby_interpreters(file).join('|')})/.match?(first_line)
143
143
  rescue EOFError, ArgumentError => e
144
144
  warn("Unprocessable file #{file}: #{e.class}, #{e.message}") if debug?
145
145
 
@@ -160,7 +160,7 @@ module RuboCop
160
160
  end
161
161
 
162
162
  def configured_include?(file)
163
- @config_store.for('.').file_to_include?(file)
163
+ @config_store.for_pwd.file_to_include?(file)
164
164
  end
165
165
 
166
166
  def included_file?(file)
@@ -3,11 +3,11 @@
3
3
  module RuboCop
4
4
  # The kind of Ruby that code inspected by RuboCop is written in.
5
5
  class TargetRuby
6
- KNOWN_RUBIES = [2.4, 2.5, 2.6, 2.7].freeze
6
+ KNOWN_RUBIES = [2.4, 2.5, 2.6, 2.7, 2.8].freeze
7
7
  DEFAULT_VERSION = KNOWN_RUBIES.first
8
8
 
9
9
  OBSOLETE_RUBIES = {
10
- 1.9 => '0.50', 2.0 => '0.50', 2.1 => '0.58', 2.2 => '0.69', 2.3 => '0.81'
10
+ 1.9 => '0.41', 2.0 => '0.50', 2.1 => '0.57', 2.2 => '0.68', 2.3 => '0.81'
11
11
  }.freeze
12
12
  private_constant :KNOWN_RUBIES, :OBSOLETE_RUBIES
13
13
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '0.85.0'
6
+ STRING = '0.88.0'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.85.0
4
+ version: 0.88.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-06-01 00:00:00.000000000 Z
13
+ date: 2020-07-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel
@@ -32,14 +32,14 @@ dependencies:
32
32
  requirements:
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: 2.7.0.1
35
+ version: 2.7.1.1
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 2.7.0.1
42
+ version: 2.7.1.1
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rainbow
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -94,14 +94,20 @@ dependencies:
94
94
  requirements:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
- version: 0.0.3
97
+ version: 0.1.0
98
+ - - "<"
99
+ - !ruby/object:Gem::Version
100
+ version: '1.0'
98
101
  type: :runtime
99
102
  prerelease: false
100
103
  version_requirements: !ruby/object:Gem::Requirement
101
104
  requirements:
102
105
  - - ">="
103
106
  - !ruby/object:Gem::Version
104
- version: 0.0.3
107
+ version: 0.1.0
108
+ - - "<"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
105
111
  - !ruby/object:Gem::Dependency
106
112
  name: ruby-progressbar
107
113
  requirement: !ruby/object:Gem::Requirement
@@ -157,8 +163,8 @@ dependencies:
157
163
  - !ruby/object:Gem::Version
158
164
  version: '3.0'
159
165
  description: |2
160
- Automatic Ruby code style checking tool.
161
- Aims to enforce the community-driven Ruby Style Guide.
166
+ RuboCop is a Ruby code style checking and code formatting tool.
167
+ It aims to enforce the community-driven Ruby Style Guide.
162
168
  email: rubocop@googlegroups.com
163
169
  executables:
164
170
  - rubocop
@@ -172,6 +178,7 @@ files:
172
178
  - assets/logo.png
173
179
  - assets/output.html.erb
174
180
  - bin/console
181
+ - bin/rubocop-profile
175
182
  - bin/setup
176
183
  - config/default.yml
177
184
  - exe/rubocop
@@ -196,6 +203,7 @@ files:
196
203
  - lib/rubocop/config_validator.rb
197
204
  - lib/rubocop/cop/autocorrect_logic.rb
198
205
  - lib/rubocop/cop/badge.rb
206
+ - lib/rubocop/cop/base.rb
199
207
  - lib/rubocop/cop/bundler/duplicated_gem.rb
200
208
  - lib/rubocop/cop/bundler/gem_comment.rb
201
209
  - lib/rubocop/cop/bundler/insecure_protocol_source.rb
@@ -325,6 +333,8 @@ files:
325
333
  - lib/rubocop/cop/layout/space_inside_string_interpolation.rb
326
334
  - lib/rubocop/cop/layout/trailing_empty_lines.rb
327
335
  - lib/rubocop/cop/layout/trailing_whitespace.rb
336
+ - lib/rubocop/cop/legacy/corrections_proxy.rb
337
+ - lib/rubocop/cop/legacy/corrector.rb
328
338
  - lib/rubocop/cop/lint/ambiguous_block_association.rb
329
339
  - lib/rubocop/cop/lint/ambiguous_operator.rb
330
340
  - lib/rubocop/cop/lint/ambiguous_regexp_literal.rb
@@ -332,11 +342,13 @@ files:
332
342
  - lib/rubocop/cop/lint/big_decimal_new.rb
333
343
  - lib/rubocop/cop/lint/boolean_symbol.rb
334
344
  - lib/rubocop/cop/lint/circular_argument_reference.rb
345
+ - lib/rubocop/cop/lint/constant_resolution.rb
335
346
  - lib/rubocop/cop/lint/debugger.rb
336
347
  - lib/rubocop/cop/lint/deprecated_class_methods.rb
337
348
  - lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb
338
349
  - lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb
339
350
  - lib/rubocop/cop/lint/duplicate_case_condition.rb
351
+ - lib/rubocop/cop/lint/duplicate_elsif_condition.rb
340
352
  - lib/rubocop/cop/lint/duplicate_hash_key.rb
341
353
  - lib/rubocop/cop/lint/duplicate_methods.rb
342
354
  - lib/rubocop/cop/lint/each_with_object_argument.rb
@@ -421,14 +433,17 @@ files:
421
433
  - lib/rubocop/cop/metrics/parameter_lists.rb
422
434
  - lib/rubocop/cop/metrics/perceived_complexity.rb
423
435
  - lib/rubocop/cop/metrics/utils/abc_size_calculator.rb
436
+ - lib/rubocop/cop/metrics/utils/code_length_calculator.rb
437
+ - lib/rubocop/cop/metrics/utils/iterating_block.rb
424
438
  - lib/rubocop/cop/migration/department_name.rb
425
439
  - lib/rubocop/cop/mixin/alignment.rb
440
+ - lib/rubocop/cop/mixin/allowed_methods.rb
426
441
  - lib/rubocop/cop/mixin/annotation_comment.rb
427
442
  - lib/rubocop/cop/mixin/array_min_size.rb
428
443
  - lib/rubocop/cop/mixin/array_syntax.rb
444
+ - lib/rubocop/cop/mixin/auto_corrector.rb
429
445
  - lib/rubocop/cop/mixin/check_assignment.rb
430
446
  - lib/rubocop/cop/mixin/check_line_breakable.rb
431
- - lib/rubocop/cop/mixin/classish_length.rb
432
447
  - lib/rubocop/cop/mixin/code_length.rb
433
448
  - lib/rubocop/cop/mixin/configurable_enforced_style.rb
434
449
  - lib/rubocop/cop/mixin/configurable_formatting.rb
@@ -487,6 +502,7 @@ files:
487
502
  - lib/rubocop/cop/mixin/trailing_comma.rb
488
503
  - lib/rubocop/cop/mixin/uncommunicative_name.rb
489
504
  - lib/rubocop/cop/mixin/unused_argument.rb
505
+ - lib/rubocop/cop/mixin/visibility_help.rb
490
506
  - lib/rubocop/cop/naming/accessor_method_name.rb
491
507
  - lib/rubocop/cop/naming/ascii_identifiers.rb
492
508
  - lib/rubocop/cop/naming/binary_operator_parameter_name.rb
@@ -512,17 +528,21 @@ files:
512
528
  - lib/rubocop/cop/security/yaml_load.rb
513
529
  - lib/rubocop/cop/severity.rb
514
530
  - lib/rubocop/cop/style/access_modifier_declarations.rb
531
+ - lib/rubocop/cop/style/accessor_grouping.rb
515
532
  - lib/rubocop/cop/style/alias.rb
516
533
  - lib/rubocop/cop/style/and_or.rb
534
+ - lib/rubocop/cop/style/array_coercion.rb
517
535
  - lib/rubocop/cop/style/array_join.rb
518
536
  - lib/rubocop/cop/style/ascii_comments.rb
519
537
  - lib/rubocop/cop/style/attr.rb
520
538
  - lib/rubocop/cop/style/auto_resource_cleanup.rb
521
539
  - lib/rubocop/cop/style/bare_percent_literals.rb
522
540
  - lib/rubocop/cop/style/begin_block.rb
541
+ - lib/rubocop/cop/style/bisected_attr_accessor.rb
523
542
  - lib/rubocop/cop/style/block_comments.rb
524
543
  - lib/rubocop/cop/style/block_delimiters.rb
525
544
  - lib/rubocop/cop/style/case_equality.rb
545
+ - lib/rubocop/cop/style/case_like_if.rb
526
546
  - lib/rubocop/cop/style/character_literal.rb
527
547
  - lib/rubocop/cop/style/class_and_module_children.rb
528
548
  - lib/rubocop/cop/style/class_check.rb
@@ -566,7 +586,9 @@ files:
566
586
  - lib/rubocop/cop/style/frozen_string_literal_comment.rb
567
587
  - lib/rubocop/cop/style/global_vars.rb
568
588
  - lib/rubocop/cop/style/guard_clause.rb
589
+ - lib/rubocop/cop/style/hash_as_last_array_item.rb
569
590
  - lib/rubocop/cop/style/hash_each_methods.rb
591
+ - lib/rubocop/cop/style/hash_like_case.rb
570
592
  - lib/rubocop/cop/style/hash_syntax.rb
571
593
  - lib/rubocop/cop/style/hash_transform_keys.rb
572
594
  - lib/rubocop/cop/style/hash_transform_values.rb
@@ -631,11 +653,14 @@ files:
631
653
  - lib/rubocop/cop/style/proc.rb
632
654
  - lib/rubocop/cop/style/raise_args.rb
633
655
  - lib/rubocop/cop/style/random_with_offset.rb
656
+ - lib/rubocop/cop/style/redundant_assignment.rb
634
657
  - lib/rubocop/cop/style/redundant_begin.rb
635
658
  - lib/rubocop/cop/style/redundant_capital_w.rb
636
659
  - lib/rubocop/cop/style/redundant_condition.rb
637
660
  - lib/rubocop/cop/style/redundant_conditional.rb
638
661
  - lib/rubocop/cop/style/redundant_exception.rb
662
+ - lib/rubocop/cop/style/redundant_fetch_block.rb
663
+ - lib/rubocop/cop/style/redundant_file_extension_in_require.rb
639
664
  - lib/rubocop/cop/style/redundant_freeze.rb
640
665
  - lib/rubocop/cop/style/redundant_interpolation.rb
641
666
  - lib/rubocop/cop/style/redundant_parentheses.rb
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- # Common functionality for checking length of classes and modules.
6
- module ClassishLength
7
- include CodeLength
8
-
9
- private
10
-
11
- def code_length(node)
12
- body_line_numbers = line_range(node).to_a[1...-1]
13
-
14
- target_line_numbers = body_line_numbers -
15
- line_numbers_of_inner_nodes(node, :module, :class)
16
-
17
- target_line_numbers.reduce(0) do |length, line_number|
18
- source_line = processed_source[line_number]
19
- next length if irrelevant_line(source_line)
20
-
21
- length + 1
22
- end
23
- end
24
-
25
- def line_numbers_of_inner_nodes(node, *types)
26
- line_numbers = Set.new
27
-
28
- node.each_descendant(*types) do |inner_node|
29
- line_range = line_range(inner_node)
30
- line_numbers.merge(line_range)
31
- end
32
-
33
- line_numbers.to_a
34
- end
35
- end
36
- end
37
- end