rubocop 1.22.0 → 1.22.1

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: '08520f6dcf324dcb95ce7191673f070e86c3b5c2613942d19e4c951119a43476'
4
- data.tar.gz: 90fd28bb4692e3feb9973d0b711a181c90608b205741b4b68cc23df9a9d42142
3
+ metadata.gz: fc48ec8bad4f5af1a464cb2d8d512975a10efd1d9c73e74ce024f798a4b200cc
4
+ data.tar.gz: 65ed09a920ce2211ab2d29a26780d1b198c08d29b3af92ef783c46024e056607
5
5
  SHA512:
6
- metadata.gz: 27a14f94b096be10618d7670ff591f4443ab4e09d8fce7f2604e686a1f7ab5544aaf53136c09a6ec62198f9f56950b5ab0c3cea64ee0ccd565e328b7ba131a5d
7
- data.tar.gz: 419cf3d94cf235cf31b09d26cbed550937dcb1930797e3e28c97cfb27116b160732aeec5434de8e0c3417f6900bf795c1826d7941e49cf8f12e9a15c245472b4
6
+ metadata.gz: 9fff6f773ae50140975bfac3f671f1657cd7da4c1df10623a7e36096e21032630fa8c41eb5a5d4eb8f07b92a48e7d99fc2b40d20da5811fc4bb0060dfc410e3b
7
+ data.tar.gz: 0aa4fa740168feb2643edbeecedc723c3da44c0f2c4843a39b9593c7dda07db21d05552ae52731b1b1ddbeeb2ffe0816d2c5e7d0423caec2dc40888cbd52758f
@@ -136,7 +136,7 @@ module RuboCop
136
136
  end
137
137
  end
138
138
 
139
- # Returns the path rubocop inferred as the root of the project. No file
139
+ # Returns the path RuboCop inferred as the root of the project. No file
140
140
  # searches will go past this directory.
141
141
  def project_root
142
142
  @project_root ||= find_project_root
@@ -68,14 +68,18 @@ module RuboCop
68
68
  end
69
69
 
70
70
  def proper_dot_position?(node)
71
- receiver_line = receiver_end_line(node.receiver)
72
71
  selector_line = selector_range(node).line
73
72
 
74
- # receiver and selector are on the same line
75
- return true if selector_line == receiver_line
73
+ # If the receiver is a HEREDOC and the selector is on the same line
74
+ # then there is nothing to do
75
+ return true if heredoc?(node.receiver) && node.receiver.loc.first_line == selector_line
76
76
 
77
+ receiver_line = receiver_end_line(node.receiver)
77
78
  dot_line = node.loc.dot.line
78
79
 
80
+ # receiver and selector are on the same line
81
+ return true if selector_line == receiver_line
82
+
79
83
  # don't register an offense if there is a line comment between the
80
84
  # dot and the selector otherwise, we might break the code while
81
85
  # "correcting" it (even if there is just an extra blank line, treat
@@ -27,6 +27,7 @@ module RuboCop
27
27
 
28
28
  def on_send(node)
29
29
  return unless (required_feature = node.first_argument)
30
+ return unless required_feature.respond_to?(:value)
30
31
  return unless same_file?(processed_source.file_path, required_feature.value)
31
32
 
32
33
  add_offense(node) do |corrector|
@@ -13,7 +13,11 @@ module RuboCop
13
13
  if style == :single_quotes
14
14
  !double_quotes_required?(src)
15
15
  else
16
- !/" | \\[^'\\] | \#[@{$]/x.match?(src)
16
+ # The string needs single quotes if:
17
+ # 1. It contains a double quote
18
+ # 2. It contains text that would become an escape sequence with double quotes
19
+ # 3. It contains text that would become an interpolation with double quotes
20
+ !/" | (?<!\\)\\[abcefMnrtuUx0-7] | \#[@{$]/x.match?(src)
17
21
  end
18
22
  end
19
23
  end
@@ -4,7 +4,8 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  # Checks if the quotes used for quoted symbols match the configured defaults.
7
- # By default uses the same configuration as `Style/StringLiterals`.
7
+ # By default uses the same configuration as `Style/StringLiterals`; if that
8
+ # cop is not enabled, the default `EnforcedStyle` is `single_quotes`.
8
9
  #
9
10
  # String interpolation is always kept in double quotes.
10
11
  #
@@ -75,11 +76,14 @@ module RuboCop
75
76
  end
76
77
 
77
78
  def correct_quotes(str)
78
- if style == :single_quotes
79
- to_string_literal(str)
80
- else
81
- str.inspect
82
- end
79
+ correction = if style == :single_quotes
80
+ to_string_literal(str)
81
+ else
82
+ str.gsub("\\'", "'").inspect
83
+ end
84
+
85
+ # The conversion process doubles escaped slashes, so they have to be reverted
86
+ correction.gsub('\\\\', '\\')
83
87
  end
84
88
 
85
89
  def style
@@ -58,8 +58,11 @@ module RuboCop
58
58
  return if node.arguments.count != 1
59
59
  return unless redundant_argument?(node)
60
60
 
61
- add_offense(node, message: format(MSG, arg: node.arguments.first.source)) do |corrector|
62
- corrector.remove(argument_range(node))
61
+ offense_range = argument_range(node)
62
+ message = format(MSG, arg: node.arguments.first.source)
63
+
64
+ add_offense(offense_range, message: message) do |corrector|
65
+ corrector.remove(offense_range)
63
66
  end
64
67
  end
65
68
 
@@ -3,9 +3,15 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Style
6
- # This cop looks for places where an subset of an array
7
- # is calculated based on a `Regexp` match, and suggests `grep` or
8
- # `grep_v` instead.
6
+ # This cop looks for places where an subset of an Enumerable (array,
7
+ # range, set, etc.; see note below) is calculated based on a `Regexp`
8
+ # match, and suggests `grep` or `grep_v` instead.
9
+ #
10
+ # NOTE: Hashes do not behave as you may expect with `grep`, which
11
+ # means that `hash.grep` is not equivalent to `hash.select`. Although
12
+ # RuboCop is limited by static analysis, this cop attempts to avoid
13
+ # registering an offense when the receiver is a hash (hash literal,
14
+ # `Hash.new`, `Hash#[]`, or `to_h`/`to_hash`).
9
15
  #
10
16
  # NOTE: `grep` and `grep_v` were optimized when used without a block
11
17
  # in Ruby 3.0, but may be slower in previous versions.
@@ -16,6 +22,10 @@ module RuboCop
16
22
  # not be created by `grep`, but may have previously been relied
17
23
  # upon after the `match?` or `=~` call.
18
24
  #
25
+ # Additionally, the cop cannot guarantee that the receiver of
26
+ # `select` or `reject` is actually an array by static analysis,
27
+ # so the correction may not be actually equivalent.
28
+ #
19
29
  # @example
20
30
  # # bad (select or find_all)
21
31
  # array.select { |x| x.match? /regexp/ }
@@ -49,6 +59,16 @@ module RuboCop
49
59
  }
50
60
  PATTERN
51
61
 
62
+ # Returns true if a node appears to return a hash
63
+ # @!method creates_hash?(node)
64
+ def_node_matcher :creates_hash?, <<~PATTERN
65
+ {
66
+ (send (const _ :Hash) {:new :[]} ...)
67
+ (block (send (const _ :Hash) :new ...) ...)
68
+ (send _ { :to_h :to_hash } ...)
69
+ }
70
+ PATTERN
71
+
52
72
  # @!method calls_lvar?(node, name)
53
73
  def_node_matcher :calls_lvar?, <<~PATTERN
54
74
  {
@@ -61,6 +81,7 @@ module RuboCop
61
81
  def on_send(node)
62
82
  return unless (block_node = node.block_node)
63
83
  return if block_node.body.begin_type?
84
+ return if receiver_allowed?(block_node.receiver)
64
85
  return unless (regexp_method_send_node = extract_send_node(block_node))
65
86
 
66
87
  regexp = find_regexp(regexp_method_send_node)
@@ -69,6 +90,12 @@ module RuboCop
69
90
 
70
91
  private
71
92
 
93
+ def receiver_allowed?(node)
94
+ return false unless node
95
+
96
+ node.hash_type? || creates_hash?(node)
97
+ end
98
+
72
99
  def register_offense(node, block_node, regexp)
73
100
  replacement = REPLACEMENTS[node.method_name.to_sym]
74
101
  message = format(MSG, replacement: replacement, original_method: node.method_name)
@@ -113,7 +113,8 @@ module RuboCop
113
113
  if needs_escaping?(string) && compatible_external_encoding_for?(string)
114
114
  string.inspect
115
115
  else
116
- "'#{string.gsub('\\') { '\\\\' }}'"
116
+ # In a single-quoted strings, double quotes don't need to be escaped
117
+ "'#{string.gsub('\"', '"').gsub('\\') { '\\\\' }}'"
117
118
  end
118
119
  end
119
120
 
@@ -33,7 +33,7 @@ module RuboCop
33
33
  private
34
34
 
35
35
  def run_cli(verbose, options)
36
- # We lazy-load rubocop so that the task doesn't dramatically impact the
36
+ # We lazy-load RuboCop so that the task doesn't dramatically impact the
37
37
  # load time of your Rakefile.
38
38
  require 'rubocop'
39
39
 
@@ -6,7 +6,7 @@ require 'etc'
6
6
  require 'zlib'
7
7
 
8
8
  module RuboCop
9
- # Provides functionality for caching rubocop runs.
9
+ # Provides functionality for caching RuboCop runs.
10
10
  # @api private
11
11
  class ResultCache
12
12
  NON_CHANGING = %i[color format formatters out debug fail_level auto_correct
@@ -170,7 +170,7 @@ module RuboCop
170
170
  attr_accessor :source_checksum, :inhibit_cleanup
171
171
  end
172
172
 
173
- # The checksum of the rubocop program running the inspection.
173
+ # The checksum of the RuboCop program running the inspection.
174
174
  def rubocop_checksum
175
175
  ResultCache.source_checksum ||=
176
176
  begin
@@ -60,7 +60,7 @@ module RuboCop
60
60
 
61
61
  private
62
62
 
63
- # Warms up the RuboCop cache by forking a suitable number of rubocop
63
+ # Warms up the RuboCop cache by forking a suitable number of RuboCop
64
64
  # instances that each inspects its allotted group of files.
65
65
  def warm_cache(target_files)
66
66
  puts 'Running parallel inspection' if @options[:debug]
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.22.0'
6
+ STRING = '1.22.1'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.22.0
4
+ version: 1.22.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
8
8
  - Jonas Arvidsson
9
9
  - Yuji Nakayama
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-09-29 00:00:00.000000000 Z
13
+ date: 2021-10-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel
@@ -899,7 +899,7 @@ metadata:
899
899
  source_code_uri: https://github.com/rubocop/rubocop/
900
900
  documentation_uri: https://docs.rubocop.org/rubocop/1.22/
901
901
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
902
- post_install_message:
902
+ post_install_message:
903
903
  rdoc_options: []
904
904
  require_paths:
905
905
  - lib
@@ -914,8 +914,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
914
914
  - !ruby/object:Gem::Version
915
915
  version: '0'
916
916
  requirements: []
917
- rubygems_version: 3.1.2
918
- signing_key:
917
+ rubygems_version: 3.2.22
918
+ signing_key:
919
919
  specification_version: 4
920
920
  summary: Automatic Ruby code style checking tool.
921
921
  test_files: []