rubocop 1.74.0 → 1.75.0
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 +1 -1
- data/config/default.yml +32 -6
- data/config/obsoletion.yml +3 -1
- data/lib/rubocop/cli.rb +1 -1
- data/lib/rubocop/config.rb +35 -6
- data/lib/rubocop/config_loader.rb +4 -0
- data/lib/rubocop/config_obsoletion/renamed_cop.rb +18 -3
- data/lib/rubocop/config_obsoletion.rb +46 -2
- data/lib/rubocop/config_validator.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +6 -5
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/block_end_newline.rb +1 -0
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -0
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +1 -0
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -0
- data/lib/rubocop/cop/layout/line_length.rb +5 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +1 -0
- data/lib/rubocop/cop/layout/redundant_line_break.rb +9 -5
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +4 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -0
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -0
- data/lib/rubocop/cop/lint/debugger.rb +2 -2
- data/lib/rubocop/cop/lint/raise_exception.rb +29 -10
- data/lib/rubocop/cop/lint/redundant_with_index.rb +3 -0
- data/lib/rubocop/cop/lint/redundant_with_object.rb +3 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +8 -1
- data/lib/rubocop/cop/lint/unexpected_block_arity.rb +2 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_loop.rb +5 -5
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -0
- data/lib/rubocop/cop/lint/void.rb +1 -0
- data/lib/rubocop/cop/metrics/block_length.rb +1 -0
- data/lib/rubocop/cop/metrics/method_length.rb +1 -0
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +2 -2
- data/lib/rubocop/cop/mixin/forbidden_identifiers.rb +20 -0
- data/lib/rubocop/cop/mixin/forbidden_pattern.rb +16 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -0
- data/lib/rubocop/cop/naming/method_name.rb +64 -8
- data/lib/rubocop/cop/naming/variable_name.rb +6 -19
- data/lib/rubocop/cop/registry.rb +9 -6
- data/lib/rubocop/cop/style/array_intersect.rb +39 -28
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -1
- data/lib/rubocop/cop/style/collection_methods.rb +1 -0
- data/lib/rubocop/cop/style/combinable_loops.rb +1 -0
- data/lib/rubocop/cop/style/for.rb +1 -0
- data/lib/rubocop/cop/style/guard_clause.rb +2 -1
- data/lib/rubocop/cop/style/hash_each_methods.rb +3 -2
- data/lib/rubocop/cop/style/hash_fetch_chain.rb +105 -0
- data/lib/rubocop/cop/style/if_inside_else.rb +10 -13
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -0
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +2 -2
- data/lib/rubocop/cop/style/ip_addresses.rb +2 -2
- data/lib/rubocop/cop/style/it_block_parameter.rb +100 -0
- data/lib/rubocop/cop/style/lambda.rb +1 -0
- data/lib/rubocop/cop/style/map_into_array.rb +1 -0
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -0
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -0
- data/lib/rubocop/cop/style/next.rb +44 -0
- data/lib/rubocop/cop/style/object_then.rb +1 -0
- data/lib/rubocop/cop/style/proc.rb +1 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -0
- data/lib/rubocop/cop/style/redundant_format.rb +10 -3
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -1
- data/lib/rubocop/cop/style/redundant_self.rb +1 -0
- data/lib/rubocop/cop/style/redundant_sort_by.rb +17 -1
- data/lib/rubocop/cop/style/select_by_regexp.rb +4 -1
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +3 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +41 -100
- data/lib/rubocop/cop/style/symbol_proc.rb +2 -0
- data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -0
- data/lib/rubocop/cop/variable_force/scope.rb +1 -1
- data/lib/rubocop/cop/variable_force/variable.rb +1 -6
- data/lib/rubocop/cop/variable_force.rb +1 -1
- data/lib/rubocop/lsp/runtime.rb +4 -4
- data/lib/rubocop/lsp/stdin_runner.rb +3 -1
- data/lib/rubocop/rspec/cop_helper.rb +4 -1
- data/lib/rubocop/rspec/shared_contexts.rb +20 -0
- data/lib/rubocop/rspec/support.rb +2 -0
- data/lib/rubocop/runner.rb +5 -1
- data/lib/rubocop/target_ruby.rb +1 -1
- data/lib/rubocop/version.rb +14 -7
- data/lib/rubocop.rb +4 -0
- data/lib/ruby_lsp/rubocop/runtime_adapter.rb +20 -2
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e806cf86ed67dd63a42a7aa49d9d7078fbc9adbf2445ae4ad078746755aab399
|
4
|
+
data.tar.gz: c987baa5c2b372e4e223f660ee1b703f82c07f9a31a641aa0e53e0b1fb3f85a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8182e7c9d9e1f55ea0c53dfe9c56ff157621384ee399efeea397a2cef82ec83e066c4f7868b498c7dd25cf5072223b6475daeb62fa82520539974f07fbcdbd2e
|
7
|
+
data.tar.gz: fa8b6cb67554bf5da2121ad5005f9d5dca3840cb5416711f38665ac5859f48ef3a4fb165aef554c5ce46d957dcaa315140e77b193162c59ef6f8924bee9e3516
|
data/README.md
CHANGED
@@ -52,7 +52,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
|
|
52
52
|
in your `Gemfile`:
|
53
53
|
|
54
54
|
```rb
|
55
|
-
gem 'rubocop', '~> 1.
|
55
|
+
gem 'rubocop', '~> 1.75', require: false
|
56
56
|
```
|
57
57
|
|
58
58
|
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
|
data/config/default.yml
CHANGED
@@ -146,12 +146,14 @@ AllCops:
|
|
146
146
|
# Ruby version is still unresolved, RuboCop will use the oldest officially
|
147
147
|
# supported Ruby version (currently Ruby 2.7).
|
148
148
|
TargetRubyVersion: ~
|
149
|
-
#
|
149
|
+
# RuboCop choses the parser engine automatically but you can also specify it yourself.
|
150
|
+
# These options are available:
|
151
|
+
# - `default`
|
150
152
|
# - `parser_whitequark` ... https://github.com/whitequark/parser
|
151
153
|
# - `parser_prism` ... https://github.com/ruby/prism (`Prism::Translation::Parser`)
|
152
|
-
#
|
153
|
-
#
|
154
|
-
ParserEngine:
|
154
|
+
# Not every parser engine can handle every `TargetRubyVersion`. `parser_whitequark`
|
155
|
+
# only works with versions 3.4 and below, `parser_prism` with versions 3.3 and above.
|
156
|
+
ParserEngine: default
|
155
157
|
# Determines if a notification for extension libraries should be shown when
|
156
158
|
# rubocop is run. Keys are the name of the extension, and values are an array
|
157
159
|
# of gems in the Gemfile that the extension is suggested for, if not already
|
@@ -2995,6 +2997,7 @@ Naming/MethodName:
|
|
2995
2997
|
StyleGuide: '#snake-case-symbols-methods-vars'
|
2996
2998
|
Enabled: true
|
2997
2999
|
VersionAdded: '0.50'
|
3000
|
+
VersionChanged: '1.75'
|
2998
3001
|
EnforcedStyle: snake_case
|
2999
3002
|
SupportedStyles:
|
3000
3003
|
- snake_case
|
@@ -3006,6 +3009,10 @@ Naming/MethodName:
|
|
3006
3009
|
# - '\A\s*onSelectionCleared\s*'
|
3007
3010
|
#
|
3008
3011
|
AllowedPatterns: []
|
3012
|
+
ForbiddenIdentifiers:
|
3013
|
+
- __id__
|
3014
|
+
- __send__
|
3015
|
+
ForbiddenPatterns: []
|
3009
3016
|
|
3010
3017
|
Naming/MethodParameterName:
|
3011
3018
|
Description: >-
|
@@ -3042,17 +3049,19 @@ Naming/PredicateName:
|
|
3042
3049
|
StyleGuide: '#bool-methods-qmark'
|
3043
3050
|
Enabled: true
|
3044
3051
|
VersionAdded: '0.50'
|
3045
|
-
VersionChanged: '
|
3052
|
+
VersionChanged: '1.75'
|
3046
3053
|
# Predicate name prefixes.
|
3047
3054
|
NamePrefix:
|
3048
3055
|
- is_
|
3049
3056
|
- has_
|
3050
3057
|
- have_
|
3058
|
+
- does_
|
3051
3059
|
# Predicate name prefixes that should be removed.
|
3052
3060
|
ForbiddenPrefixes:
|
3053
3061
|
- is_
|
3054
3062
|
- has_
|
3055
3063
|
- have_
|
3064
|
+
- does_
|
3056
3065
|
# Predicate names which, despite having a forbidden prefix, or no `?`,
|
3057
3066
|
# should still be accepted
|
3058
3067
|
AllowedMethods:
|
@@ -4195,6 +4204,12 @@ Style/HashExcept:
|
|
4195
4204
|
VersionAdded: '1.7'
|
4196
4205
|
VersionChanged: '1.39'
|
4197
4206
|
|
4207
|
+
Style/HashFetchChain:
|
4208
|
+
Description: 'Use `Hash#dig` instead of chained `fetch` calls.'
|
4209
|
+
Enabled: pending
|
4210
|
+
Safe: false
|
4211
|
+
VersionAdded: '1.75'
|
4212
|
+
|
4198
4213
|
Style/HashLikeCase:
|
4199
4214
|
Description: >-
|
4200
4215
|
Checks for places where `case-when` represents a simple 1:1
|
@@ -4405,6 +4420,16 @@ Style/ItAssignment:
|
|
4405
4420
|
Enabled: pending
|
4406
4421
|
VersionAdded: '1.70'
|
4407
4422
|
|
4423
|
+
Style/ItBlockParameter:
|
4424
|
+
Description: 'Checks for blocks with one argument where `it` block parameter can be used.'
|
4425
|
+
Enabled: pending
|
4426
|
+
EnforcedStyle: allow_named_parameter
|
4427
|
+
SupportedStyles:
|
4428
|
+
- allow_named_parameter
|
4429
|
+
- always
|
4430
|
+
- disallow
|
4431
|
+
VersionAdded: '1.75'
|
4432
|
+
|
4408
4433
|
Style/KeywordArgumentsMerging:
|
4409
4434
|
Description: >-
|
4410
4435
|
When passing an existing hash as keyword arguments, provide additional arguments
|
@@ -4793,7 +4818,7 @@ Style/Next:
|
|
4793
4818
|
StyleGuide: '#no-nested-conditionals'
|
4794
4819
|
Enabled: true
|
4795
4820
|
VersionAdded: '0.22'
|
4796
|
-
VersionChanged: '
|
4821
|
+
VersionChanged: '1.75'
|
4797
4822
|
# With `always` all conditions at the end of an iteration needs to be
|
4798
4823
|
# replaced by next - with `skip_modifier_ifs` the modifier if like this one
|
4799
4824
|
# are ignored: [1, 2].each { |a| return 'yes' if a == 1 }
|
@@ -4801,6 +4826,7 @@ Style/Next:
|
|
4801
4826
|
# `MinBodyLength` defines the number of lines of the a body of an `if` or `unless`
|
4802
4827
|
# needs to have to trigger this cop
|
4803
4828
|
MinBodyLength: 3
|
4829
|
+
AllowConsecutiveConditionals: false
|
4804
4830
|
SupportedStyles:
|
4805
4831
|
- skip_modifier_ifs
|
4806
4832
|
- always
|
data/config/obsoletion.yml
CHANGED
@@ -43,7 +43,9 @@ renamed:
|
|
43
43
|
Style/MethodCallParentheses: Style/MethodCallWithoutArgsParentheses
|
44
44
|
Style/MethodName: Naming/MethodName
|
45
45
|
Style/OpMethod: Naming/BinaryOperatorParameterName
|
46
|
-
Style/PredicateName:
|
46
|
+
Style/PredicateName:
|
47
|
+
new_name: Naming/PredicateName
|
48
|
+
severity: warning
|
47
49
|
Style/SingleSpaceBeforeFirstArg: Layout/SpaceBeforeFirstArg
|
48
50
|
Style/UnneededCapitalW: Style/RedundantCapitalW
|
49
51
|
Style/UnneededCondition: Style/RedundantCondition
|
data/lib/rubocop/cli.rb
CHANGED
data/lib/rubocop/config.rb
CHANGED
@@ -27,14 +27,43 @@ module RuboCop
|
|
27
27
|
config
|
28
28
|
end
|
29
29
|
|
30
|
-
# rubocop:disable Metrics/AbcSize
|
30
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
31
31
|
def initialize(hash = RuboCop::ConfigLoader.default_configuration, loaded_path = nil)
|
32
32
|
@loaded_path = loaded_path
|
33
33
|
@for_cop = Hash.new do |h, cop|
|
34
34
|
cop_name = cop.respond_to?(:cop_name) ? cop.cop_name : cop
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
|
36
|
+
if ConfigObsoletion.deprecated_cop_name?(cop)
|
37
|
+
# Since a deprecated cop will no longer have a qualified name (as the badge is no
|
38
|
+
# longer valid), and since we do not want to automatically enable the cop, we just
|
39
|
+
# set the configuration to an empty hash if it is unset.
|
40
|
+
# This is necessary to allow a renamed cop have its old configuration merged in
|
41
|
+
# before being used (which is necessary to allow it to be disabled via config).
|
42
|
+
cop_options = self[cop_name].dup || {}
|
43
|
+
else
|
44
|
+
qualified_cop_name = Cop::Registry.qualified_cop_name(cop_name, loaded_path, warn: false)
|
45
|
+
cop_options = self[qualified_cop_name].dup || {}
|
46
|
+
cop_options['Enabled'] = enable_cop?(qualified_cop_name, cop_options)
|
47
|
+
|
48
|
+
# If the cop has deprecated names (ie. it has been renamed), it is possible that
|
49
|
+
# users will still have old configuration for the cop's old name. In this case,
|
50
|
+
# if `ConfigObsoletion` is configured to warn rather than error (and therefore
|
51
|
+
# RuboCop runs), we want to respect the old configuration, so merge it in.
|
52
|
+
#
|
53
|
+
# NOTE: If there is configuration for both the cop and a deprecated names, the old
|
54
|
+
# configuration will be merged on top of the new configuration!
|
55
|
+
ConfigObsoletion.deprecated_names_for(cop).each do |deprecated_cop_name|
|
56
|
+
deprecated_config = @for_cop[deprecated_cop_name]
|
57
|
+
next if deprecated_config.empty?
|
58
|
+
|
59
|
+
warn Rainbow(<<~WARNING).yellow
|
60
|
+
Warning: Using `#{deprecated_cop_name}` configuration in #{loaded_path} for `#{cop}`.
|
61
|
+
WARNING
|
62
|
+
|
63
|
+
cop_options.merge!(@for_cop[deprecated_cop_name])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
38
67
|
h[cop] = h[cop_name] = cop_options
|
39
68
|
end
|
40
69
|
@hash = hash
|
@@ -43,7 +72,7 @@ module RuboCop
|
|
43
72
|
@badge_config_cache = {}.compare_by_identity
|
44
73
|
@clusivity_config_exists_cache = {}
|
45
74
|
end
|
46
|
-
# rubocop:enable Metrics/AbcSize
|
75
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
47
76
|
|
48
77
|
def loaded_plugins
|
49
78
|
@loaded_plugins ||= ConfigLoader.loaded_plugins
|
@@ -262,7 +291,7 @@ module RuboCop
|
|
262
291
|
end
|
263
292
|
|
264
293
|
def parser_engine
|
265
|
-
@parser_engine ||= for_all_cops.fetch('ParserEngine', :
|
294
|
+
@parser_engine ||= for_all_cops.fetch('ParserEngine', :default).to_sym
|
266
295
|
end
|
267
296
|
|
268
297
|
def target_rails_version
|
@@ -91,8 +91,12 @@ module RuboCop
|
|
91
91
|
def add_missing_namespaces(path, hash)
|
92
92
|
# Using `hash.each_key` will cause the
|
93
93
|
# `can't add a new key into hash during iteration` error
|
94
|
+
obsoletion = ConfigObsoletion.new(hash)
|
95
|
+
|
94
96
|
hash_keys = hash.keys
|
95
97
|
hash_keys.each do |key|
|
98
|
+
next if obsoletion.deprecated_cop_name?(key)
|
99
|
+
|
96
100
|
q = Cop::Registry.qualified_cop_name(key, path)
|
97
101
|
next if q == key
|
98
102
|
|
@@ -6,17 +6,28 @@ module RuboCop
|
|
6
6
|
# a cop or moving it to a new department.
|
7
7
|
# @api private
|
8
8
|
class RenamedCop < CopRule
|
9
|
-
attr_reader :new_name
|
9
|
+
attr_reader :new_name, :metadata
|
10
10
|
|
11
|
-
def initialize(config, old_name,
|
11
|
+
def initialize(config, old_name, name_or_hash)
|
12
12
|
super(config, old_name)
|
13
|
-
|
13
|
+
|
14
|
+
if name_or_hash.is_a?(Hash)
|
15
|
+
@metadata = name_or_hash
|
16
|
+
@new_name = name_or_hash['new_name']
|
17
|
+
else
|
18
|
+
@metadata = {}
|
19
|
+
@new_name = name_or_hash
|
20
|
+
end
|
14
21
|
end
|
15
22
|
|
16
23
|
def rule_message
|
17
24
|
"The `#{old_name}` cop has been #{verb} to `#{new_name}`."
|
18
25
|
end
|
19
26
|
|
27
|
+
def warning?
|
28
|
+
severity == 'warning'
|
29
|
+
end
|
30
|
+
|
20
31
|
private
|
21
32
|
|
22
33
|
def moved?
|
@@ -29,6 +40,10 @@ module RuboCop
|
|
29
40
|
def verb
|
30
41
|
moved? ? 'moved' : 'renamed'
|
31
42
|
end
|
43
|
+
|
44
|
+
def severity
|
45
|
+
metadata['severity']
|
46
|
+
end
|
32
47
|
end
|
33
48
|
end
|
34
49
|
end
|
@@ -23,9 +23,40 @@ module RuboCop
|
|
23
23
|
class << self
|
24
24
|
attr_accessor :files
|
25
25
|
|
26
|
+
def global
|
27
|
+
@global ||= new(Config.new)
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset!
|
31
|
+
@global = nil
|
32
|
+
@deprecated_names = {}
|
33
|
+
LOAD_RULES_CACHE[rules_cache_key] = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def rules_cache_key
|
37
|
+
files.hash
|
38
|
+
end
|
39
|
+
|
26
40
|
def legacy_cop_names
|
27
41
|
# Used by DepartmentName#qualified_legacy_cop_name
|
28
|
-
|
42
|
+
global.legacy_cop_names
|
43
|
+
end
|
44
|
+
|
45
|
+
def deprecated_cop_name?(name)
|
46
|
+
global.deprecated_cop_name?(name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def deprecated_names_for(cop)
|
50
|
+
@deprecated_names ||= {}
|
51
|
+
return @deprecated_names[cop] if @deprecated_names.key?(cop)
|
52
|
+
|
53
|
+
@deprecated_names[cop] = global.rules.filter_map do |rule|
|
54
|
+
next unless rule.cop_rule?
|
55
|
+
next unless rule.respond_to?(:new_name)
|
56
|
+
next unless rule.new_name == cop
|
57
|
+
|
58
|
+
rule.old_name
|
59
|
+
end
|
29
60
|
end
|
30
61
|
end
|
31
62
|
|
@@ -45,12 +76,21 @@ module RuboCop
|
|
45
76
|
raise ValidationError, messages.join("\n")
|
46
77
|
end
|
47
78
|
|
79
|
+
def legacy_cop_names
|
80
|
+
# Used by DepartmentName#qualified_legacy_cop_name
|
81
|
+
cop_rules.map(&:old_name)
|
82
|
+
end
|
83
|
+
|
84
|
+
def deprecated_cop_name?(name)
|
85
|
+
legacy_cop_names.include?(name)
|
86
|
+
end
|
87
|
+
|
48
88
|
private
|
49
89
|
|
50
90
|
# Default rules for obsoletions are in config/obsoletion.yml
|
51
91
|
# Additional rules files can be added with `RuboCop::ConfigObsoletion.files << filename`
|
52
92
|
def load_rules # rubocop:disable Metrics/AbcSize
|
53
|
-
rules = LOAD_RULES_CACHE[self.class.
|
93
|
+
rules = LOAD_RULES_CACHE[self.class.rules_cache_key] ||=
|
54
94
|
self.class.files.each_with_object({}) do |filename, hash|
|
55
95
|
hash.merge!(YAML.safe_load(File.read(filename)) || {}) do |_key, first, second|
|
56
96
|
case first
|
@@ -107,5 +147,9 @@ module RuboCop
|
|
107
147
|
rule.message
|
108
148
|
end
|
109
149
|
end
|
150
|
+
|
151
|
+
def cop_rules
|
152
|
+
rules.select(&:cop_rule?)
|
153
|
+
end
|
110
154
|
end
|
111
155
|
end
|
@@ -118,6 +118,7 @@ module RuboCop
|
|
118
118
|
invalid_cop_names.each do |name|
|
119
119
|
# There could be a custom cop with this name. If so, don't warn
|
120
120
|
next if Cop::Registry.global.contains_cop_matching?([name])
|
121
|
+
next if ConfigObsoletion.deprecated_cop_name?(name)
|
121
122
|
|
122
123
|
# Special case for inherit_mode, which is a directive that we keep in
|
123
124
|
# the configuration (even though it's not a cop), because it's easier
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
MSG = 'Replace `%<names>s` in node pattern union with `%<replacement>s`.'
|
28
28
|
RESTRICT_ON_SEND = %i[def_node_matcher def_node_search].freeze
|
29
29
|
NODE_GROUPS = {
|
30
|
-
any_block: %i[block numblock],
|
30
|
+
any_block: %i[block numblock itblock],
|
31
31
|
argument: %i[arg optarg restarg kwarg kwoptarg kwrestarg blockarg forward_arg shadowarg],
|
32
32
|
boolean: %i[true false],
|
33
33
|
call: %i[send csend],
|
@@ -38,23 +38,24 @@ module RuboCop
|
|
38
38
|
|
39
39
|
describe = find_describe_method_node(node)
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
41
|
+
should_append_config = describe && describe.last_argument.source != ':config'
|
42
|
+
additional_message = ' and specify `:config` in `describe`' if should_append_config
|
44
43
|
|
45
44
|
message = format(MSG, additional_message: additional_message)
|
46
45
|
|
47
46
|
add_offense(node, message: message) do |corrector|
|
48
47
|
corrector.remove(range_by_whole_lines(node.source_range, include_final_newline: true))
|
49
48
|
|
50
|
-
corrector.insert_after(describe.last_argument, ', :config')
|
49
|
+
corrector.insert_after(describe.last_argument, ', :config') if should_append_config
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
53
|
private
|
55
54
|
|
56
55
|
def find_describe_method_node(block_node)
|
57
|
-
block_node.ancestors.find
|
56
|
+
block_node.ancestors.find do |node|
|
57
|
+
node.block_type? && node.method?(:describe)
|
58
|
+
end&.send_node
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|
@@ -92,7 +92,7 @@ module RuboCop
|
|
92
92
|
case parent.type
|
93
93
|
when :def, :defs then base_for_method_definition(parent)
|
94
94
|
when :kwbegin then parent.loc.begin
|
95
|
-
when :block, :numblock
|
95
|
+
when :block, :numblock, :itblock
|
96
96
|
assignment_node = assignment_node(parent)
|
97
97
|
if same_line?(parent, assignment_node)
|
98
98
|
assignment_node.source_range
|
@@ -75,6 +75,7 @@ module RuboCop
|
|
75
75
|
check_for_breakable_block(node)
|
76
76
|
end
|
77
77
|
alias on_numblock on_block
|
78
|
+
alias on_itblock on_block
|
78
79
|
|
79
80
|
def on_str(node)
|
80
81
|
check_for_breakable_str(node)
|
@@ -92,6 +93,7 @@ module RuboCop
|
|
92
93
|
alias on_send on_potential_breakable_node
|
93
94
|
alias on_csend on_potential_breakable_node
|
94
95
|
alias on_def on_potential_breakable_node
|
96
|
+
alias on_defs on_potential_breakable_node
|
95
97
|
|
96
98
|
def on_new_investigation
|
97
99
|
return unless processed_source.raw_source.include?(';')
|
@@ -370,7 +372,9 @@ module RuboCop
|
|
370
372
|
|
371
373
|
def string_delimiter(node)
|
372
374
|
delimiter = node.loc.begin
|
373
|
-
|
375
|
+
if node.parent&.dstr_type? && node.parent.loc.respond_to?(:begin)
|
376
|
+
delimiter ||= node.parent.loc.begin
|
377
|
+
end
|
374
378
|
delimiter = delimiter&.source
|
375
379
|
|
376
380
|
delimiter if %w[' "].include?(delimiter)
|
@@ -6,25 +6,29 @@ module RuboCop
|
|
6
6
|
# Checks whether certain expressions, e.g. method calls, that could fit
|
7
7
|
# completely on a single line, are broken up into multiple lines unnecessarily.
|
8
8
|
#
|
9
|
-
# @example
|
9
|
+
# @example
|
10
10
|
# # bad
|
11
11
|
# foo(
|
12
12
|
# a,
|
13
13
|
# b
|
14
14
|
# )
|
15
15
|
#
|
16
|
+
# # good
|
17
|
+
# foo(a, b)
|
18
|
+
#
|
19
|
+
# # bad
|
16
20
|
# puts 'string that fits on ' \
|
17
21
|
# 'a single line'
|
18
22
|
#
|
23
|
+
# # good
|
24
|
+
# puts 'string that fits on a single line'
|
25
|
+
#
|
26
|
+
# # bad
|
19
27
|
# things
|
20
28
|
# .select { |thing| thing.cond? }
|
21
29
|
# .join('-')
|
22
30
|
#
|
23
31
|
# # good
|
24
|
-
# foo(a, b)
|
25
|
-
#
|
26
|
-
# puts 'string that fits on a single line'
|
27
|
-
#
|
28
32
|
# things.select { |thing| thing.cond? }.join('-')
|
29
33
|
#
|
30
34
|
# @example InspectBlocks: false (default)
|
@@ -96,7 +96,7 @@ module RuboCop
|
|
96
96
|
def alignment_source(node, starting_loc)
|
97
97
|
ending_loc =
|
98
98
|
case node.type
|
99
|
-
when :block, :numblock, :kwbegin
|
99
|
+
when :block, :numblock, :itblock, :kwbegin
|
100
100
|
node.loc.begin
|
101
101
|
when :def, :defs, :class, :module,
|
102
102
|
:lvasgn, :ivasgn, :cvasgn, :gvasgn, :casgn
|
@@ -260,7 +260,10 @@ module RuboCop
|
|
260
260
|
end
|
261
261
|
|
262
262
|
def hash_table_style?
|
263
|
-
|
263
|
+
return false unless align_hash_cop_config
|
264
|
+
|
265
|
+
enforced_styles = Array(align_hash_cop_config['EnforcedHashRocketStyle'])
|
266
|
+
enforced_styles.include?('table')
|
264
267
|
end
|
265
268
|
|
266
269
|
def space_around_exponent_operator?
|
@@ -73,7 +73,7 @@ module RuboCop
|
|
73
73
|
# require 'my_debugger/start'
|
74
74
|
class Debugger < Base
|
75
75
|
MSG = 'Remove debugger entry point `%<source>s`.'
|
76
|
-
BLOCK_TYPES = %i[block numblock kwbegin].freeze
|
76
|
+
BLOCK_TYPES = %i[block numblock itblock kwbegin].freeze
|
77
77
|
|
78
78
|
def on_send(node)
|
79
79
|
return if assumed_usage_context?(node)
|
@@ -120,7 +120,7 @@ module RuboCop
|
|
120
120
|
return true if assumed_argument?(node)
|
121
121
|
|
122
122
|
node.each_ancestor.none? do |ancestor|
|
123
|
-
|
123
|
+
ancestor.type?(:any_block, :kwbegin) || ancestor.lambda_or_proc?
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|