rubocop 1.28.0 → 1.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/config/default.yml +21 -6
- data/lib/rubocop/cop/badge.rb +1 -1
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/gemspec/dependency_version.rb +156 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +3 -6
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +80 -0
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_brackets.rb +7 -0
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -1
- data/lib/rubocop/cop/layout/trailing_empty_lines.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +2 -1
- data/lib/rubocop/cop/lint/ambiguous_range.rb +2 -2
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +0 -3
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +1 -1
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +1 -1
- data/lib/rubocop/cop/lint/return_in_void_context.rb +5 -17
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +5 -0
- data/lib/rubocop/cop/mixin/duplication.rb +1 -1
- data/lib/rubocop/cop/mixin/preferred_delimiters.rb +2 -2
- data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +1 -1
- data/lib/rubocop/cop/naming/file_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +2 -2
- data/lib/rubocop/cop/naming/variable_name.rb +9 -0
- data/lib/rubocop/cop/naming/variable_number.rb +10 -0
- data/lib/rubocop/cop/security/yaml_load.rb +1 -1
- data/lib/rubocop/cop/style/alias.rb +3 -3
- data/lib/rubocop/cop/style/and_or.rb +1 -1
- data/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +5 -0
- data/lib/rubocop/cop/style/case_like_if.rb +1 -1
- data/lib/rubocop/cop/style/character_literal.rb +1 -1
- data/lib/rubocop/cop/style/collection_compact.rb +3 -3
- data/lib/rubocop/cop/style/date_time.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +28 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +1 -1
- data/lib/rubocop/cop/style/empty_literal.rb +1 -1
- data/lib/rubocop/cop/style/env_home.rb +56 -0
- data/lib/rubocop/cop/style/fetch_env_var.rb +256 -15
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +2 -2
- data/lib/rubocop/cop/style/map_to_hash.rb +0 -3
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +5 -1
- data/lib/rubocop/cop/style/next.rb +1 -1
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
- data/lib/rubocop/cop/style/optional_boolean_parameter.rb +1 -1
- data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +77 -7
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
- data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
- data/lib/rubocop/cop/style/slicing_with_range.rb +0 -3
- data/lib/rubocop/cop/style/string_chars.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +7 -8
- data/lib/rubocop/cops_documentation_generator.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +1 -0
- data/lib/rubocop/formatter/html_formatter.rb +2 -9
- data/lib/rubocop/formatter/markdown_formatter.rb +76 -0
- data/lib/rubocop/magic_comment.rb +4 -3
- data/lib/rubocop/options.rb +4 -3
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/parallel_formatter.rb +1 -1
- data/lib/rubocop/rspec/shared_contexts.rb +1 -5
- data/lib/rubocop/runner.rb +1 -1
- data/lib/rubocop/string_interpreter.rb +4 -4
- data/lib/rubocop/target_ruby.rb +8 -2
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +3 -1
- metadata +17 -8
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 155e1b253bffe887bc046c38febc46563a88b77ce29d4cbacc3e33f034e6e7be
|
4
|
+
data.tar.gz: 16d70c60ef38d1fab5de15d98f5408f9304ef07de75c10d99a798d7ce2228d8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18820cc0427edc64afcbb6e057f9d0dc6c091632ea31f140992cbccf0b075abf7c1484257aab61391bdbb6e31a2341c5469f64caf666e6edb68fd61606d4ebe5
|
7
|
+
data.tar.gz: 286cfc060c368697258b551ae330dc7cead75710baaba53c33622da59026c6a36f4db313af2a1610ed522696d57695e6f2f87ab939a93b5b5f43e584f420ba0e
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
|
|
53
53
|
in your `Gemfile`:
|
54
54
|
|
55
55
|
```rb
|
56
|
-
gem 'rubocop', '~> 1.
|
56
|
+
gem 'rubocop', '~> 1.29', require: false
|
57
57
|
```
|
58
58
|
|
59
59
|
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
|
@@ -75,8 +75,8 @@ You can read a lot more about RuboCop in its [official docs](https://docs.ruboco
|
|
75
75
|
|
76
76
|
RuboCop officially supports the following Ruby implementations:
|
77
77
|
|
78
|
-
* MRI 2.
|
79
|
-
* JRuby 9.
|
78
|
+
* MRI 2.6+
|
79
|
+
* JRuby 9.3+
|
80
80
|
|
81
81
|
See the [compatibility documentation](https://docs.rubocop.org/rubocop/compatibility.html) for further details.
|
82
82
|
|
data/config/default.yml
CHANGED
@@ -140,7 +140,7 @@ AllCops:
|
|
140
140
|
# or gems.locked file. (Although the Ruby version is specified in the Gemfile
|
141
141
|
# or gems.rb file, RuboCop reads the final value from the lock file.) If the
|
142
142
|
# Ruby version is still unresolved, RuboCop will use the oldest officially
|
143
|
-
# supported Ruby version (currently Ruby 2.
|
143
|
+
# supported Ruby version (currently Ruby 2.6).
|
144
144
|
TargetRubyVersion: ~
|
145
145
|
# Determines if a notification for extension libraries should be shown when
|
146
146
|
# rubocop is run. Keys are the name of the extension, and values are an array
|
@@ -242,6 +242,18 @@ Gemspec/DateAssignment:
|
|
242
242
|
Include:
|
243
243
|
- '**/*.gemspec'
|
244
244
|
|
245
|
+
Gemspec/DependencyVersion:
|
246
|
+
Description: 'Requires or forbids specifying gem dependency versions.'
|
247
|
+
Enabled: false
|
248
|
+
VersionAdded: '1.29'
|
249
|
+
EnforcedStyle: 'required'
|
250
|
+
SupportedStyles:
|
251
|
+
- 'required'
|
252
|
+
- 'forbidden'
|
253
|
+
Include:
|
254
|
+
- '**/*.gemspec'
|
255
|
+
AllowedGems: []
|
256
|
+
|
245
257
|
Gemspec/DuplicatedAssignment:
|
246
258
|
Description: 'An attribute assignment method calls should be listed only once in a gemspec.'
|
247
259
|
Enabled: true
|
@@ -2329,11 +2341,6 @@ Lint/UselessAssignment:
|
|
2329
2341
|
Enabled: true
|
2330
2342
|
VersionAdded: '0.11'
|
2331
2343
|
|
2332
|
-
Lint/UselessElseWithoutRescue:
|
2333
|
-
Description: 'Checks for useless `else` in `begin..end` without `rescue`.'
|
2334
|
-
Enabled: true
|
2335
|
-
VersionAdded: '0.17'
|
2336
|
-
|
2337
2344
|
Lint/UselessMethodDefinition:
|
2338
2345
|
Description: 'Checks for useless method definitions.'
|
2339
2346
|
Enabled: true
|
@@ -2772,6 +2779,7 @@ Naming/VariableName:
|
|
2772
2779
|
- snake_case
|
2773
2780
|
- camelCase
|
2774
2781
|
AllowedIdentifiers: []
|
2782
|
+
AllowedPatterns: []
|
2775
2783
|
|
2776
2784
|
Naming/VariableNumber:
|
2777
2785
|
Description: 'Use the configured style when numbering symbols, methods and variables.'
|
@@ -2793,6 +2801,7 @@ Naming/VariableNumber:
|
|
2793
2801
|
- rfc822 # Time#rfc822
|
2794
2802
|
- rfc2822 # Time#rfc2822
|
2795
2803
|
- rfc3339 # DateTime.rfc3339
|
2804
|
+
AllowedPatterns: []
|
2796
2805
|
|
2797
2806
|
#################### Security ##############################
|
2798
2807
|
|
@@ -3495,6 +3504,12 @@ Style/EndlessMethod:
|
|
3495
3504
|
- allow_always
|
3496
3505
|
- disallow
|
3497
3506
|
|
3507
|
+
Style/EnvHome:
|
3508
|
+
Description: "Checks for consistent usage of `ENV['HOME']`."
|
3509
|
+
Enabled: pending
|
3510
|
+
Safe: false
|
3511
|
+
VersionAdded: '1.29'
|
3512
|
+
|
3498
3513
|
Style/EvalWithLocation:
|
3499
3514
|
Description: 'Pass `__FILE__` and `__LINE__` to `eval` method, as they are used by backtraces.'
|
3500
3515
|
Enabled: true
|
data/lib/rubocop/cop/badge.rb
CHANGED
@@ -15,7 +15,7 @@ module RuboCop
|
|
15
15
|
def self.for(class_name)
|
16
16
|
parts = class_name.split('::')
|
17
17
|
name_deep_enough = parts.length >= 4
|
18
|
-
new(name_deep_enough ? parts[2
|
18
|
+
new(name_deep_enough ? parts[2..] : parts.last(2))
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.parse(identifier)
|
@@ -152,7 +152,7 @@ module RuboCop
|
|
152
152
|
def restrictive_version_specified_gem?(node)
|
153
153
|
return unless version_specified_gem?(node)
|
154
154
|
|
155
|
-
node.arguments[1
|
155
|
+
node.arguments[1..]
|
156
156
|
.any? { |arg| arg&.str_type? && RESTRICTIVE_VERSION_PATTERN.match?(arg.value) }
|
157
157
|
end
|
158
158
|
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Gemspec
|
6
|
+
# Enforce that gem dependency version specifications or a commit reference (branch,
|
7
|
+
# ref, or tag) are either required or forbidden.
|
8
|
+
#
|
9
|
+
# @example EnforcedStyle: required (default)
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# Gem::Specification.new do |spec|
|
13
|
+
# spec.add_dependency 'parser'
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
# Gem::Specification.new do |spec|
|
18
|
+
# spec.add_development_dependency 'parser'
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# # good
|
22
|
+
# Gem::Specification.new do |spec|
|
23
|
+
# spec.add_dependency 'parser', '>= 2.3.3.1', '< 3.0'
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# # good
|
27
|
+
# Gem::Specification.new do |spec|
|
28
|
+
# spec.add_development_dependency 'parser', '>= 2.3.3.1', '< 3.0'
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# @example EnforcedStyle: forbidden
|
32
|
+
#
|
33
|
+
# # bad
|
34
|
+
# Gem::Specification.new do |spec|
|
35
|
+
# spec.add_dependency 'parser', '>= 2.3.3.1', '< 3.0'
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# # bad
|
39
|
+
# Gem::Specification.new do |spec|
|
40
|
+
# spec.add_development_dependency 'parser', '>= 2.3.3.1', '< 3.0'
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# # good
|
44
|
+
# Gem::Specification.new do |spec|
|
45
|
+
# spec.add_dependency 'parser'
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# # good
|
49
|
+
# Gem::Specification.new do |spec|
|
50
|
+
# spec.add_development_dependency 'parser'
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
class DependencyVersion < Base
|
54
|
+
include ConfigurableEnforcedStyle
|
55
|
+
include GemspecHelp
|
56
|
+
|
57
|
+
REQUIRED_MSG = 'Dependency version specification is required.'
|
58
|
+
FORBIDDEN_MSG = 'Dependency version specification is forbidden.'
|
59
|
+
VERSION_SPECIFICATION_REGEX = /^\s*[~<>=]*\s*[0-9.]+/.freeze
|
60
|
+
|
61
|
+
# @!method add_dependency_method_declarations(node)
|
62
|
+
def_node_search :add_dependency_method_declarations, <<~PATTERN
|
63
|
+
(send
|
64
|
+
(lvar #match_block_variable_name?) #add_dependency_method? ...)
|
65
|
+
PATTERN
|
66
|
+
|
67
|
+
# @!method includes_version_specification?(node)
|
68
|
+
def_node_matcher :includes_version_specification?, <<~PATTERN
|
69
|
+
(send _ #add_dependency_method? <(str #version_specification?) ...>)
|
70
|
+
PATTERN
|
71
|
+
|
72
|
+
# @!method includes_commit_reference?(node)
|
73
|
+
def_node_matcher :includes_commit_reference?, <<~PATTERN
|
74
|
+
(send _ #add_dependency_method? <(hash <(pair (sym {:branch :ref :tag}) (str _)) ...>) ...>)
|
75
|
+
PATTERN
|
76
|
+
|
77
|
+
def on_new_investigation
|
78
|
+
return if processed_source.blank?
|
79
|
+
|
80
|
+
add_dependency_method_nodes.each do |node|
|
81
|
+
next if allowed_gem?(node)
|
82
|
+
|
83
|
+
if offense?(node)
|
84
|
+
add_offense(node)
|
85
|
+
opposite_style_detected
|
86
|
+
else
|
87
|
+
correct_style_detected
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def allowed_gem?(node)
|
95
|
+
allowed_gems.include?(node.first_argument.value)
|
96
|
+
end
|
97
|
+
|
98
|
+
def allowed_gems
|
99
|
+
Array(cop_config['AllowedGems'])
|
100
|
+
end
|
101
|
+
|
102
|
+
def message(range)
|
103
|
+
gem_specification = range.source
|
104
|
+
|
105
|
+
if required_style?
|
106
|
+
format(REQUIRED_MSG, gem_specification: gem_specification)
|
107
|
+
elsif forbidden_style?
|
108
|
+
format(FORBIDDEN_MSG, gem_specification: gem_specification)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def match_block_variable_name?(receiver_name)
|
113
|
+
gem_specification(processed_source.ast) do |block_variable_name|
|
114
|
+
return block_variable_name == receiver_name
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def add_dependency_method?(method_name)
|
119
|
+
method_name.to_s.end_with?('_dependency')
|
120
|
+
end
|
121
|
+
|
122
|
+
def add_dependency_method_nodes
|
123
|
+
add_dependency_method_declarations(processed_source.ast)
|
124
|
+
end
|
125
|
+
|
126
|
+
def offense?(node)
|
127
|
+
required_offense?(node) || forbidden_offense?(node)
|
128
|
+
end
|
129
|
+
|
130
|
+
def required_offense?(node)
|
131
|
+
return unless required_style?
|
132
|
+
|
133
|
+
!includes_version_specification?(node) && !includes_commit_reference?(node)
|
134
|
+
end
|
135
|
+
|
136
|
+
def forbidden_offense?(node)
|
137
|
+
return unless forbidden_style?
|
138
|
+
|
139
|
+
includes_version_specification?(node) || includes_commit_reference?(node)
|
140
|
+
end
|
141
|
+
|
142
|
+
def forbidden_style?
|
143
|
+
style == :forbidden
|
144
|
+
end
|
145
|
+
|
146
|
+
def required_style?
|
147
|
+
style == :required
|
148
|
+
end
|
149
|
+
|
150
|
+
def version_specification?(expression)
|
151
|
+
expression.match?(VERSION_SPECIFICATION_REGEX)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -44,14 +44,14 @@ module RuboCop
|
|
44
44
|
# @!method assignment_method_declarations(node)
|
45
45
|
def_node_search :assignment_method_declarations, <<~PATTERN
|
46
46
|
(send
|
47
|
-
(lvar #match_block_variable_name?)
|
47
|
+
(lvar #match_block_variable_name?) _ ...)
|
48
48
|
PATTERN
|
49
49
|
|
50
50
|
def on_new_investigation
|
51
51
|
return if processed_source.blank?
|
52
52
|
|
53
53
|
duplicated_assignment_method_nodes.each do |nodes|
|
54
|
-
nodes[1
|
54
|
+
nodes[1..].each do |node|
|
55
55
|
register_offense(node, node.method_name, nodes.first.first_line)
|
56
56
|
end
|
57
57
|
end
|
@@ -65,12 +65,9 @@ module RuboCop
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
def assignment_method?(method_name)
|
69
|
-
method_name.to_s.end_with?('=')
|
70
|
-
end
|
71
|
-
|
72
68
|
def duplicated_assignment_method_nodes
|
73
69
|
assignment_method_declarations(processed_source.ast)
|
70
|
+
.select(&:assignment_method?)
|
74
71
|
.group_by(&:method_name)
|
75
72
|
.values
|
76
73
|
.select { |nodes| nodes.size > 1 }
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# This cop checks potentially usage of method identifier predicates
|
7
|
+
# defined in rubocop-ast instead of `method_name.end_with?`.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# node.method_name.to_s.end_with?('=')
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# node.assignment_method?
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
# node.method_name.to_s.end_with?('?')
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# node.predicate_method?
|
21
|
+
#
|
22
|
+
# # bad
|
23
|
+
# node.method_name.to_s.end_with?('!')
|
24
|
+
#
|
25
|
+
# # good
|
26
|
+
# node.bang_method?
|
27
|
+
#
|
28
|
+
class MethodNameEndWith < Base
|
29
|
+
include RangeHelp
|
30
|
+
extend AutoCorrector
|
31
|
+
|
32
|
+
MSG = 'Use `%<method_name>s` instead of `%<method_suffix>s`.'
|
33
|
+
SUGGEST_METHOD_FOR_SUFFIX = {
|
34
|
+
'=' => 'assignment_method?',
|
35
|
+
'!' => 'bang_method?',
|
36
|
+
'?' => 'predicate_method?'
|
37
|
+
}.freeze
|
38
|
+
|
39
|
+
# @!method method_name_end_with?(node)
|
40
|
+
def_node_matcher :method_name_end_with?, <<~PATTERN
|
41
|
+
{
|
42
|
+
(call
|
43
|
+
(call
|
44
|
+
$(... :method_name) :to_s) :end_with?
|
45
|
+
$(str {"=" "?" "!"}))
|
46
|
+
(call
|
47
|
+
$(... :method_name) :end_with?
|
48
|
+
$(str {"=" "?" "!"}))
|
49
|
+
}
|
50
|
+
PATTERN
|
51
|
+
|
52
|
+
def on_send(node)
|
53
|
+
method_name_end_with?(node) do |method_name_node, end_with_arg|
|
54
|
+
range = range(method_name_node, node)
|
55
|
+
message = format(
|
56
|
+
MSG,
|
57
|
+
method_name: SUGGEST_METHOD_FOR_SUFFIX[end_with_arg.value],
|
58
|
+
method_suffix: range.source
|
59
|
+
)
|
60
|
+
|
61
|
+
add_offense(range, message: message)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
alias on_csend on_send
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def range(method_name_node, node)
|
69
|
+
range = if method_name_node.call_type?
|
70
|
+
method_name_node.loc.selector
|
71
|
+
else
|
72
|
+
method_name_node.source_range
|
73
|
+
end
|
74
|
+
|
75
|
+
range_between(range.begin_pos, node.source_range.end_pos)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -4,6 +4,7 @@ require_relative 'internal_affairs/empty_line_between_expect_offense_and_correct
|
|
4
4
|
require_relative 'internal_affairs/example_description'
|
5
5
|
require_relative 'internal_affairs/inherit_deprecated_cop_class'
|
6
6
|
require_relative 'internal_affairs/location_line_equality_comparison'
|
7
|
+
require_relative 'internal_affairs/method_name_end_with'
|
7
8
|
require_relative 'internal_affairs/method_name_equal'
|
8
9
|
require_relative 'internal_affairs/node_destructuring'
|
9
10
|
require_relative 'internal_affairs/node_matcher_directive'
|
@@ -139,7 +139,7 @@ module RuboCop
|
|
139
139
|
|
140
140
|
def line_after_comment(comment)
|
141
141
|
lines = processed_source.lines
|
142
|
-
lines[comment.loc.line
|
142
|
+
lines[comment.loc.line..].find { |line| !line.blank? }
|
143
143
|
end
|
144
144
|
|
145
145
|
def correct_indentation(next_line)
|
@@ -110,7 +110,7 @@ module RuboCop
|
|
110
110
|
|
111
111
|
def check_aligned(children, start_index)
|
112
112
|
base_column = children[start_index - 1].loc.column
|
113
|
-
children[start_index
|
113
|
+
children[start_index..].each do |child|
|
114
114
|
@column_delta = base_column - child.loc.column
|
115
115
|
add_offense_and_correction(child, MSG_ALIGN) if @column_delta != 0
|
116
116
|
base_column = child.loc.column
|
@@ -113,7 +113,7 @@ module RuboCop
|
|
113
113
|
def last_end_pos_inside_pipes(arguments, range)
|
114
114
|
pos = range.end_pos
|
115
115
|
num = pos - arguments.source_range.begin_pos
|
116
|
-
trailing_comma_index = arguments.source[num
|
116
|
+
trailing_comma_index = arguments.source[num..].index(',')
|
117
117
|
|
118
118
|
trailing_comma_index ? pos + trailing_comma_index + 1 : pos
|
119
119
|
end
|
@@ -37,6 +37,7 @@ module RuboCop
|
|
37
37
|
receiver_end_pos = node.receiver.source_range.end_pos
|
38
38
|
selector_begin_pos = node.loc.selector.begin_pos
|
39
39
|
return if receiver_end_pos >= selector_begin_pos
|
40
|
+
return if dot_before_brackets?(node, receiver_end_pos, selector_begin_pos)
|
40
41
|
|
41
42
|
range_between(receiver_end_pos, selector_begin_pos)
|
42
43
|
elsif node.method?(:[]=)
|
@@ -44,6 +45,12 @@ module RuboCop
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
48
|
+
def dot_before_brackets?(node, receiver_end_pos, selector_begin_pos)
|
49
|
+
return false unless node.loc.respond_to?(:dot) && (dot = node.loc.dot)
|
50
|
+
|
51
|
+
dot.begin_pos == receiver_end_pos && dot.end_pos == selector_begin_pos
|
52
|
+
end
|
53
|
+
|
47
54
|
def offense_range_for_assignment(node, begin_pos)
|
48
55
|
end_pos = node.receiver.source_range.end_pos
|
49
56
|
|
@@ -118,7 +118,7 @@ module RuboCop
|
|
118
118
|
i = tokens.index(opening_bracket)
|
119
119
|
inner_left_brackets_needing_closure = 0
|
120
120
|
|
121
|
-
tokens[i
|
121
|
+
tokens[i..].each do |token|
|
122
122
|
inner_left_brackets_needing_closure += 1 if token.left_bracket?
|
123
123
|
inner_left_brackets_needing_closure -= 1 if token.right_bracket?
|
124
124
|
return token if inner_left_brackets_needing_closure.zero? && token.right_bracket?
|
@@ -82,7 +82,7 @@ module RuboCop
|
|
82
82
|
return true if buffer.source.strip.start_with?('__END__')
|
83
83
|
return false if processed_source.tokens.empty?
|
84
84
|
|
85
|
-
extra = buffer.source[processed_source.tokens.last.end_pos
|
85
|
+
extra = buffer.source[processed_source.tokens.last.end_pos..]
|
86
86
|
extra&.strip&.start_with?('__END__')
|
87
87
|
end
|
88
88
|
|
@@ -44,7 +44,8 @@ module RuboCop
|
|
44
44
|
return unless node.arguments?
|
45
45
|
|
46
46
|
return unless ambiguous_block_association?(node)
|
47
|
-
return if node.parenthesized? || node.last_argument.lambda? ||
|
47
|
+
return if node.parenthesized? || node.last_argument.lambda? || node.last_argument.proc? ||
|
48
|
+
allowed_method?(node)
|
48
49
|
|
49
50
|
message = message(node)
|
50
51
|
|
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Lint
|
6
6
|
# This cop checks for ambiguous ranges.
|
7
7
|
#
|
8
|
-
# Ranges have quite low precedence, which leads to unexpected
|
8
|
+
# Ranges have quite low precedence, which leads to unexpected behavior when
|
9
9
|
# using a range with other operators. This cop avoids that by making ranges
|
10
10
|
# explicit by requiring parenthesis around complex range boundaries (anything
|
11
11
|
# that is not a literal: numerics, strings, symbols, etc.).
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
# The cop auto-corrects by wrapping the entire boundary in parentheses, which
|
22
22
|
# makes the outcome more explicit but is possible to not be the intention of the
|
23
23
|
# programmer. For this reason, this cop's auto-correct is unsafe (it will not
|
24
|
-
# change the
|
24
|
+
# change the behavior of the code, but will not necessarily match the
|
25
25
|
# intent of the program).
|
26
26
|
#
|
27
27
|
# @example
|
@@ -61,11 +61,8 @@ module RuboCop
|
|
61
61
|
#
|
62
62
|
class ErbNewArguments < Base
|
63
63
|
include RangeHelp
|
64
|
-
extend TargetRubyVersion
|
65
64
|
extend AutoCorrector
|
66
65
|
|
67
|
-
minimum_target_ruby_version 2.6
|
68
|
-
|
69
66
|
MESSAGES = [
|
70
67
|
'Passing safe_level with the 2nd argument of `ERB.new` is ' \
|
71
68
|
'deprecated. Do not use it, and specify other arguments as ' \
|
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
# This cop checks for uses of `begin...end while/until something`.
|
7
7
|
#
|
8
8
|
# @safety
|
9
|
-
# The cop is unsafe because
|
9
|
+
# The cop is unsafe because behavior can change in some cases, including
|
10
10
|
# if a local variable inside the loop body is accessed outside of it, or if the
|
11
11
|
# loop body raises a `StopIteration` exception (which `Kernel#loop` rescues).
|
12
12
|
#
|
@@ -40,12 +40,12 @@ module RuboCop
|
|
40
40
|
context_node = non_void_context(return_node)
|
41
41
|
|
42
42
|
return unless context_node&.def_type?
|
43
|
+
return unless context_node&.void_context?
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
add_offense(return_node.loc.keyword, message: format(message, method: method_name))
|
45
|
+
add_offense(
|
46
|
+
return_node.loc.keyword,
|
47
|
+
message: format(message, method: context_node.method_name)
|
48
|
+
)
|
49
49
|
end
|
50
50
|
|
51
51
|
private
|
@@ -53,18 +53,6 @@ module RuboCop
|
|
53
53
|
def non_void_context(return_node)
|
54
54
|
return_node.each_ancestor(:block, :def, :defs).first
|
55
55
|
end
|
56
|
-
|
57
|
-
def method_name(context_node)
|
58
|
-
context_node.children.first
|
59
|
-
end
|
60
|
-
|
61
|
-
def void_context_method?(method_name)
|
62
|
-
method_name == :initialize || setter_method?(method_name)
|
63
|
-
end
|
64
|
-
|
65
|
-
def setter_method?(method_name)
|
66
|
-
method_name.to_s.end_with?('=') && !AST::Node::COMPARISON_OPERATORS.include?(method_name)
|
67
|
-
end
|
68
56
|
end
|
69
57
|
end
|
70
58
|
end
|
@@ -157,6 +157,7 @@ module RuboCop
|
|
157
157
|
def omit_length(descendant)
|
158
158
|
parent = descendant.parent
|
159
159
|
return 0 if another_args?(parent)
|
160
|
+
return 0 unless parenthesized?(parent)
|
160
161
|
|
161
162
|
[
|
162
163
|
parent.loc.begin.end_pos != descendant.loc.expression.begin_pos,
|
@@ -164,6 +165,10 @@ module RuboCop
|
|
164
165
|
].count(true)
|
165
166
|
end
|
166
167
|
|
168
|
+
def parenthesized?(node)
|
169
|
+
node.call_type? && node.parenthesized?
|
170
|
+
end
|
171
|
+
|
167
172
|
def another_args?(node)
|
168
173
|
node.call_type? && node.arguments.count > 1
|
169
174
|
end
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
# @param [Array] collection an array to return consecutive duplicates for
|
30
30
|
# @return [Array] the consecutive duplicates
|
31
31
|
def consecutive_duplicates(collection)
|
32
|
-
grouped_duplicates(collection).flat_map { |items| items[1
|
32
|
+
grouped_duplicates(collection).flat_map { |items| items[1..] }
|
33
33
|
end
|
34
34
|
|
35
35
|
# Returns a hash of grouped duplicates. The key will be the first
|