rubocop 1.31.1 → 1.31.2
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/lib/rubocop/config_loader_resolver.rb +1 -1
- data/lib/rubocop/cop/base.rb +1 -1
- data/lib/rubocop/cop/generator.rb +4 -0
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +54 -0
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +4 -3
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +3 -3
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +9 -5
- data/lib/rubocop/cop/mixin/def_node.rb +2 -7
- data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +6 -13
- data/lib/rubocop/cop/style/module_function.rb +2 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -1
- data/lib/rubocop/cop/style/top_level_method_definition.rb +0 -2
- data/lib/rubocop/rake_task.rb +5 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 998eb88b2df9c70d2b432d79cd43901b7e72d33714c2a1ac1e1ebf3f64d75b85
|
|
4
|
+
data.tar.gz: 335fd1c15204af498ebee7200f2958902ccfd96923f9530b589517a857967a72
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ceda90af46b2317f03cc4a86ea8aba7c63a96f12d55d6bea533ae2537d68bdc75a647f2d2a1f5103c1799f2dda6ec0f923351891050915a237919df241d39e1e
|
|
7
|
+
data.tar.gz: 8a0c5273cf612ca4717d619ce33b37dc2206beb4c6d247c3b501a67ec364861e18c24878b513c37b67e499084162cb70ab618e6e090f7876fda8da37c93d45d1
|
|
@@ -179,7 +179,7 @@ module RuboCop
|
|
|
179
179
|
|
|
180
180
|
def determine_inherit_mode(hash, key)
|
|
181
181
|
cop_cfg = hash[key]
|
|
182
|
-
local_inherit = cop_cfg
|
|
182
|
+
local_inherit = cop_cfg['inherit_mode'] if cop_cfg.is_a?(Hash)
|
|
183
183
|
local_inherit || hash['inherit_mode'] || {}
|
|
184
184
|
end
|
|
185
185
|
|
data/lib/rubocop/cop/base.rb
CHANGED
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
|
48
48
|
InvestigationReport = Struct.new(:cop, :processed_source, :offenses, :corrector)
|
|
49
49
|
|
|
50
50
|
# List of methods names to restrict calls for `on_send` / `on_csend`
|
|
51
|
-
RESTRICT_ON_SEND = Set[].freeze
|
|
51
|
+
RESTRICT_ON_SEND = Set[].freeze # rubocop:disable InternalAffairs/UselessRestrictOnSend
|
|
52
52
|
|
|
53
53
|
# List of cops that should not try to autocorrect at the same
|
|
54
54
|
# time as this cop
|
|
@@ -62,6 +62,10 @@ module RuboCop
|
|
|
62
62
|
# For example
|
|
63
63
|
MSG = 'Use `#good_method` instead of `#bad_method`.'
|
|
64
64
|
|
|
65
|
+
# TODO: Don't call `on_send` unless the method name is in this list
|
|
66
|
+
# If you don't need `on_send` in the cop you created, remove it.
|
|
67
|
+
RESTRICT_ON_SEND = %%i[bad_method].freeze
|
|
68
|
+
|
|
65
69
|
# @!method bad_method?(node)
|
|
66
70
|
def_node_matcher :bad_method?, <<~PATTERN
|
|
67
71
|
(send nil? :bad_method ...)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module InternalAffairs
|
|
6
|
+
# Check for useless `RESTRICT_ON_SEND`.
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# # bad
|
|
10
|
+
# class FooCop
|
|
11
|
+
# RESTRICT_ON_SEND = %i[bad_method].freeze
|
|
12
|
+
# end
|
|
13
|
+
#
|
|
14
|
+
# # good
|
|
15
|
+
# class FooCop
|
|
16
|
+
# RESTRICT_ON_SEND = %i[bad_method].freeze
|
|
17
|
+
# def on_send(node)
|
|
18
|
+
# # ...
|
|
19
|
+
# end
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
22
|
+
# # good
|
|
23
|
+
# class FooCop
|
|
24
|
+
# RESTRICT_ON_SEND = %i[bad_method].freeze
|
|
25
|
+
# def after_send(node)
|
|
26
|
+
# # ...
|
|
27
|
+
# end
|
|
28
|
+
# end
|
|
29
|
+
#
|
|
30
|
+
class UselessRestrictOnSend < Base
|
|
31
|
+
extend AutoCorrector
|
|
32
|
+
|
|
33
|
+
MSG = 'Useless `RESTRICT_ON_SEND` is defined.'
|
|
34
|
+
|
|
35
|
+
# @!method defined_send_callback?(node)
|
|
36
|
+
def_node_search :defined_send_callback?, '(def {:on_send :after_send} ...)'
|
|
37
|
+
|
|
38
|
+
def on_casgn(node)
|
|
39
|
+
return if !restrict_on_send?(node) || defined_send_callback?(node.parent)
|
|
40
|
+
|
|
41
|
+
add_offense(node) do |corrector|
|
|
42
|
+
corrector.remove(node)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def restrict_on_send?(node)
|
|
49
|
+
node.name == :RESTRICT_ON_SEND
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -20,3 +20,4 @@ require_relative 'internal_affairs/redundant_method_dispatch_node'
|
|
|
20
20
|
require_relative 'internal_affairs/style_detected_api_use'
|
|
21
21
|
require_relative 'internal_affairs/undefined_config'
|
|
22
22
|
require_relative 'internal_affairs/useless_message_assertion'
|
|
23
|
+
require_relative 'internal_affairs/useless_restrict_on_send'
|
|
@@ -120,14 +120,15 @@ module RuboCop
|
|
|
120
120
|
check_first(first_elem, left_bracket, left_parenthesis, 0)
|
|
121
121
|
end
|
|
122
122
|
|
|
123
|
-
check_right_bracket(array_node.loc.end, left_bracket, left_parenthesis)
|
|
123
|
+
check_right_bracket(array_node.loc.end, first_elem, left_bracket, left_parenthesis)
|
|
124
124
|
end
|
|
125
125
|
|
|
126
|
-
def check_right_bracket(right_bracket, left_bracket, left_parenthesis)
|
|
126
|
+
def check_right_bracket(right_bracket, first_elem, left_bracket, left_parenthesis)
|
|
127
127
|
# if the right bracket is on the same line as the last value, accept
|
|
128
128
|
return if /\S/.match?(right_bracket.source_line[0...right_bracket.column])
|
|
129
129
|
|
|
130
|
-
expected_column, indent_base_type = indent_base(left_bracket,
|
|
130
|
+
expected_column, indent_base_type = indent_base(left_bracket, first_elem,
|
|
131
|
+
left_parenthesis)
|
|
131
132
|
@column_delta = expected_column - right_bracket.column
|
|
132
133
|
return if @column_delta.zero?
|
|
133
134
|
|
|
@@ -158,14 +158,14 @@ module RuboCop
|
|
|
158
158
|
end
|
|
159
159
|
end
|
|
160
160
|
|
|
161
|
-
check_right_brace(hash_node.loc.end, left_brace, left_parenthesis)
|
|
161
|
+
check_right_brace(hash_node.loc.end, first_pair, left_brace, left_parenthesis)
|
|
162
162
|
end
|
|
163
163
|
|
|
164
|
-
def check_right_brace(right_brace, left_brace, left_parenthesis)
|
|
164
|
+
def check_right_brace(right_brace, first_pair, left_brace, left_parenthesis)
|
|
165
165
|
# if the right brace is on the same line as the last value, accept
|
|
166
166
|
return if /\S/.match?(right_brace.source_line[0...right_brace.column])
|
|
167
167
|
|
|
168
|
-
expected_column, indent_base_type = indent_base(left_brace, left_parenthesis)
|
|
168
|
+
expected_column, indent_base_type = indent_base(left_brace, first_pair, left_parenthesis)
|
|
169
169
|
@column_delta = expected_column - right_brace.column
|
|
170
170
|
return if @column_delta.zero?
|
|
171
171
|
|
|
@@ -71,18 +71,22 @@ module RuboCop
|
|
|
71
71
|
PATTERN
|
|
72
72
|
|
|
73
73
|
def on_send(node)
|
|
74
|
-
return unless node.parent
|
|
75
|
-
return if
|
|
74
|
+
return unless (parent = node.parent) && parent.if_type?
|
|
75
|
+
return if allowable_use_with_if?(parent)
|
|
76
76
|
return if explicit_not_force?(node)
|
|
77
|
-
return unless (exist_node = send_exist_node(
|
|
77
|
+
return unless (exist_node = send_exist_node(parent).first)
|
|
78
78
|
return unless exist_node.first_argument == node.first_argument
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
register_offense(node, exist_node)
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
private
|
|
84
84
|
|
|
85
|
-
def
|
|
85
|
+
def allowable_use_with_if?(if_node)
|
|
86
|
+
if_node.condition.and_type? || if_node.condition.or_type? || if_node.else_branch
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def register_offense(node, exist_node)
|
|
86
90
|
range = range_between(node.parent.loc.keyword.begin_pos,
|
|
87
91
|
exist_node.loc.expression.end_pos)
|
|
88
92
|
|
|
@@ -5,8 +5,7 @@ module RuboCop
|
|
|
5
5
|
# Common functionality for checking def nodes.
|
|
6
6
|
module DefNode
|
|
7
7
|
extend NodePattern::Macros
|
|
8
|
-
|
|
9
|
-
NON_PUBLIC_MODIFIERS = %w[private protected].freeze
|
|
8
|
+
include VisibilityHelp
|
|
10
9
|
|
|
11
10
|
private
|
|
12
11
|
|
|
@@ -15,11 +14,7 @@ module RuboCop
|
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
def preceding_non_public_modifier?(node)
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def stripped_source_upto(index)
|
|
22
|
-
processed_source[0..index].map(&:strip)
|
|
17
|
+
node_visibility(node) != :public
|
|
23
18
|
end
|
|
24
19
|
|
|
25
20
|
# @!method non_public_modifier?(node)
|
|
@@ -26,7 +26,7 @@ module RuboCop
|
|
|
26
26
|
def check_first(first, left_brace, left_parenthesis, offset)
|
|
27
27
|
actual_column = first.source_range.column
|
|
28
28
|
|
|
29
|
-
indent_base_column, indent_base_type = indent_base(left_brace, left_parenthesis)
|
|
29
|
+
indent_base_column, indent_base_type = indent_base(left_brace, first, left_parenthesis)
|
|
30
30
|
expected_column = indent_base_column + configured_indentation_width + offset
|
|
31
31
|
|
|
32
32
|
@column_delta = expected_column - actual_column
|
|
@@ -47,10 +47,10 @@ module RuboCop
|
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
def indent_base(left_brace, left_parenthesis)
|
|
50
|
+
def indent_base(left_brace, first, left_parenthesis)
|
|
51
51
|
return [left_brace.column, :left_brace_or_bracket] if style == brace_alignment_style
|
|
52
52
|
|
|
53
|
-
pair = hash_pair_where_value_beginning_with(left_brace)
|
|
53
|
+
pair = hash_pair_where_value_beginning_with(left_brace, first)
|
|
54
54
|
if pair && key_and_value_begin_on_same_line?(pair) &&
|
|
55
55
|
right_sibling_begins_on_subsequent_line?(pair)
|
|
56
56
|
return [pair.loc.column, :parent_hash_key]
|
|
@@ -63,17 +63,10 @@ module RuboCop
|
|
|
63
63
|
[left_brace.source_line =~ /\S/, :start_of_line]
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
def hash_pair_where_value_beginning_with(left_brace)
|
|
67
|
-
|
|
68
|
-
node.parent&.pair_type? ? node.parent : nil
|
|
69
|
-
end
|
|
66
|
+
def hash_pair_where_value_beginning_with(left_brace, first)
|
|
67
|
+
return unless first && first.parent.loc.begin == left_brace
|
|
70
68
|
|
|
71
|
-
|
|
72
|
-
processed_source.ast.each_descendant do |node|
|
|
73
|
-
if node.loc.is_a?(Parser::Source::Map::Collection) && (node.loc.begin == left_brace)
|
|
74
|
-
break node
|
|
75
|
-
end
|
|
76
|
-
end
|
|
69
|
+
first.parent&.parent&.pair_type? ? first.parent.parent : nil
|
|
77
70
|
end
|
|
78
71
|
|
|
79
72
|
def key_and_value_begin_on_same_line?(pair)
|
|
@@ -117,10 +117,10 @@ module RuboCop
|
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
def check_module_function(nodes)
|
|
120
|
-
|
|
120
|
+
return if nodes.any? { |node| private_directive?(node) }
|
|
121
121
|
|
|
122
122
|
nodes.each do |node|
|
|
123
|
-
yield node if extend_self_node?(node)
|
|
123
|
+
yield node if extend_self_node?(node)
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
126
|
|
|
@@ -81,7 +81,8 @@ module RuboCop
|
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
def like_method_argument_parentheses?(node)
|
|
84
|
-
node.send_type? && node.arguments.
|
|
84
|
+
node.send_type? && node.arguments.one? &&
|
|
85
|
+
!node.arithmetic_operation? && node.first_argument.begin_type?
|
|
85
86
|
end
|
|
86
87
|
|
|
87
88
|
def empty_parentheses?(node)
|
data/lib/rubocop/rake_task.rb
CHANGED
|
@@ -73,11 +73,15 @@ module RuboCop
|
|
|
73
73
|
namespace(name) do
|
|
74
74
|
# rubocop:todo Naming/InclusiveLanguage
|
|
75
75
|
task(:auto_correct, *args) do
|
|
76
|
+
require 'rainbow'
|
|
76
77
|
warn Rainbow(
|
|
77
78
|
'rubocop:auto_correct task is deprecated; ' \
|
|
78
79
|
'use rubocop:autocorrect task or rubocop:autocorrect_all task instead.'
|
|
79
80
|
).yellow
|
|
80
|
-
|
|
81
|
+
RakeFileUtils.verbose(verbose) do
|
|
82
|
+
yield(*[self, task_args].slice(0, task_block.arity)) if task_block
|
|
83
|
+
perform('--autocorrect')
|
|
84
|
+
end
|
|
81
85
|
end
|
|
82
86
|
# rubocop:enable Naming/InclusiveLanguage
|
|
83
87
|
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
|
@@ -72,7 +72,6 @@ require_relative 'rubocop/cop/mixin/configurable_enforced_style'
|
|
|
72
72
|
require_relative 'rubocop/cop/mixin/configurable_formatting'
|
|
73
73
|
require_relative 'rubocop/cop/mixin/configurable_naming'
|
|
74
74
|
require_relative 'rubocop/cop/mixin/configurable_numbering'
|
|
75
|
-
require_relative 'rubocop/cop/mixin/def_node'
|
|
76
75
|
require_relative 'rubocop/cop/mixin/documentation_comment'
|
|
77
76
|
require_relative 'rubocop/cop/mixin/duplication'
|
|
78
77
|
require_relative 'rubocop/cop/mixin/range_help'
|
|
@@ -130,6 +129,7 @@ require_relative 'rubocop/cop/mixin/uncommunicative_name'
|
|
|
130
129
|
require_relative 'rubocop/cop/mixin/unused_argument'
|
|
131
130
|
require_relative 'rubocop/cop/mixin/visibility_help'
|
|
132
131
|
require_relative 'rubocop/cop/mixin/comments_help' # relies on visibility_help
|
|
132
|
+
require_relative 'rubocop/cop/mixin/def_node' # relies on visibility_help
|
|
133
133
|
|
|
134
134
|
require_relative 'rubocop/cop/utils/format_string'
|
|
135
135
|
|
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.31.
|
|
4
|
+
version: 1.31.2
|
|
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: 2022-
|
|
13
|
+
date: 2022-07-07 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: json
|
|
@@ -301,6 +301,7 @@ files:
|
|
|
301
301
|
- lib/rubocop/cop/internal_affairs/style_detected_api_use.rb
|
|
302
302
|
- lib/rubocop/cop/internal_affairs/undefined_config.rb
|
|
303
303
|
- lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
|
|
304
|
+
- lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb
|
|
304
305
|
- lib/rubocop/cop/layout/access_modifier_indentation.rb
|
|
305
306
|
- lib/rubocop/cop/layout/argument_alignment.rb
|
|
306
307
|
- lib/rubocop/cop/layout/array_alignment.rb
|
|
@@ -985,7 +986,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
985
986
|
- !ruby/object:Gem::Version
|
|
986
987
|
version: '0'
|
|
987
988
|
requirements: []
|
|
988
|
-
rubygems_version: 3.2
|
|
989
|
+
rubygems_version: 3.1.2
|
|
989
990
|
signing_key:
|
|
990
991
|
specification_version: 4
|
|
991
992
|
summary: Automatic Ruby code style checking tool.
|