rubocop 0.91.1 → 0.92.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3c2093a4cd4b9f214ecef0ecf755abf1fcdcef137aaf5cd2c088537cfa3a7e6
4
- data.tar.gz: e470d985cba7af81cfae61f82b5cc52fde7b8e1bceb1993af84db21bb370b592
3
+ metadata.gz: 682e17739f5c067f13eb30a3e84b365533bb0e075da92a40529c943e5a67e3b0
4
+ data.tar.gz: 2c7e59ef470ad45515bed37249c97419181add1f451379d00b31ff45b21ddd36
5
5
  SHA512:
6
- metadata.gz: bb916e735bfbdc7063f730d0a0407a3bb3037b2ccb1c0166b73fdc08e887f47f45aa95ab02bd2540404868c3afa48e77b3a2efaa0c93333fc61a6ae12c4ba275
7
- data.tar.gz: b70b264424f19e87a194bbfe370c368806b398be3b6efba1f420ae980d3c0ac1c50d3fd736571bd1933aaa38d81b083a47abb7c10167d972667b2234ec3dba84
6
+ metadata.gz: 0bc3d0c3238795b8563b974c99c20d3cfb34dff97bc33f5231d6ef7497f53ce6f4753923bce17954fe30e69b0a8d4146a3b1377d0489e7f10bc97a0b3c69ae7b
7
+ data.tar.gz: 4131b9c8a874e09d8c0581a04e91b44acc76855afa565cd52a324055a0bd7e1a40d37bc532b8b3781c9af9847335c6596ca8ed17fe9bff03d13283171d77c168
data/README.md CHANGED
@@ -49,7 +49,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
49
49
  might want to use a conservative version lock in your `Gemfile`:
50
50
 
51
51
  ```rb
52
- gem 'rubocop', '~> 0.91.1', require: false
52
+ gem 'rubocop', '~> 0.92.0', require: false
53
53
  ```
54
54
 
55
55
  ## Quickstart
@@ -2463,7 +2463,7 @@ Style/ArrayCoercion:
2463
2463
  with a variable you want to treat as an Array, but you're not certain it's an array.
2464
2464
  StyleGuide: '#array-coercion'
2465
2465
  Safe: false
2466
- Enabled: 'pending'
2466
+ Enabled: false
2467
2467
  VersionAdded: '0.88'
2468
2468
 
2469
2469
  Style/ArrayJoin:
@@ -2863,7 +2863,8 @@ Style/DateTime:
2863
2863
  StyleGuide: '#date--time'
2864
2864
  Enabled: false
2865
2865
  VersionAdded: '0.51'
2866
- VersionChanged: '0.59'
2866
+ VersionChanged: '0.92'
2867
+ SafeAutoCorrect: false
2867
2868
  AllowCoercion: false
2868
2869
 
2869
2870
  Style/DefWithParentheses:
@@ -3725,6 +3726,8 @@ Style/OptionalBooleanParameter:
3725
3726
  Enabled: pending
3726
3727
  Safe: false
3727
3728
  VersionAdded: '0.89'
3729
+ AllowedMethods:
3730
+ - respond_to_missing?
3728
3731
 
3729
3732
  Style/OrAssignment:
3730
3733
  Description: 'Recommend usage of double pipe equals (||=) where applicable.'
@@ -8,12 +8,14 @@ require 'set'
8
8
  require 'forwardable'
9
9
  require 'regexp_parser'
10
10
  require 'unicode/display_width/no_string_ext'
11
+
12
+ # we have to require RuboCop's version, before rubocop-ast's
13
+ require_relative 'rubocop/version'
11
14
  require 'rubocop-ast'
15
+
12
16
  require_relative 'rubocop/ast_aliases'
13
17
  require_relative 'rubocop/ext/regexp_node'
14
18
 
15
- require_relative 'rubocop/version'
16
-
17
19
  require_relative 'rubocop/core_ext/string'
18
20
  require_relative 'rubocop/ext/processed_source'
19
21
 
@@ -628,6 +630,7 @@ require_relative 'rubocop/cli/command/execute_runner'
628
630
  require_relative 'rubocop/cli/command/init_dotfile'
629
631
  require_relative 'rubocop/cli/command/show_cops'
630
632
  require_relative 'rubocop/cli/command/version'
633
+ require_relative 'rubocop/config_regeneration'
631
634
  require_relative 'rubocop/options'
632
635
  require_relative 'rubocop/remote_config'
633
636
  require_relative 'rubocop/target_ruby'
@@ -636,3 +639,4 @@ require_relative 'rubocop/yaml_duplication_checker'
636
639
  unless File.exist?("#{__dir__}/../rubocop.gemspec") # Check if we are a gem
637
640
  RuboCop::ResultCache.rubocop_required_features = $LOADED_FEATURES - before_us
638
641
  end
642
+ RuboCop::AST.rubocop_loaded if RuboCop::AST.respond_to?(:rubocop_loaded)
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ # This class handles collecting the options for regenerating a TODO file.
5
+ # @api private
6
+ class ConfigRegeneration
7
+ AUTO_GENERATED_FILE = RuboCop::CLI::Command::AutoGenerateConfig::AUTO_GENERATED_FILE
8
+ COMMAND_REGEX = /(?<=`rubocop )(.*?)(?=`)/.freeze
9
+ DEFAULT_OPTIONS = { auto_gen_config: true }.freeze
10
+
11
+ # Get options from the comment in the TODO file, and parse them as options
12
+ def options
13
+ # If there's no existing TODO file, generate one
14
+ return DEFAULT_OPTIONS unless todo_exists?
15
+
16
+ match = generation_command.match(COMMAND_REGEX)
17
+ return DEFAULT_OPTIONS unless match
18
+
19
+ options = match[1].split(' ')
20
+ Options.new.parse(options).first
21
+ end
22
+
23
+ private
24
+
25
+ def todo_exists?
26
+ File.exist?(AUTO_GENERATED_FILE) && !File.empty?(AUTO_GENERATED_FILE)
27
+ end
28
+
29
+ def generation_command
30
+ File.foreach(AUTO_GENERATED_FILE).take(2).last
31
+ end
32
+ end
33
+ end
@@ -44,6 +44,7 @@ module RuboCop
44
44
 
45
45
  def on_array(node)
46
46
  return if node.children.size < 2
47
+ return if node.parent&.masgn_type?
47
48
 
48
49
  check_alignment(node.children, base_column(node, node.children))
49
50
  end
@@ -5,6 +5,10 @@ module RuboCop
5
5
  module Style
6
6
  # This cop enforces the use of `Array()` instead of explicit `Array` check or `[*var]`.
7
7
  #
8
+ # This cop is disabled by default because false positive will occur if
9
+ # the argument of `Array()` is not an array (e.g. Hash, Set),
10
+ # an array will be returned as an incompatibility result.
11
+ #
8
12
  # @example
9
13
  # # bad
10
14
  # paths = [paths] unless paths.is_a?(Array)
@@ -42,6 +42,8 @@ module RuboCop
42
42
  # # good
43
43
  # something.to_time
44
44
  class DateTime < Base
45
+ extend AutoCorrector
46
+
45
47
  CLASS_MSG = 'Prefer Time over DateTime.'
46
48
  COERCION_MSG = 'Do not use #to_datetime.'
47
49
 
@@ -63,7 +65,10 @@ module RuboCop
63
65
  return if historic_date?(node)
64
66
 
65
67
  message = to_datetime?(node) ? COERCION_MSG : CLASS_MSG
66
- add_offense(node, message: message)
68
+
69
+ add_offense(node, message: message) do |corrector|
70
+ autocorrect(corrector, node)
71
+ end
67
72
  end
68
73
 
69
74
  private
@@ -71,6 +76,12 @@ module RuboCop
71
76
  def disallow_coercion?
72
77
  !cop_config['AllowCoercion']
73
78
  end
79
+
80
+ def autocorrect(corrector, node)
81
+ return if to_datetime?(node)
82
+
83
+ corrector.replace(node.receiver.loc.name, 'Time')
84
+ end
74
85
  end
75
86
  end
76
87
  end
@@ -50,41 +50,21 @@ module RuboCop
50
50
  const)
51
51
  PATTERN
52
52
 
53
- def_node_matcher :wrapped_macro_scope?, <<~PATTERN
54
- {({sclass class module block} ... ({begin if} ...))}
53
+ def_node_matcher :in_top_level_scope?, <<~PATTERN
54
+ {
55
+ root? # either at the top level
56
+ ^[ {kwbegin begin if def} # or wrapped within one of these
57
+ #in_top_level_scope? ] # that is in top level scope
58
+ }
55
59
  PATTERN
56
60
 
57
61
  def on_send(node)
58
62
  include_statement(node) do |statement|
59
- return if node.argument? ||
60
- accepted_include?(node) ||
61
- belongs_to_class_or_module?(node)
63
+ return unless in_top_level_scope?(node)
62
64
 
63
65
  add_offense(node, message: format(MSG, statement: statement))
64
66
  end
65
67
  end
66
-
67
- private
68
-
69
- def accepted_include?(node)
70
- node.parent && (node.macro? || ascend_macro_scope?(node.parent))
71
- end
72
-
73
- def ascend_macro_scope?(ancestor)
74
- return true if wrapped_macro_scope?(ancestor)
75
-
76
- ancestor.parent && ascend_macro_scope?(ancestor.parent)
77
- end
78
-
79
- def belongs_to_class_or_module?(node)
80
- if !node.parent
81
- false
82
- else
83
- return true if node.parent.class_type? || node.parent.module_type?
84
-
85
- belongs_to_class_or_module?(node.parent)
86
- end
87
- end
88
68
  end
89
69
  end
90
70
  end
@@ -4,7 +4,8 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  # This cop checks for places where keyword arguments can be used instead of
7
- # boolean arguments when defining methods.
7
+ # boolean arguments when defining methods. `respond_to_missing?` method is allowed by default.
8
+ # These are customizable with `AllowedMethods` option.
8
9
  #
9
10
  # @example
10
11
  # # bad
@@ -23,13 +24,20 @@ module RuboCop
23
24
  # puts bar
24
25
  # end
25
26
  #
27
+ # @example AllowedMethods: ['some_method']
28
+ # # good
29
+ # def some_method(bar = false)
30
+ # puts bar
31
+ # end
32
+ #
26
33
  class OptionalBooleanParameter < Base
34
+ include AllowedMethods
35
+
27
36
  MSG = 'Use keyword arguments when defining method with boolean argument.'
28
37
  BOOLEAN_TYPES = %i[true false].freeze
29
- METHODS_EXCLUDED = %i[respond_to_missing?].freeze
30
38
 
31
39
  def on_def(node)
32
- return if METHODS_EXCLUDED.include?(node.method_name)
40
+ return if allowed_method?(node.method_name)
33
41
 
34
42
  node.arguments.each do |arg|
35
43
  next unless arg.optarg_type?
@@ -32,7 +32,6 @@ module RuboCop
32
32
  @exclude_limit_option = @options[:exclude_limit]
33
33
  @exclude_limit = Integer(@exclude_limit_option ||
34
34
  RuboCop::Options::DEFAULT_MAXIMUM_EXCLUSION_ITEMS)
35
- @show_offense_counts = !@options[:no_offense_counts]
36
35
  end
37
36
 
38
37
  def file_finished(file, offenses)
@@ -56,6 +55,14 @@ module RuboCop
56
55
 
57
56
  private
58
57
 
58
+ def show_timestamp?
59
+ @options.fetch(:auto_gen_timestamp, true)
60
+ end
61
+
62
+ def show_offense_counts?
63
+ @options.fetch(:offense_counts, true)
64
+ end
65
+
59
66
  def command
60
67
  command = 'rubocop --auto-gen-config'
61
68
 
@@ -66,15 +73,15 @@ module RuboCop
66
73
  format(' --exclude-limit %<limit>d',
67
74
  limit: Integer(@exclude_limit_option))
68
75
  end
69
- command += ' --no-offense-counts' if @options[:no_offense_counts]
76
+ command += ' --no-offense-counts' unless show_offense_counts?
70
77
 
71
- command += ' --no-auto-gen-timestamp' if @options[:no_auto_gen_timestamp]
78
+ command += ' --no-auto-gen-timestamp' unless show_timestamp?
72
79
 
73
80
  command
74
81
  end
75
82
 
76
83
  def timestamp
77
- @options[:no_auto_gen_timestamp] ? '' : "on #{Time.now.utc} "
84
+ show_timestamp? ? "on #{Time.now.utc} " : ''
78
85
  end
79
86
 
80
87
  def output_offenses
@@ -112,7 +119,7 @@ module RuboCop
112
119
  end
113
120
 
114
121
  def output_cop_comments(output_buffer, cfg, cop_name, offense_count)
115
- output_buffer.puts "# Offense count: #{offense_count}" if @show_offense_counts
122
+ output_buffer.puts "# Offense count: #{offense_count}" if show_offense_counts?
116
123
 
117
124
  cop_class = Cop::Registry.global.find_by_cop_name(cop_name)
118
125
  output_buffer.puts '# Cop supports --auto-correct.' if cop_class&.support_autocorrect?
@@ -114,20 +114,19 @@ module RuboCop
114
114
  def add_auto_gen_options(opts)
115
115
  option(opts, '--auto-gen-config')
116
116
 
117
+ option(opts, '--regenerate-todo') do
118
+ @options.replace(ConfigRegeneration.new.options.merge(@options))
119
+ end
120
+
117
121
  option(opts, '--exclude-limit COUNT') do
118
122
  @validator.validate_exclude_limit_option
119
123
  end
120
124
 
121
125
  option(opts, '--disable-uncorrectable')
122
126
 
123
- option(opts, '--no-offense-counts') do
124
- @options[:no_offense_counts] = true
125
- end
126
-
127
- option(opts, '--auto-gen-only-exclude')
128
- option(opts, '--no-auto-gen-timestamp') do
129
- @options[:no_auto_gen_timestamp] = true
130
- end
127
+ option(opts, '--[no-]offense-counts')
128
+ option(opts, '--[no-]auto-gen-only-exclude')
129
+ option(opts, '--[no-]auto-gen-timestamp')
131
130
 
132
131
  option(opts, '--init')
133
132
  end
@@ -318,7 +317,7 @@ module RuboCop
318
317
 
319
318
  message = '--%<flag>s can only be used together with --auto-gen-config.'
320
319
 
321
- %i[exclude_limit no_offense_counts no_auto_gen_timestamp
320
+ %i[exclude_limit offense_counts auto_gen_timestamp
322
321
  auto_gen_only_exclude].each do |option|
323
322
  if @options.key?(option)
324
323
  raise OptionArgumentError,
@@ -423,17 +422,20 @@ module RuboCop
423
422
  config: 'Specify configuration file.',
424
423
  auto_gen_config: ['Generate a configuration file acting as a',
425
424
  'TODO list.'],
426
- no_offense_counts: ['Do not include offense counts in configuration',
427
- 'file generated by --auto-gen-config.'],
428
- no_auto_gen_timestamp:
429
- ['Do not include the date and time when',
430
- 'the --auto-gen-config was run in the file it',
431
- 'generates.'],
425
+ regenerate_todo: ['Regenerate the TODO configuration file using',
426
+ 'the last configuration. If there is no existing',
427
+ 'TODO file, acts like --auto-gen-config.'],
428
+ offense_counts: ['Include offense counts in configuration',
429
+ 'file generated by --auto-gen-config.',
430
+ 'Default is true.'],
431
+ auto_gen_timestamp:
432
+ ['Include the date and time when the --auto-gen-config',
433
+ 'was run in the file it generates. Default is true.'],
432
434
  auto_gen_only_exclude:
433
435
  ['Generate only Exclude parameters and not Max',
434
436
  'when running --auto-gen-config, except if the',
435
437
  'number of files with offenses is bigger than',
436
- 'exclude-limit.'],
438
+ 'exclude-limit. Default is false.'],
437
439
  exclude_limit: ['Used together with --auto-gen-config to',
438
440
  'set the limit for how many Exclude',
439
441
  "properties to generate. Default is #{MAX_EXCL}."],
@@ -133,14 +133,14 @@ module RuboCop
133
133
  "#{@processed_source.diagnostics.map(&:render).join("\n")}"
134
134
  end
135
135
 
136
- offenses = _investigate(cop, @processed_source)
136
+ @offenses = _investigate(cop, @processed_source)
137
137
  actual_annotations =
138
- expected_annotations.with_offense_annotations(offenses)
138
+ expected_annotations.with_offense_annotations(@offenses)
139
139
 
140
140
  expect(actual_annotations).to eq(expected_annotations), ''
141
- expect(offenses.map(&:severity).uniq).to eq([severity]) if severity
141
+ expect(@offenses.map(&:severity).uniq).to eq([severity]) if severity
142
142
 
143
- offenses
143
+ @offenses
144
144
  end
145
145
 
146
146
  def expect_correction(correction, loop: true)
@@ -157,7 +157,7 @@ module RuboCop
157
157
  break corrected_source if corrected_source == @processed_source.buffer.source
158
158
 
159
159
  if iteration > RuboCop::Runner::MAX_ITERATIONS
160
- raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [])
160
+ raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [@offenses])
161
161
  end
162
162
 
163
163
  # Prepare for next loop
@@ -16,7 +16,11 @@ module RuboCop
16
16
  root_cause = offenses_by_iteration[loop_start..-1]
17
17
  .map { |x| x.map(&:cop_name).uniq.join(', ') }
18
18
  .join(' -> ')
19
- super "Infinite loop detected in #{path} and caused by #{root_cause}"
19
+
20
+ message = 'Infinite loop detected'
21
+ message += " in #{path}" if path
22
+ message += " and caused by #{root_cause}" if root_cause
23
+ super message
20
24
  end
21
25
  end
22
26
 
@@ -5,6 +5,8 @@ module RuboCop
5
5
  # and picking ruby files.
6
6
  # @api private
7
7
  class TargetFinder
8
+ HIDDEN_PATH_SUBSTRING = "#{File::SEPARATOR}."
9
+
8
10
  def initialize(config_store, options = {})
9
11
  @config_store = config_store
10
12
  @options = options
@@ -55,7 +57,8 @@ module RuboCop
55
57
  # Support Windows: Backslashes from command-line -> forward slashes
56
58
  base_dir = base_dir.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
57
59
  all_files = find_files(base_dir, File::FNM_DOTMATCH)
58
- hidden_files = Set.new(all_files - find_files(base_dir, 0))
60
+ # use file.include? for performance optimization
61
+ hidden_files = all_files.select { |file| file.include?(HIDDEN_PATH_SUBSTRING) }
59
62
  base_dir_config = @config_store.for(base_dir)
60
63
 
61
64
  target_files = all_files.select do |file|
@@ -4,7 +4,7 @@ module RuboCop
4
4
  # The kind of Ruby that code inspected by RuboCop is written in.
5
5
  # @api private
6
6
  class TargetRuby
7
- KNOWN_RUBIES = [2.4, 2.5, 2.6, 2.7, 2.8].freeze
7
+ KNOWN_RUBIES = [2.4, 2.5, 2.6, 2.7, 3.0].freeze
8
8
  DEFAULT_VERSION = KNOWN_RUBIES.first
9
9
 
10
10
  OBSOLETE_RUBIES = {
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '0.91.1'
6
+ STRING = '0.92.0'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
@@ -20,5 +20,10 @@ module RuboCop
20
20
  STRING
21
21
  end
22
22
  end
23
+
24
+ # @api private
25
+ def self.document_version
26
+ STRING.match('\d+\.\d+').to_s
27
+ end
23
28
  end
24
29
  end
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.91.1
4
+ version: 0.92.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-09-23 00:00:00.000000000 Z
13
+ date: 2020-09-25 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.1.1
35
+ version: 2.7.1.5
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.1.1
42
+ version: 2.7.1.5
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rainbow
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -94,20 +94,14 @@ dependencies:
94
94
  requirements:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
- version: 0.4.0
98
- - - "<"
99
- - !ruby/object:Gem::Version
100
- version: '1.0'
97
+ version: 0.5.0
101
98
  type: :runtime
102
99
  prerelease: false
103
100
  version_requirements: !ruby/object:Gem::Requirement
104
101
  requirements:
105
102
  - - ">="
106
103
  - !ruby/object:Gem::Version
107
- version: 0.4.0
108
- - - "<"
109
- - !ruby/object:Gem::Version
110
- version: '1.0'
104
+ version: 0.5.0
111
105
  - !ruby/object:Gem::Dependency
112
106
  name: ruby-progressbar
113
107
  requirement: !ruby/object:Gem::Requirement
@@ -199,6 +193,7 @@ files:
199
193
  - lib/rubocop/config_loader.rb
200
194
  - lib/rubocop/config_loader_resolver.rb
201
195
  - lib/rubocop/config_obsoletion.rb
196
+ - lib/rubocop/config_regeneration.rb
202
197
  - lib/rubocop/config_store.rb
203
198
  - lib/rubocop/config_validator.rb
204
199
  - lib/rubocop/cop/autocorrect_logic.rb
@@ -808,7 +803,7 @@ metadata:
808
803
  homepage_uri: https://rubocop.org/
809
804
  changelog_uri: https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md
810
805
  source_code_uri: https://github.com/rubocop-hq/rubocop/
811
- documentation_uri: https://docs.rubocop.org/
806
+ documentation_uri: https://docs.rubocop.org/rubocop/0.92/
812
807
  bug_tracker_uri: https://github.com/rubocop-hq/rubocop/issues
813
808
  post_install_message:
814
809
  rdoc_options: []