rubocop 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5013f1930869ad961d7fe1cf2cd8bad7a36a15bc37f6cf42e1663fbdb61f2cc2
4
- data.tar.gz: 1ac4e658406f0f6e22a068f28fab225a8e9f53c59a79f89f0e52157cdc076efc
3
+ metadata.gz: 4238df3546a63ce2c279ced4bba228a61c137b083a3fad76b45365954555f690
4
+ data.tar.gz: bf3bd7a2409203b911212906d013aec7219f1a21825352bc92e0b897faafbd66
5
5
  SHA512:
6
- metadata.gz: 555adab63cf768a150f37d2ca84e08f2322e84182528949e09bd5eda4c79348e4c41dc17d23737785ea044a78f54f99d99d512047446d7437efdeaf306147f32
7
- data.tar.gz: 3fe186c044fd8733f4edef4055c036106d739e485dbfdcdbffe7882961175695edb79aafe27c1b11a8bbe9791f0754f26e7bd7534571dd09955bd5caf6aa6afe
6
+ metadata.gz: a87bd4426855a7278963b8c3e4373b7c995994b5685318aad04bc2b0832c0db44e705d50d4ea21d81eb47074137fde56665f8317121caae8a81e208e044ce4a7
7
+ data.tar.gz: 3bb4cb7794129ac95c70876bc009a4ed07425a7a346acaf77279c4e0fc8b1c20f31e82e9590e1d880fa011ddddc08c93bb3851f6f815718b9de8ff7a0dd78c6f
@@ -1176,7 +1176,7 @@ Layout/SpaceBeforeBlockBraces:
1176
1176
  SupportedStylesForEmptyBraces:
1177
1177
  - space
1178
1178
  - no_space
1179
- VersionChanged: '0.52.1'
1179
+ VersionChanged: '0.52'
1180
1180
 
1181
1181
  Layout/SpaceBeforeComma:
1182
1182
  Description: 'No spaces before commas.'
@@ -1401,7 +1401,10 @@ Lint/ConstantDefinitionInBlock:
1401
1401
  Enabled: true
1402
1402
  VersionAdded: '0.91'
1403
1403
  VersionChanged: '1.3'
1404
- AllowedMethods: []
1404
+ # `enums` for Typed Enums via T::Enum in Sorbet.
1405
+ # https://sorbet.org/docs/tenum
1406
+ AllowedMethods:
1407
+ - enums
1405
1408
 
1406
1409
  Lint/ConstantResolution:
1407
1410
  Description: 'Check that constants are fully qualified with `::`.'
@@ -1862,7 +1865,7 @@ Lint/RescueException:
1862
1865
  StyleGuide: '#no-blind-rescues'
1863
1866
  Enabled: true
1864
1867
  VersionAdded: '0.9'
1865
- VersionChanged: '0.27.1'
1868
+ VersionChanged: '0.27'
1866
1869
 
1867
1870
  Lint/RescueType:
1868
1871
  Description: 'Avoid rescuing from non constants that could result in a `TypeError`.'
@@ -3917,7 +3920,7 @@ Style/PercentLiteralDelimiters:
3917
3920
  '%r': '{}'
3918
3921
  '%w': '[]'
3919
3922
  '%W': '[]'
3920
- VersionChanged: '0.48.1'
3923
+ VersionChanged: '0.48'
3921
3924
 
3922
3925
  Style/PercentQLiterals:
3923
3926
  Description: 'Checks if uses of %Q/%q match the configured preference.'
@@ -4324,7 +4327,7 @@ Style/StringMethods:
4324
4327
  Description: 'Checks if configured preferred methods are used over non-preferred.'
4325
4328
  Enabled: false
4326
4329
  VersionAdded: '0.34'
4327
- VersionChanged: '0.34.2'
4330
+ VersionChanged: '0.34'
4328
4331
  # Mapping from undesired method to desired_method
4329
4332
  # e.g. to use `to_sym` over `intern`:
4330
4333
  #
@@ -255,10 +255,18 @@ module RuboCop
255
255
  "Configuration file not found: #{absolute_path}"
256
256
  end
257
257
 
258
- raise 'SafeYAML is unmaintained, no longer needed and should be removed' if defined?(SafeYAML)
258
+ def yaml_safe_load(yaml_code, filename)
259
+ yaml_safe_load!(yaml_code, filename)
260
+ rescue ::StandardError
261
+ if defined?(::SafeYAML)
262
+ raise 'SafeYAML is unmaintained, no longer needed and should be removed'
263
+ end
264
+
265
+ raise
266
+ end
259
267
 
260
268
  if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
261
- def yaml_safe_load(yaml_code, filename)
269
+ def yaml_safe_load!(yaml_code, filename)
262
270
  YAML.safe_load(yaml_code,
263
271
  permitted_classes: [Regexp, Symbol],
264
272
  permitted_symbols: [],
@@ -266,7 +274,7 @@ module RuboCop
266
274
  filename: filename)
267
275
  end
268
276
  else # Ruby < 2.6
269
- def yaml_safe_load(yaml_code, filename)
277
+ def yaml_safe_load!(yaml_code, filename)
270
278
  YAML.safe_load(yaml_code, [Regexp, Symbol], [], true, filename)
271
279
  end
272
280
  end
@@ -17,7 +17,6 @@ module RuboCop
17
17
  SOURCE_TEMPLATE = <<-RUBY.gsub(/^ {8}/, '')
18
18
  # frozen_string_literal: true
19
19
 
20
- # TODO: when finished, run `rake generate_cops_documentation` to update the docs
21
20
  module RuboCop
22
21
  module Cop
23
22
  module %<department>s
@@ -134,7 +133,7 @@ module RuboCop
134
133
  end
135
134
 
136
135
  def inject_config(config_file_path: 'config/default.yml',
137
- version_added: bump_minor_version)
136
+ version_added: '<<next>>')
138
137
  injector =
139
138
  ConfigurationInjector.new(configuration_file_path: config_file_path,
140
139
  badge: badge,
@@ -213,12 +212,6 @@ module RuboCop
213
212
  .gsub(/([A-Z])([A-Z][^A-Z\d]+)/, '\1_\2')
214
213
  .downcase
215
214
  end
216
-
217
- def bump_minor_version
218
- versions = RuboCop::Version::STRING.split('.')
219
-
220
- "#{versions[0]}.#{versions[1].succ}"
221
- end
222
215
  end
223
216
  end
224
217
  end
@@ -14,7 +14,7 @@ module RuboCop
14
14
  VersionAdded: '%<version_added>s'
15
15
  YAML
16
16
 
17
- def initialize(configuration_file_path:, badge:, version_added:)
17
+ def initialize(configuration_file_path:, badge:, version_added: '<<next>>')
18
18
  @configuration_file_path = configuration_file_path
19
19
  @badge = badge
20
20
  @version_added = version_added
@@ -147,6 +147,10 @@ module RuboCop
147
147
  MSG = '`%<category>s` is supposed to appear before ' \
148
148
  '`%<previous>s`.'
149
149
 
150
+ def_node_matcher :dynamic_constant?, <<~PATTERN
151
+ (casgn nil? _ (send ...))
152
+ PATTERN
153
+
150
154
  # Validates code style on class declaration.
151
155
  # Add offense when find a node out of expected order.
152
156
  def on_class(class_node)
@@ -168,11 +172,10 @@ module RuboCop
168
172
 
169
173
  # Autocorrect by swapping between two nodes autocorrecting them
170
174
  def autocorrect(corrector, node)
171
- node_classification = classify(node)
172
175
  previous = node.left_siblings.find do |sibling|
173
- classification = classify(sibling)
174
- !ignore?(classification) && node_classification != classification
176
+ !ignore_for_autocorrect?(node, sibling)
175
177
  end
178
+ return unless previous
176
179
 
177
180
  current_range = source_range_with_comment(node)
178
181
  previous_range = source_range_with_comment(previous)
@@ -241,6 +244,15 @@ module RuboCop
241
244
  expected_order.index(classification).nil?
242
245
  end
243
246
 
247
+ def ignore_for_autocorrect?(node, sibling)
248
+ classification = classify(node)
249
+ sibling_class = classify(sibling)
250
+
251
+ ignore?(sibling_class) ||
252
+ classification == sibling_class ||
253
+ dynamic_constant?(node)
254
+ end
255
+
244
256
  def humanize_node(node)
245
257
  if node.def_type?
246
258
  return :initializer if node.method?(:initialize)
@@ -50,8 +50,11 @@ module RuboCop
50
50
  # end
51
51
  # end
52
52
  #
53
- # @example AllowedMethods: ['enums']
53
+ # @example AllowedMethods: ['enums'] (default)
54
54
  # # good
55
+ #
56
+ # # `enums` for Typed Enums via `T::Enum` in Sorbet.
57
+ # # https://sorbet.org/docs/tenum
55
58
  # class TestEnum < T::Enum
56
59
  # enums do
57
60
  # Foo = new("foo")
@@ -8,23 +8,14 @@ module RuboCop
8
8
  #
9
9
  # @example
10
10
  # # bad
11
- # def method(x, y = 1)
12
- # return to_enum(__method__, x) # `y` is missing
11
+ # def foo(x, y = 1)
12
+ # return to_enum(__callee__, x) # `y` is missing
13
13
  # end
14
14
  #
15
15
  # # good
16
- # def method(x, y = 1)
17
- # return to_enum(__method__, x, y)
18
- # end
19
- #
20
- # # bad
21
- # def method(required:)
22
- # return to_enum(:method, required: something) # `required` has incorrect value
23
- # end
24
- #
25
- # # good
26
- # def method(required:)
27
- # return to_enum(:method, required: required)
16
+ # def foo(x, y = 1)
17
+ # return to_enum(__callee__, x, y)
18
+ # # alternatives to `__callee__` are `__method__` and `:foo`
28
19
  # end
29
20
  #
30
21
  class ToEnumArguments < Base
@@ -37,7 +28,7 @@ module RuboCop
37
28
  PATTERN
38
29
 
39
30
  def_node_matcher :method_name?, <<~PATTERN
40
- {(send nil? :__method__) (sym %1)}
31
+ {(send nil? {:__method__ :__callee__}) (sym %1)}
41
32
  PATTERN
42
33
 
43
34
  def_node_matcher :passing_keyword_arg?, <<~PATTERN
@@ -8,9 +8,9 @@ module RuboCop
8
8
  include ConfigurableFormatting
9
9
 
10
10
  FORMATS = {
11
- snake_case: /(?:\D|_\d+)$/,
12
- normalcase: /(?:\D|[^_\d]\d+)$/,
13
- non_integer: /\D$/
11
+ snake_case: /(?:\D|_\d+|\A\d+)\z/,
12
+ normalcase: /(?:\D|[^_\d]\d+|\A\d+)\z/,
13
+ non_integer: /(\D|\A\d+)\z/
14
14
  }.freeze
15
15
  end
16
16
  end
@@ -68,6 +68,12 @@ module RuboCop
68
68
  # end
69
69
  # EOT
70
70
  # )
71
+ #
72
+ # # bad - interpolated string without comment
73
+ # class_eval("def #{unsafe_method}!(*params); end")
74
+ #
75
+ # # good - with inline comment or replace it with block comment using heredoc
76
+ # class_eval("def #{unsafe_method}!(*params); end # def capitalize!(*params); end")
71
77
  class DocumentDynamicEvalDefinition < Base
72
78
  BLOCK_COMMENT_REGEXP = /^\s*#(?!{)/.freeze
73
79
  COMMENT_REGEXP = /\s*#(?!{).*/.freeze
@@ -79,7 +85,8 @@ module RuboCop
79
85
  arg_node = node.first_argument
80
86
 
81
87
  return unless arg_node&.dstr_type? && interpolated?(arg_node)
82
- return if inline_comment_docs?(arg_node) || comment_block_docs?(arg_node)
88
+ return if inline_comment_docs?(arg_node) ||
89
+ arg_node.heredoc? && comment_block_docs?(arg_node)
83
90
 
84
91
  add_offense(node.loc.selector)
85
92
  end
@@ -35,6 +35,8 @@ module RuboCop
35
35
 
36
36
  NEGATED_EQUALITY_METHODS = %i[!= !~].freeze
37
37
 
38
+ def_node_matcher :double_negation?, '(send (send _ :!) :!)'
39
+
38
40
  def self.autocorrect_incompatible_with
39
41
  [Style::InverseMethods, Style::Not]
40
42
  end
@@ -47,7 +49,7 @@ module RuboCop
47
49
  return unless if_else?(node)
48
50
 
49
51
  condition = node.condition
50
- return unless negated_condition?(condition)
52
+ return if double_negation?(condition) || !negated_condition?(condition)
51
53
 
52
54
  type = node.ternary? ? 'ternary' : 'if-else'
53
55
  add_offense(node, message: format(MSG, type: type)) do |corrector|
@@ -94,7 +94,7 @@ module RuboCop
94
94
  end
95
95
 
96
96
  def wanted_dir_patterns(base_dir, exclude_pattern, flags)
97
- dirs = Dir.glob(File.join(base_dir, '*/'), flags)
97
+ dirs = Dir.glob(File.join(base_dir.gsub('/**/', '/\**/'), '*/'), flags)
98
98
  .reject do |dir|
99
99
  dir.end_with?('/./', '/../') || File.fnmatch?(exclude_pattern, dir, flags)
100
100
  end
@@ -123,6 +123,10 @@ module RuboCop
123
123
  (send _ :required_ruby_version= $_)
124
124
  PATTERN
125
125
 
126
+ def_node_matcher :gem_requirement?, <<~PATTERN
127
+ (send (const(const _ :Gem):Requirement) :new $str)
128
+ PATTERN
129
+
126
130
  def name
127
131
  "`required_ruby_version` parameter (in #{gemspec_filename})"
128
132
  end
@@ -136,10 +140,9 @@ module RuboCop
136
140
  version = version_from_gemspec_file(file)
137
141
  return if version.nil?
138
142
 
139
- if version.array_type?
140
- versions = version.children.map { |v| version_from_str(v.str_content) }
141
- return versions.compact.min
142
- end
143
+ requirement = version.children.last
144
+ return version_from_array(version) if version.array_type?
145
+ return version_from_array(requirement) if gem_requirement? version
143
146
 
144
147
  version_from_str(version.str_content)
145
148
  end
@@ -161,6 +164,11 @@ module RuboCop
161
164
  required_ruby_version(processed_source.ast).first
162
165
  end
163
166
 
167
+ def version_from_array(array)
168
+ versions = array.children.map { |v| version_from_str(v.is_a?(String) ? v : v.str_content) }
169
+ versions.compact.min
170
+ end
171
+
164
172
  def version_from_str(str)
165
173
  str.match(/^(?:>=|<=)?\s*(?<version>\d+(?:\.\d+)*)/) do |md|
166
174
  md[:version].to_f
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.3.0'
6
+ STRING = '1.3.1'
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.3.0
4
+ version: 1.3.1
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-11-12 00:00:00.000000000 Z
13
+ date: 2020-11-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel