rubocop 1.63.3 → 1.63.5

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: 280ae6904ade12bb288a774c260e7a51c2e3152446d82415f3839f41b15d83a1
4
- data.tar.gz: 48b8fce72325a97238428955dde6d3dbcafacbb2b5ea5952808d088003b2a6b8
3
+ metadata.gz: 1911c884de81dd524490fea5075e7605d3ccf82fad85ebc9d09adbe5d29637ca
4
+ data.tar.gz: 8206c237dd18bbcd9769d55b1206d160ce766a21caa5c8f8ea956ae845371ea2
5
5
  SHA512:
6
- metadata.gz: e9cc268aefd0aefd13db5ca31865aaf1298639da77fa3c36fba425d980c36b209550cdd1dddfd68d644c50665a33cb6908512434a25639319c41ea266015409c
7
- data.tar.gz: f3b64a7ed84536a42546ef6bd8a4f6ebcb8b9402fbe01a24421ac5f3aee9efa2f4e66ce1563caf0ca2504f265fecf9c4b27e5444c20e5a2bd6803980996d39b8
6
+ metadata.gz: 429dfdfda489516f4856fa00ad50c062a172588ca4bb1006baa25213c2fb949b0781af446d689200f0a87017f47708ad49324a6644cce104f79dd42b129dd680
7
+ data.tar.gz: ce8363fa68a56f9c5f36c40d1596932b1233854823c54bfb9dc36a669256dca64459186037fe10e9723a550cec0a6f11df2e1d802e4471d8c9d1e98db8c528f3
data/lib/rubocop/cli.rb CHANGED
@@ -57,6 +57,10 @@ module RuboCop
57
57
  rescue RuboCop::Error => e
58
58
  warn Rainbow("Error: #{e.message}").red
59
59
  STATUS_ERROR
60
+ rescue Interrupt
61
+ warn ''
62
+ warn 'Exiting...'
63
+ STATUS_INTERRUPTED
60
64
  rescue Finished
61
65
  STATUS_SUCCESS
62
66
  rescue OptionParser::InvalidOption => e
@@ -160,7 +160,7 @@ module RuboCop
160
160
  end
161
161
 
162
162
  def two_alternatives?(line)
163
- /^\s*(else|elsif|when|rescue|ensure)\b/.match?(line)
163
+ /^\s*(else|elsif|when|in|rescue|ensure)\b/.match?(line)
164
164
  end
165
165
  end
166
166
  end
@@ -92,6 +92,8 @@ module RuboCop
92
92
  'in an array, relative to %<base_description>s.'
93
93
 
94
94
  def on_array(node)
95
+ return if style != :consistent && enforce_first_argument_with_fixed_indentation?
96
+
95
97
  check(node, nil) if node.loc.begin
96
98
  end
97
99
 
@@ -51,8 +51,8 @@ module RuboCop
51
51
  when :method_call
52
52
  ->(node) { node.call_type? }
53
53
  else
54
- raise ArgumentError, "Unknown foldable type: #{type.inspect}. " \
55
- "Valid foldable types are: #{FOLDABLE_TYPES.join(', ')}."
54
+ raise Warning, "Unknown foldable type: #{type.inspect}. " \
55
+ "Valid foldable types are: #{FOLDABLE_TYPES.join(', ')}."
56
56
  end
57
57
  end
58
58
  end
@@ -30,8 +30,8 @@ module RuboCop
30
30
  class CompoundHash < Base
31
31
  COMBINATOR_IN_HASH_MSG = 'Use `[...].hash` instead of combining hash values manually.'
32
32
  MONUPLE_HASH_MSG =
33
- 'Delegate hash directly without wrapping in an array when only using a single value'
34
- REDUNDANT_HASH_MSG = 'Calling .hash on elements of a hashed array is redundant'
33
+ 'Delegate hash directly without wrapping in an array when only using a single value.'
34
+ REDUNDANT_HASH_MSG = 'Calling .hash on elements of a hashed array is redundant.'
35
35
 
36
36
  # @!method hash_method_definition?(node)
37
37
  def_node_matcher :hash_method_definition?, <<~PATTERN
@@ -214,7 +214,7 @@ module RuboCop
214
214
  extend AutoCorrector
215
215
 
216
216
  MSG = 'Use the return of the conditional for variable assignment and comparison.'
217
- ASSIGN_TO_CONDITION_MSG = 'Assign variables inside of conditionals'
217
+ ASSIGN_TO_CONDITION_MSG = 'Assign variables inside of conditionals.'
218
218
  VARIABLE_ASSIGNMENT_TYPES = %i[casgn cvasgn gvasgn ivasgn lvasgn].freeze
219
219
  ASSIGNMENT_TYPES = VARIABLE_ASSIGNMENT_TYPES + %i[and_asgn or_asgn op_asgn masgn].freeze
220
220
  LINE_LENGTH = 'Layout/LineLength'
@@ -118,12 +118,14 @@ module RuboCop
118
118
 
119
119
  return unless numeric && operator && replacement_supported?(operator)
120
120
 
121
- [numeric, replacement(numeric, operator)]
121
+ [numeric, replacement(node, numeric, operator)]
122
122
  end
123
123
 
124
- def replacement(numeric, operation)
124
+ def replacement(node, numeric, operation)
125
125
  if style == :predicate
126
126
  [parenthesized_source(numeric), REPLACEMENTS.invert[operation.to_s]].join('.')
127
+ elsif negated?(node)
128
+ "(#{numeric.source} #{REPLACEMENTS[operation.to_s]} 0)"
127
129
  else
128
130
  [numeric.source, REPLACEMENTS[operation.to_s], 0].join(' ')
129
131
  end
@@ -157,6 +159,12 @@ module RuboCop
157
159
  end
158
160
  end
159
161
 
162
+ def negated?(node)
163
+ return false unless (parent = node.parent)
164
+
165
+ parent.send_type? && parent.method?(:!)
166
+ end
167
+
160
168
  # @!method predicate(node)
161
169
  def_node_matcher :predicate, <<~PATTERN
162
170
  (send $(...) ${:zero? :positive? :negative?})
@@ -137,7 +137,9 @@ module RuboCop
137
137
  # do_something \
138
138
  # argument
139
139
  def method_with_argument?(current_token, next_token)
140
- current_token.type == :tIDENTIFIER && ARGUMENT_TYPES.include?(next_token.type)
140
+ return false if current_token.type != :tIDENTIFIER && current_token.type != :kRETURN
141
+
142
+ ARGUMENT_TYPES.include?(next_token.type)
141
143
  end
142
144
 
143
145
  # rubocop:disable Metrics/AbcSize
@@ -58,9 +58,8 @@ module RuboCop
58
58
  #
59
59
  # @example EnforcedStyle: use_builtin_english_names
60
60
  #
61
- # Like `use_perl_names` but allows builtin global vars.
62
- #
63
61
  # # good
62
+ # # Like `use_perl_names` but allows builtin global vars.
64
63
  # puts $LOAD_PATH
65
64
  # puts $LOADED_FEATURES
66
65
  # puts $PROGRAM_NAME
@@ -1,5 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ begin
4
+ # We might not be running with `bundle exec`, so we need to pull in Bundler ourselves,
5
+ # in order to use `Bundler::LockfileParser`.
6
+ require 'bundler'
7
+ rescue LoadError
8
+ nil
9
+ end
10
+
3
11
  module RuboCop
4
12
  # Encapsulation of a lockfile for use when checking for gems.
5
13
  # Does not actually resolve gems, just parses the lockfile.
@@ -7,7 +15,11 @@ module RuboCop
7
15
  class Lockfile
8
16
  # @param [String, Pathname, nil] lockfile_path
9
17
  def initialize(lockfile_path = nil)
10
- lockfile_path ||= Bundler.default_lockfile if bundler_lock_parser_defined?
18
+ lockfile_path ||= begin
19
+ ::Bundler.default_lockfile if bundler_lock_parser_defined?
20
+ rescue ::Bundler::GemfileNotFound
21
+ nil # We might not be a folder with a Gemfile, but that's okay.
22
+ end
11
23
 
12
24
  @lockfile_path = lockfile_path
13
25
  end
@@ -60,8 +60,9 @@ module RuboCop
60
60
 
61
61
  handle 'initialized' do |_request|
62
62
  version = RuboCop::Version::STRING
63
+ yjit = Object.const_defined?('RubyVM::YJIT') && RubyVM::YJIT.enabled? ? ' +YJIT' : ''
63
64
 
64
- Logger.log("RuboCop #{version} language server initialized, PID #{Process.pid}")
65
+ Logger.log("RuboCop #{version} language server#{yjit} initialized, PID #{Process.pid}")
65
66
  end
66
67
 
67
68
  handle 'shutdown' do |request|
@@ -73,9 +74,7 @@ module RuboCop
73
74
  end
74
75
 
75
76
  handle 'textDocument/diagnostic' do |request|
76
- doc = request[:params][:textDocument]
77
- result = diagnostic(doc[:uri], doc[:text])
78
- @server.write(result)
77
+ # no-op, diagnostics are handled in textDocument/didChange
79
78
  end
80
79
 
81
80
  handle 'textDocument/didChange' do |request|
@@ -573,7 +573,7 @@ module RuboCop
573
573
  'cops. Only valid for --format junit.'],
574
574
  display_only_fail_level_offenses:
575
575
  ['Only output offense messages at',
576
- 'the specified --fail-level or above'],
576
+ 'the specified --fail-level or above.'],
577
577
  display_only_correctable: ['Only output correctable offense messages.'],
578
578
  display_only_safe_correctable: ['Only output safe-correctable offense messages',
579
579
  'when combined with --display-only-correctable.'],
@@ -636,8 +636,8 @@ module RuboCop
636
636
  raise_cop_error: ['Raise cop-related errors with cause and location.',
637
637
  'This is used to prevent cops from failing silently.',
638
638
  'Default is false.'],
639
- profile: 'Profile rubocop',
640
- memory: 'Profile rubocop memory usage'
639
+ profile: 'Profile rubocop.',
640
+ memory: 'Profile rubocop memory usage.'
641
641
  }.freeze
642
642
  end
643
643
  # rubocop:enable Metrics/ModuleLength
@@ -44,7 +44,7 @@ module RuboCop
44
44
  def run_cli(verbose, options)
45
45
  # We lazy-load RuboCop so that the task doesn't dramatically impact the
46
46
  # load time of your Rakefile.
47
- require 'rubocop'
47
+ require_relative '../rubocop'
48
48
 
49
49
  cli = CLI.new
50
50
  puts 'Running RuboCop...' if verbose
@@ -20,10 +20,11 @@ module RuboCop
20
20
  message = 'Infinite loop detected'
21
21
  message += " in #{path}" if path
22
22
  message += " and caused by #{root_cause}" if root_cause
23
- message += ' Hint: Please update to the latest RuboCop version if not already in use,'
24
- message += ' and report a bug if the issue still occurs on this version.'
25
- message += ' Please check the latest version at https://rubygems.org/gems/rubocop'
26
- super(message)
23
+ message += "\n"
24
+ hint = 'Hint: Please update to the latest RuboCop version if not already in use, ' \
25
+ "and report a bug if the issue still occurs on this version.\n" \
26
+ 'Please check the latest version at https://rubygems.org/gems/rubocop.'
27
+ super(Rainbow(message).red + Rainbow(hint).yellow)
27
28
  end
28
29
  end
29
30
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.63.3'
6
+ STRING = '1.63.5'
7
7
 
8
8
  MSG = '%<version>s (using %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
@@ -42,9 +42,9 @@ module RuboCop
42
42
  # @api private
43
43
  def self.parser_version
44
44
  config_path = ConfigFinder.find_config_path(Dir.pwd)
45
- yaml = YAML.safe_load(
46
- File.read(config_path), permitted_classes: [Regexp, Symbol], aliases: true
47
- )
45
+ yaml = Util.silence_warnings do
46
+ ConfigLoader.load_yaml_configuration(config_path)
47
+ end
48
48
 
49
49
  if yaml.dig('AllCops', 'ParserEngine') == 'parser_prism'
50
50
  require 'prism'
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.63.3
4
+ version: 1.63.5
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: 2024-04-22 00:00:00.000000000 Z
13
+ date: 2024-05-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -1032,7 +1032,7 @@ licenses:
1032
1032
  - MIT
1033
1033
  metadata:
1034
1034
  homepage_uri: https://rubocop.org/
1035
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.63.3
1035
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.63.5
1036
1036
  source_code_uri: https://github.com/rubocop/rubocop/
1037
1037
  documentation_uri: https://docs.rubocop.org/rubocop/1.63/
1038
1038
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues