rubocop 1.64.0 → 1.64.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 +4 -4
- data/README.md +0 -1
- data/lib/rubocop/cop/force.rb +12 -0
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +3 -4
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +21 -14
- data/lib/rubocop/cop/style/copyright.rb +5 -2
- data/lib/rubocop/cop/style/documentation.rb +24 -24
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +2 -1
- data/lib/rubocop/cop/style/send_with_literal_method_name.rb +9 -2
- data/lib/rubocop/cop/style/super_arguments.rb +24 -5
- data/lib/rubocop/cop/team.rb +2 -0
- data/lib/rubocop/lsp/routes.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc79c69246529843a3d6179458d5563867515189cca9f68d34e6cba9f103a032
|
4
|
+
data.tar.gz: 2b71ef0f55a63904b93e1315417ab4bd9701c1d91f3f87087fda9046243a4176
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ea1aa79a49f5a9c7331286e58563b5b92c5c8b11bc1d81dbddee107595a9588e84c7888a8fe6338b29e856740d35d56df47e8d7b485db5cc4cd6cd0f45a8406
|
7
|
+
data.tar.gz: f5bc4fb8153c6277534bc4acd22da3bb3e41ef0ca5eef2639817893fa2312b5291ca80b308151c2e315db993ea086f32f618f9ef65146b69e4b99fc50782c165
|
data/README.md
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
----------
|
6
6
|
[](https://github.com/rubocop/rubocop)
|
7
7
|
[](https://badge.fury.io/rb/rubocop)
|
8
|
-
[](https://circleci.com/gh/rubocop/rubocop/tree/master)
|
9
8
|
[](https://github.com/rubocop/rubocop/actions?query=workflow%3ACI)
|
10
9
|
[](https://codeclimate.com/github/rubocop/rubocop/test_coverage)
|
11
10
|
[](https://codeclimate.com/github/rubocop/rubocop/maintainability)
|
data/lib/rubocop/cop/force.rb
CHANGED
@@ -4,6 +4,16 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
# A scaffold for concrete forces.
|
6
6
|
class Force
|
7
|
+
# @api private
|
8
|
+
class HookError < StandardError
|
9
|
+
attr_reader :joining_cop
|
10
|
+
|
11
|
+
def initialize(joining_cop)
|
12
|
+
super
|
13
|
+
@joining_cop = joining_cop
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
7
17
|
attr_reader :cops
|
8
18
|
|
9
19
|
def self.all
|
@@ -32,6 +42,8 @@ module RuboCop
|
|
32
42
|
next unless cop.respond_to?(method_name)
|
33
43
|
|
34
44
|
cop.public_send(method_name, *args)
|
45
|
+
rescue StandardError
|
46
|
+
raise HookError, cop
|
35
47
|
end
|
36
48
|
end
|
37
49
|
|
@@ -25,8 +25,7 @@ module RuboCop
|
|
25
25
|
include RangeHelp
|
26
26
|
extend AutoCorrector
|
27
27
|
|
28
|
-
|
29
|
-
SPACE_MSG = 'Missing space inside string interpolation detected.'
|
28
|
+
MSG = '%<command>s space inside string interpolation.'
|
30
29
|
|
31
30
|
def on_interpolation(begin_node)
|
32
31
|
return if begin_node.multiline?
|
@@ -36,9 +35,9 @@ module RuboCop
|
|
36
35
|
return if empty_brackets?(left, right, tokens: tokens)
|
37
36
|
|
38
37
|
if style == :no_space
|
39
|
-
no_space_offenses(begin_node, left, right,
|
38
|
+
no_space_offenses(begin_node, left, right, MSG)
|
40
39
|
else
|
41
|
-
space_offenses(begin_node, left, right,
|
40
|
+
space_offenses(begin_node, left, right, MSG)
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
@@ -65,17 +65,15 @@ module RuboCop
|
|
65
65
|
|
66
66
|
minimum_target_ruby_version 2.6
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
'`ERB.new(str, eoutvar: %<arg_value>s)` instead.'
|
78
|
-
].freeze
|
68
|
+
MESSAGE_SAFE_LEVEL = 'Passing safe_level with the 2nd argument of `ERB.new` is ' \
|
69
|
+
'deprecated. Do not use it, and specify other arguments as ' \
|
70
|
+
'keyword arguments.'
|
71
|
+
MESSAGE_TRIM_MODE = 'Passing trim_mode with the 3rd argument of `ERB.new` is ' \
|
72
|
+
'deprecated. Use keyword argument like ' \
|
73
|
+
'`ERB.new(str, trim_mode: %<arg_value>s)` instead.'
|
74
|
+
MESSAGE_EOUTVAR = 'Passing eoutvar with the 4th argument of `ERB.new` is ' \
|
75
|
+
'deprecated. Use keyword argument like ' \
|
76
|
+
'`ERB.new(str, eoutvar: %<arg_value>s)` instead.'
|
79
77
|
|
80
78
|
RESTRICT_ON_SEND = %i[new].freeze
|
81
79
|
|
@@ -92,10 +90,8 @@ module RuboCop
|
|
92
90
|
arguments[1..3].each_with_index do |argument, i|
|
93
91
|
next if !argument || argument.hash_type?
|
94
92
|
|
95
|
-
message = format(MESSAGES[i], arg_value: argument.source)
|
96
|
-
|
97
93
|
add_offense(
|
98
|
-
argument.source_range, message: message
|
94
|
+
argument.source_range, message: message(i, argument.source)
|
99
95
|
) do |corrector|
|
100
96
|
autocorrect(corrector, node)
|
101
97
|
end
|
@@ -105,6 +101,17 @@ module RuboCop
|
|
105
101
|
|
106
102
|
private
|
107
103
|
|
104
|
+
def message(positional_argument_index, arg_value)
|
105
|
+
case positional_argument_index
|
106
|
+
when 0
|
107
|
+
MESSAGE_SAFE_LEVEL
|
108
|
+
when 1
|
109
|
+
format(MESSAGE_TRIM_MODE, arg_value: arg_value)
|
110
|
+
when 2
|
111
|
+
format(MESSAGE_EOUTVAR, arg_value: arg_value)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
108
115
|
def autocorrect(corrector, node)
|
109
116
|
str_arg = node.first_argument.source
|
110
117
|
|
@@ -58,12 +58,15 @@ module RuboCop
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def verify_autocorrect_notice!
|
61
|
-
|
61
|
+
if autocorrect_notice.nil? || autocorrect_notice.empty?
|
62
|
+
raise Warning, "#{cop_name}: #{AUTOCORRECT_EMPTY_WARNING}"
|
63
|
+
end
|
62
64
|
|
63
65
|
regex = Regexp.new(notice)
|
64
66
|
return if autocorrect_notice.gsub(/^# */, '').match?(regex)
|
65
67
|
|
66
|
-
|
68
|
+
message = "AutocorrectNotice '#{autocorrect_notice}' must match Notice /#{notice}/"
|
69
|
+
raise Warning, "#{cop_name}: #{message}"
|
67
70
|
end
|
68
71
|
|
69
72
|
def insert_notice_before(processed_source)
|
@@ -29,36 +29,36 @@ module RuboCop
|
|
29
29
|
# end
|
30
30
|
#
|
31
31
|
# # allowed
|
32
|
-
#
|
32
|
+
# # Class without body
|
33
|
+
# class Person
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# # Namespace - A namespace can be a class or a module
|
37
|
+
# # Containing a class
|
38
|
+
# module Namespace
|
39
|
+
# # Description/Explanation of Person class
|
33
40
|
# class Person
|
41
|
+
# # ...
|
34
42
|
# end
|
43
|
+
# end
|
35
44
|
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
# # Description/Explanation of Person class
|
40
|
-
# class Person
|
41
|
-
# # ...
|
42
|
-
# end
|
45
|
+
# # Containing constant visibility declaration
|
46
|
+
# module Namespace
|
47
|
+
# class Private
|
43
48
|
# end
|
44
49
|
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
# class Private
|
48
|
-
# end
|
49
|
-
#
|
50
|
-
# private_constant :Private
|
51
|
-
# end
|
50
|
+
# private_constant :Private
|
51
|
+
# end
|
52
52
|
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
53
|
+
# # Containing constant definition
|
54
|
+
# module Namespace
|
55
|
+
# Public = Class.new
|
56
|
+
# end
|
57
57
|
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
58
|
+
# # Macro calls
|
59
|
+
# module Namespace
|
60
|
+
# extend Foo
|
61
|
+
# end
|
62
62
|
#
|
63
63
|
# @example AllowedConstants: ['ClassMethods']
|
64
64
|
#
|
@@ -67,7 +67,7 @@ module RuboCop
|
|
67
67
|
# module ClassMethods
|
68
68
|
# # ...
|
69
69
|
# end
|
70
|
-
#
|
70
|
+
# end
|
71
71
|
#
|
72
72
|
class Documentation < Base
|
73
73
|
include DocumentationComment
|
@@ -74,6 +74,7 @@ module RuboCop
|
|
74
74
|
kFALSE kNIL kSELF kTRUE tCONSTANT tCVAR tFLOAT tGVAR tIDENTIFIER tINTEGER tIVAR
|
75
75
|
tLBRACK tLCURLY tLPAREN_ARG tSTRING tSTRING_BEG tSYMBOL tXSTRING_BEG
|
76
76
|
].freeze
|
77
|
+
ARGUMENT_TAKING_FLOW_TOKEN_TYPES = %i[tIDENTIFIER kRETURN kBREAK kNEXT kYIELD].freeze
|
77
78
|
|
78
79
|
def on_new_investigation
|
79
80
|
return unless processed_source.ast
|
@@ -137,7 +138,7 @@ module RuboCop
|
|
137
138
|
# do_something \
|
138
139
|
# argument
|
139
140
|
def method_with_argument?(current_token, next_token)
|
140
|
-
return false
|
141
|
+
return false unless ARGUMENT_TAKING_FLOW_TOKEN_TYPES.include?(current_token.type)
|
141
142
|
|
142
143
|
ARGUMENT_TYPES.include?(next_token.type)
|
143
144
|
end
|
@@ -43,8 +43,14 @@ module RuboCop
|
|
43
43
|
MSG = 'Use `%<method_name>s` method call directly instead.'
|
44
44
|
RESTRICT_ON_SEND = %i[public_send send __send__].freeze
|
45
45
|
STATIC_METHOD_NAME_NODE_TYPES = %i[sym str].freeze
|
46
|
+
METHOD_NAME_PATTERN = /\A[a-zA-Z_][a-zA-Z0-9_]*[!?=]?\z/.freeze
|
47
|
+
RESERVED_WORDS = %i[
|
48
|
+
BEGIN END alias and begin break case class def defined? do else elsif end ensure
|
49
|
+
false for if in module next nil not or redo rescue retry return self super then true
|
50
|
+
undef unless until when while yield
|
51
|
+
].freeze
|
46
52
|
|
47
|
-
# rubocop:disable Metrics/AbcSize
|
53
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
48
54
|
def on_send(node)
|
49
55
|
return if allow_send? && !node.method?(:public_send)
|
50
56
|
return unless (first_argument = node.first_argument)
|
@@ -52,6 +58,7 @@ module RuboCop
|
|
52
58
|
|
53
59
|
offense_range = offense_range(node)
|
54
60
|
method_name = first_argument.value
|
61
|
+
return if !METHOD_NAME_PATTERN.match?(method_name) || RESERVED_WORDS.include?(method_name)
|
55
62
|
|
56
63
|
add_offense(offense_range, message: format(MSG, method_name: method_name)) do |corrector|
|
57
64
|
if node.arguments.one?
|
@@ -62,7 +69,7 @@ module RuboCop
|
|
62
69
|
end
|
63
70
|
end
|
64
71
|
end
|
65
|
-
# rubocop:enable Metrics/AbcSize
|
72
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
66
73
|
|
67
74
|
private
|
68
75
|
|
@@ -26,10 +26,19 @@ module RuboCop
|
|
26
26
|
# def method(*args, **kwargs)
|
27
27
|
# super()
|
28
28
|
# end
|
29
|
+
#
|
30
|
+
# # good - assigning to the block variable before calling super
|
31
|
+
# def method(&block)
|
32
|
+
# # Assigning to the block variable would pass the old value to super,
|
33
|
+
# # under this circumstance the block must be referenced explicitly.
|
34
|
+
# block ||= proc { 'fallback behavior' }
|
35
|
+
# super(&block)
|
36
|
+
# end
|
29
37
|
class SuperArguments < Base
|
30
38
|
extend AutoCorrector
|
31
39
|
|
32
40
|
DEF_TYPES = %i[def defs].freeze
|
41
|
+
ASSIGN_TYPES = %i[or_asgn lvasgn].freeze
|
33
42
|
|
34
43
|
MSG = 'Call `super` without arguments and parentheses when the signature is identical.'
|
35
44
|
|
@@ -41,7 +50,8 @@ module RuboCop
|
|
41
50
|
break node if DEF_TYPES.include?(node.type)
|
42
51
|
end
|
43
52
|
return unless def_node
|
44
|
-
return unless arguments_identical?(def_node.arguments.argument_list,
|
53
|
+
return unless arguments_identical?(def_node, def_node.arguments.argument_list,
|
54
|
+
super_node.arguments)
|
45
55
|
|
46
56
|
add_offense(super_node) { |corrector| corrector.replace(super_node, 'super') }
|
47
57
|
end
|
@@ -49,7 +59,7 @@ module RuboCop
|
|
49
59
|
private
|
50
60
|
|
51
61
|
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
52
|
-
def arguments_identical?(def_args, super_args)
|
62
|
+
def arguments_identical?(def_node, def_args, super_args)
|
53
63
|
super_args = preprocess_super_args(super_args)
|
54
64
|
return false if def_args.size != super_args.size
|
55
65
|
|
@@ -58,7 +68,7 @@ module RuboCop
|
|
58
68
|
next if positional_rest_arg_same(def_arg, super_arg)
|
59
69
|
next if keyword_arg_same?(def_arg, super_arg)
|
60
70
|
next if keyword_rest_arg_same?(def_arg, super_arg)
|
61
|
-
next if block_arg_same?(def_arg, super_arg)
|
71
|
+
next if block_arg_same?(def_node, def_arg, super_arg)
|
62
72
|
next if forward_arg_same?(def_arg, super_arg)
|
63
73
|
|
64
74
|
return false
|
@@ -104,12 +114,21 @@ module RuboCop
|
|
104
114
|
def_arg.name == lvar_node.children.first
|
105
115
|
end
|
106
116
|
|
107
|
-
def block_arg_same?(def_arg, super_arg)
|
117
|
+
def block_arg_same?(def_node, def_arg, super_arg)
|
108
118
|
return false unless def_arg.blockarg_type? && super_arg.block_pass_type?
|
109
119
|
# anonymous forwarding
|
110
120
|
return true if (block_pass_child = super_arg.children.first).nil? && def_arg.name.nil?
|
111
121
|
|
112
|
-
|
122
|
+
block_arg_name = block_pass_child.children.first
|
123
|
+
def_arg.name == block_arg_name && !block_reassigned?(def_node, block_arg_name)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Reassigning the block argument will still pass along the original block to super
|
127
|
+
# https://bugs.ruby-lang.org/issues/20505
|
128
|
+
def block_reassigned?(def_node, block_arg_name)
|
129
|
+
def_node.each_node(*ASSIGN_TYPES).any? do |assign_node|
|
130
|
+
assign_node.name == block_arg_name
|
131
|
+
end
|
113
132
|
end
|
114
133
|
|
115
134
|
def forward_arg_same?(def_arg, super_arg)
|
data/lib/rubocop/cop/team.rb
CHANGED
data/lib/rubocop/lsp/routes.rb
CHANGED
@@ -235,7 +235,7 @@ module RuboCop
|
|
235
235
|
def to_range(location)
|
236
236
|
{
|
237
237
|
start: { character: location[:start_column] - 1, line: location[:start_line] - 1 },
|
238
|
-
end: { character: location[:last_column]
|
238
|
+
end: { character: location[:last_column], line: location[:last_line] - 1 }
|
239
239
|
}
|
240
240
|
end
|
241
241
|
end
|
data/lib/rubocop/version.rb
CHANGED
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.64.
|
4
|
+
version: 1.64.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: 2024-05-
|
13
|
+
date: 2024-05-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -1034,12 +1034,12 @@ licenses:
|
|
1034
1034
|
- MIT
|
1035
1035
|
metadata:
|
1036
1036
|
homepage_uri: https://rubocop.org/
|
1037
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.64.
|
1037
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.64.1
|
1038
1038
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1039
1039
|
documentation_uri: https://docs.rubocop.org/rubocop/1.64/
|
1040
1040
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
1041
1041
|
rubygems_mfa_required: 'true'
|
1042
|
-
post_install_message:
|
1042
|
+
post_install_message:
|
1043
1043
|
rdoc_options: []
|
1044
1044
|
require_paths:
|
1045
1045
|
- lib
|
@@ -1054,8 +1054,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1054
1054
|
- !ruby/object:Gem::Version
|
1055
1055
|
version: '0'
|
1056
1056
|
requirements: []
|
1057
|
-
rubygems_version: 3.
|
1058
|
-
signing_key:
|
1057
|
+
rubygems_version: 3.3.7
|
1058
|
+
signing_key:
|
1059
1059
|
specification_version: 4
|
1060
1060
|
summary: Automatic Ruby code style checking tool.
|
1061
1061
|
test_files: []
|