rubocop 1.14.0 → 1.18.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 (98) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/config/default.yml +120 -34
  4. data/lib/rubocop.rb +8 -0
  5. data/lib/rubocop/cli/command/suggest_extensions.rb +3 -3
  6. data/lib/rubocop/config_loader.rb +1 -1
  7. data/lib/rubocop/config_validator.rb +5 -5
  8. data/lib/rubocop/cop/base.rb +2 -2
  9. data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
  10. data/lib/rubocop/cop/bundler/gem_version.rb +38 -4
  11. data/lib/rubocop/cop/corrector.rb +4 -4
  12. data/lib/rubocop/cop/generator.rb +1 -1
  13. data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -1
  14. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
  15. data/lib/rubocop/cop/layout/argument_alignment.rb +30 -12
  16. data/lib/rubocop/cop/layout/array_alignment.rb +2 -2
  17. data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
  18. data/lib/rubocop/cop/layout/case_indentation.rb +57 -9
  19. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +7 -1
  20. data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
  21. data/lib/rubocop/cop/layout/dot_position.rb +7 -1
  22. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +13 -15
  23. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -2
  24. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +14 -2
  25. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
  26. data/lib/rubocop/cop/layout/hash_alignment.rb +40 -14
  27. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -1
  28. data/lib/rubocop/cop/layout/indentation_width.rb +13 -2
  29. data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +122 -0
  30. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +6 -6
  31. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +2 -2
  32. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +6 -6
  33. data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +6 -6
  34. data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +6 -6
  35. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +3 -3
  36. data/lib/rubocop/cop/layout/parameter_alignment.rb +2 -2
  37. data/lib/rubocop/cop/layout/redundant_line_break.rb +11 -9
  38. data/lib/rubocop/cop/layout/space_around_keyword.rb +28 -0
  39. data/lib/rubocop/cop/layout/space_around_operators.rb +7 -1
  40. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -0
  41. data/lib/rubocop/cop/lint/empty_block.rb +18 -2
  42. data/lib/rubocop/cop/lint/empty_in_pattern.rb +62 -0
  43. data/lib/rubocop/cop/lint/literal_as_condition.rb +13 -1
  44. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +32 -17
  45. data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
  46. data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
  47. data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
  48. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +105 -74
  49. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -0
  50. data/lib/rubocop/cop/lint/symbol_conversion.rb +3 -13
  51. data/lib/rubocop/cop/lint/unused_block_argument.rb +1 -1
  52. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -1
  53. data/lib/rubocop/cop/lint/void.rb +1 -1
  54. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
  55. data/lib/rubocop/cop/migration/department_name.rb +3 -1
  56. data/lib/rubocop/cop/mixin/check_line_breakable.rb +28 -3
  57. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +6 -0
  58. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +14 -3
  59. data/lib/rubocop/cop/mixin/string_literals_help.rb +2 -4
  60. data/lib/rubocop/cop/mixin/symbol_help.rb +13 -0
  61. data/lib/rubocop/cop/naming/inclusive_language.rb +249 -0
  62. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -2
  63. data/lib/rubocop/cop/style/class_and_module_children.rb +28 -2
  64. data/lib/rubocop/cop/style/empty_literal.rb +8 -1
  65. data/lib/rubocop/cop/style/hash_each_methods.rb +18 -1
  66. data/lib/rubocop/cop/style/identical_conditional_branches.rb +58 -8
  67. data/lib/rubocop/cop/style/in_pattern_then.rb +56 -0
  68. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -1
  69. data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +62 -0
  70. data/lib/rubocop/cop/style/multiline_when_then.rb +2 -11
  71. data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
  72. data/lib/rubocop/cop/style/nil_lambda.rb +29 -12
  73. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
  74. data/lib/rubocop/cop/style/quoted_symbols.rb +110 -0
  75. data/lib/rubocop/cop/style/raise_args.rb +2 -0
  76. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  77. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
  78. data/lib/rubocop/cop/style/redundant_self.rb +24 -2
  79. data/lib/rubocop/cop/style/regexp_literal.rb +10 -1
  80. data/lib/rubocop/cop/style/special_global_vars.rb +3 -3
  81. data/lib/rubocop/cop/style/string_concatenation.rb +32 -5
  82. data/lib/rubocop/cop/style/string_literals.rb +3 -2
  83. data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +1 -0
  84. data/lib/rubocop/cop/style/swap_values.rb +1 -1
  85. data/lib/rubocop/cop/style/top_level_method_definition.rb +83 -0
  86. data/lib/rubocop/cop/style/trivial_accessors.rb +65 -0
  87. data/lib/rubocop/cop/style/unpack_first.rb +1 -1
  88. data/lib/rubocop/cop/style/when_then.rb +6 -2
  89. data/lib/rubocop/cop/variable_force/variable_table.rb +1 -1
  90. data/lib/rubocop/directive_comment.rb +58 -6
  91. data/lib/rubocop/formatter/junit_formatter.rb +21 -6
  92. data/lib/rubocop/options.rb +18 -24
  93. data/lib/rubocop/rake_task.rb +1 -1
  94. data/lib/rubocop/remote_config.rb +10 -2
  95. data/lib/rubocop/rspec/cop_helper.rb +1 -1
  96. data/lib/rubocop/rspec/expect_offense.rb +1 -1
  97. data/lib/rubocop/version.rb +1 -1
  98. metadata +13 -5
@@ -22,9 +22,13 @@ module RuboCop
22
22
  testsuites = REXML::Element.new('testsuites', @document)
23
23
  testsuite = REXML::Element.new('testsuite', testsuites)
24
24
  @testsuite = testsuite.tap { |element| element.add_attributes('name' => 'rubocop') }
25
+
26
+ reset_count
25
27
  end
26
28
 
27
29
  def file_finished(file, offenses)
30
+ @inspected_file_count += 1
31
+
28
32
  # TODO: Returns all cops with the same behavior as
29
33
  # the original rubocop-junit-formatter.
30
34
  # https://github.com/mikian/rubocop-junit-formatter/blob/v0.1.4/lib/rubocop/formatter/junit_formatter.rb#L9
@@ -32,15 +36,11 @@ module RuboCop
32
36
  # In the future, it would be preferable to return only enabled cops.
33
37
  Cop::Registry.all.each do |cop|
34
38
  target_offenses = offenses_for_cop(offenses, cop)
39
+ @offense_count += target_offenses.count
35
40
 
36
41
  next unless relevant_for_output?(options, target_offenses)
37
42
 
38
- REXML::Element.new('testcase', @testsuite).tap do |testcase|
39
- testcase.attributes['classname'] = classname_attribute_value(file)
40
- testcase.attributes['name'] = cop.cop_name
41
-
42
- add_failure_to(testcase, target_offenses, cop.cop_name)
43
- end
43
+ add_testcase_element_to_testsuite_element(file, target_offenses, cop)
44
44
  end
45
45
  end
46
46
 
@@ -52,16 +52,31 @@ module RuboCop
52
52
  all_offenses.select { |offense| offense.cop_name == cop.cop_name }
53
53
  end
54
54
 
55
+ def add_testcase_element_to_testsuite_element(file, target_offenses, cop)
56
+ REXML::Element.new('testcase', @testsuite).tap do |testcase|
57
+ testcase.attributes['classname'] = classname_attribute_value(file)
58
+ testcase.attributes['name'] = cop.cop_name
59
+
60
+ add_failure_to(testcase, target_offenses, cop.cop_name)
61
+ end
62
+ end
63
+
55
64
  def classname_attribute_value(file)
56
65
  file.gsub(/\.rb\Z/, '').gsub("#{Dir.pwd}/", '').tr('/', '.')
57
66
  end
58
67
 
59
68
  def finished(_inspected_files)
69
+ @testsuite.add_attributes('tests' => @inspected_file_count, 'failures' => @offense_count)
60
70
  @document.write(output, 2)
61
71
  end
62
72
 
63
73
  private
64
74
 
75
+ def reset_count
76
+ @inspected_file_count = 0
77
+ @offense_count = 0
78
+ end
79
+
65
80
  def add_failure_to(testcase, offenses, cop_name)
66
81
  # One failure per offense. Zero failures is a passing test case,
67
82
  # for most surefire/nUnit parsers.
@@ -12,9 +12,9 @@ module RuboCop
12
12
  # @api private
13
13
  class Options
14
14
  E_STDIN_NO_PATH = '-s/--stdin requires exactly one path, relative to the ' \
15
- 'root of the project. RuboCop will use this path to determine which ' \
16
- 'cops are enabled (via eg. Include/Exclude), and so that certain cops ' \
17
- 'like Naming/FileName can be checked.'
15
+ 'root of the project. RuboCop will use this path to determine which ' \
16
+ 'cops are enabled (via eg. Include/Exclude), and so that certain cops ' \
17
+ 'like Naming/FileName can be checked.'
18
18
  EXITING_OPTIONS = %i[version verbose_version show_cops].freeze
19
19
  DEFAULT_MAXIMUM_EXCLUSION_ITEMS = 15
20
20
 
@@ -292,12 +292,12 @@ module RuboCop
292
292
 
293
293
  if display_only_fail_level_offenses_with_autocorrect?
294
294
  raise OptionArgumentError, '--autocorrect cannot be used with ' \
295
- '--display-only-fail-level-offenses'
295
+ '--display-only-fail-level-offenses'
296
296
  end
297
297
  validate_auto_gen_config
298
298
  validate_auto_correct
299
299
  validate_display_only_failed
300
- validate_parallel
300
+ disable_parallel_when_invalid_option_combo
301
301
 
302
302
  return if incompatible_options.size <= 1
303
303
 
@@ -334,33 +334,27 @@ module RuboCop
334
334
  format('--disable-uncorrectable can only be used together with --auto-correct.')
335
335
  end
336
336
 
337
- def validate_parallel
337
+ def disable_parallel_when_invalid_option_combo
338
338
  return unless @options.key?(:parallel)
339
339
 
340
- if @options[:cache] == 'false'
341
- raise OptionArgumentError, '-P/--parallel uses caching to speed up ' \
342
- 'execution, so combining with --cache ' \
343
- 'false is not allowed.'
344
- end
345
-
346
- disable_parallel_when_invalid_combo
347
- end
340
+ invalid_options = [
341
+ { name: :auto_gen_config, value: true, flag: '--auto-gen-config' },
342
+ { name: :fail_fast, value: true, flag: '-F/--fail-fast.' },
343
+ { name: :auto_correct, value: true, flag: '--auto-correct.' },
344
+ { name: :cache, value: 'false', flag: '--cache false' }
345
+ ]
348
346
 
349
- def disable_parallel_when_invalid_combo
350
- combos = {
351
- auto_gen_config: '--auto-gen-config',
352
- fail_fast: '-F/--fail-fast.',
353
- auto_correct: '--auto-correct.'
354
- }
355
-
356
- invalid_combos = combos.select { |key, _flag| @options.key?(key) }
347
+ invalid_flags = invalid_options.each_with_object([]) do |option, flags|
348
+ # `>` rather than `>=` because `@options` will also contain `parallel: true`
349
+ flags << option[:flag] if @options > { option[:name] => option[:value] }
350
+ end
357
351
 
358
- return if invalid_combos.empty?
352
+ return if invalid_flags.empty?
359
353
 
360
354
  @options.delete(:parallel)
361
355
 
362
356
  puts '-P/--parallel is being ignored because ' \
363
- "it is not compatible with #{invalid_combos.values.join(', ')}"
357
+ "it is not compatible with #{invalid_flags.join(', ')}"
364
358
  end
365
359
 
366
360
  def only_includes_redundant_disable?
@@ -70,7 +70,7 @@ module RuboCop
70
70
  options = full_options.unshift('--auto-correct-all')
71
71
  # `parallel` will automatically be removed from the options internally.
72
72
  # This is a nice to have to suppress the warning message
73
- # about parallel and auto-corrent not being compatible.
73
+ # about parallel and auto-correct not being compatible.
74
74
  options.delete('--parallel')
75
75
  run_cli(verbose, options)
76
76
  end
@@ -55,6 +55,7 @@ module RuboCop
55
55
  def generate_request(uri)
56
56
  request = Net::HTTP::Get.new(uri.request_uri)
57
57
 
58
+ request.basic_auth(uri.user, uri.password) if uri.user
58
59
  request['If-Modified-Since'] = File.stat(cache_path).mtime.rfc2822 if cache_path_exists?
59
60
 
60
61
  yield request
@@ -70,7 +71,7 @@ module RuboCop
70
71
  begin
71
72
  response.error!
72
73
  rescue StandardError => e
73
- message = "#{e.message} while downloading remote config file #{uri}"
74
+ message = "#{e.message} while downloading remote config file #{cloned_url}"
74
75
  raise e, message
75
76
  end
76
77
  end
@@ -94,9 +95,16 @@ module RuboCop
94
95
  end
95
96
 
96
97
  def cache_name_from_uri
97
- uri = @uri.clone
98
+ uri = cloned_url
98
99
  uri.query = nil
99
100
  uri.to_s.gsub!(/[^0-9A-Za-z]/, '-')
100
101
  end
102
+
103
+ def cloned_url
104
+ uri = @uri.clone
105
+ uri.user = nil if uri.user
106
+ uri.password = nil if uri.password
107
+ uri
108
+ end
101
109
  end
102
110
  end
@@ -15,7 +15,7 @@ module CopHelper
15
15
  processed_source = parse_source(source, file)
16
16
  unless processed_source.valid_syntax?
17
17
  raise 'Error parsing example code: ' \
18
- "#{processed_source.diagnostics.map(&:render).join("\n")}"
18
+ "#{processed_source.diagnostics.map(&:render).join("\n")}"
19
19
  end
20
20
 
21
21
  _investigate(cop, processed_source)
@@ -195,7 +195,7 @@ module RuboCop
195
195
  return processed_source if processed_source.valid_syntax?
196
196
 
197
197
  raise 'Error parsing example code: ' \
198
- "#{processed_source.diagnostics.map(&:render).join("\n")}"
198
+ "#{processed_source.diagnostics.map(&:render).join("\n")}"
199
199
  end
200
200
 
201
201
  def set_formatter_options
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.14.0'
6
+ STRING = '1.18.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: 1.14.0
4
+ version: 1.18.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: 2021-05-05 00:00:00.000000000 Z
13
+ date: 2021-06-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel
@@ -100,7 +100,7 @@ dependencies:
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 1.5.0
103
+ version: 1.7.0
104
104
  - - "<"
105
105
  - !ruby/object:Gem::Version
106
106
  version: '2.0'
@@ -110,7 +110,7 @@ dependencies:
110
110
  requirements:
111
111
  - - ">="
112
112
  - !ruby/object:Gem::Version
113
- version: 1.5.0
113
+ version: 1.7.0
114
114
  - - "<"
115
115
  - !ruby/object:Gem::Version
116
116
  version: '2.0'
@@ -319,6 +319,7 @@ files:
319
319
  - lib/rubocop/cop/layout/initial_indentation.rb
320
320
  - lib/rubocop/cop/layout/leading_comment_space.rb
321
321
  - lib/rubocop/cop/layout/leading_empty_lines.rb
322
+ - lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb
322
323
  - lib/rubocop/cop/layout/line_length.rb
323
324
  - lib/rubocop/cop/layout/multiline_array_brace_layout.rb
324
325
  - lib/rubocop/cop/layout/multiline_array_line_breaks.rb
@@ -397,6 +398,7 @@ files:
397
398
  - lib/rubocop/cop/lint/empty_ensure.rb
398
399
  - lib/rubocop/cop/lint/empty_expression.rb
399
400
  - lib/rubocop/cop/lint/empty_file.rb
401
+ - lib/rubocop/cop/lint/empty_in_pattern.rb
400
402
  - lib/rubocop/cop/lint/empty_interpolation.rb
401
403
  - lib/rubocop/cop/lint/empty_when.rb
402
404
  - lib/rubocop/cop/lint/ensure_return.rb
@@ -562,6 +564,7 @@ files:
562
564
  - lib/rubocop/cop/mixin/string_help.rb
563
565
  - lib/rubocop/cop/mixin/string_literals_help.rb
564
566
  - lib/rubocop/cop/mixin/surrounding_space.rb
567
+ - lib/rubocop/cop/mixin/symbol_help.rb
565
568
  - lib/rubocop/cop/mixin/target_ruby_version.rb
566
569
  - lib/rubocop/cop/mixin/trailing_body.rb
567
570
  - lib/rubocop/cop/mixin/trailing_comma.rb
@@ -577,6 +580,7 @@ files:
577
580
  - lib/rubocop/cop/naming/file_name.rb
578
581
  - lib/rubocop/cop/naming/heredoc_delimiter_case.rb
579
582
  - lib/rubocop/cop/naming/heredoc_delimiter_naming.rb
583
+ - lib/rubocop/cop/naming/inclusive_language.rb
580
584
  - lib/rubocop/cop/naming/memoized_instance_variable_name.rb
581
585
  - lib/rubocop/cop/naming/method_name.rb
582
586
  - lib/rubocop/cop/naming/method_parameter_name.rb
@@ -676,6 +680,7 @@ files:
676
680
  - lib/rubocop/cop/style/if_with_boolean_literal_branches.rb
677
681
  - lib/rubocop/cop/style/if_with_semicolon.rb
678
682
  - lib/rubocop/cop/style/implicit_runtime_error.rb
683
+ - lib/rubocop/cop/style/in_pattern_then.rb
679
684
  - lib/rubocop/cop/style/infinite_loop.rb
680
685
  - lib/rubocop/cop/style/inline_comment.rb
681
686
  - lib/rubocop/cop/style/inverse_methods.rb
@@ -699,6 +704,7 @@ files:
699
704
  - lib/rubocop/cop/style/multiline_block_chain.rb
700
705
  - lib/rubocop/cop/style/multiline_if_modifier.rb
701
706
  - lib/rubocop/cop/style/multiline_if_then.rb
707
+ - lib/rubocop/cop/style/multiline_in_pattern_then.rb
702
708
  - lib/rubocop/cop/style/multiline_memoization.rb
703
709
  - lib/rubocop/cop/style/multiline_method_signature.rb
704
710
  - lib/rubocop/cop/style/multiline_ternary_operator.rb
@@ -732,6 +738,7 @@ files:
732
738
  - lib/rubocop/cop/style/perl_backrefs.rb
733
739
  - lib/rubocop/cop/style/preferred_hash_methods.rb
734
740
  - lib/rubocop/cop/style/proc.rb
741
+ - lib/rubocop/cop/style/quoted_symbols.rb
735
742
  - lib/rubocop/cop/style/raise_args.rb
736
743
  - lib/rubocop/cop/style/random_with_offset.rb
737
744
  - lib/rubocop/cop/style/redundant_argument.rb
@@ -786,6 +793,7 @@ files:
786
793
  - lib/rubocop/cop/style/symbol_literal.rb
787
794
  - lib/rubocop/cop/style/symbol_proc.rb
788
795
  - lib/rubocop/cop/style/ternary_parentheses.rb
796
+ - lib/rubocop/cop/style/top_level_method_definition.rb
789
797
  - lib/rubocop/cop/style/trailing_body_on_class.rb
790
798
  - lib/rubocop/cop/style/trailing_body_on_method_definition.rb
791
799
  - lib/rubocop/cop/style/trailing_body_on_module.rb
@@ -875,7 +883,7 @@ metadata:
875
883
  homepage_uri: https://rubocop.org/
876
884
  changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
877
885
  source_code_uri: https://github.com/rubocop/rubocop/
878
- documentation_uri: https://docs.rubocop.org/rubocop/1.14/
886
+ documentation_uri: https://docs.rubocop.org/rubocop/1.18/
879
887
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
880
888
  post_install_message:
881
889
  rdoc_options: []