rubocop 1.34.1 → 1.36.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 +33 -0
- data/lib/rubocop/cli/command/{auto_genenerate_config.rb → auto_generate_config.rb} +0 -0
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +32 -2
- data/lib/rubocop/cop/gemspec/require_mfa.rb +1 -1
- data/lib/rubocop/cop/generator/require_file_injector.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/numblock_handler.rb +69 -0
- data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +5 -4
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/block_alignment.rb +16 -12
- data/lib/rubocop/cop/layout/block_end_newline.rb +2 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +5 -2
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +2 -0
- data/lib/rubocop/cop/layout/end_of_line.rb +4 -4
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/indentation_width.rb +5 -1
- data/lib/rubocop/cop/layout/line_length.rb +4 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -0
- data/lib/rubocop/cop/layout/redundant_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +2 -0
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +25 -9
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
- data/lib/rubocop/cop/lint/duplicate_require.rb +1 -1
- data/lib/rubocop/cop/lint/empty_block.rb +1 -1
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +31 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -9
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +4 -0
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +25 -6
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +6 -6
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +12 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +9 -3
- data/lib/rubocop/cop/lint/redundant_with_index.rb +13 -10
- data/lib/rubocop/cop/lint/redundant_with_object.rb +12 -11
- data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +15 -2
- data/lib/rubocop/cop/lint/unreachable_loop.rb +8 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +8 -6
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +2 -0
- data/lib/rubocop/cop/mixin/allowed_methods.rb +10 -5
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +13 -5
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +76 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +10 -6
- data/lib/rubocop/cop/mixin/method_complexity.rb +4 -4
- data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +2 -3
- data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +2 -2
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +77 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +2 -2
- data/lib/rubocop/cop/style/case_equality.rb +40 -10
- data/lib/rubocop/cop/style/class_methods_definitions.rb +2 -1
- data/lib/rubocop/cop/style/collection_methods.rb +2 -0
- data/lib/rubocop/cop/style/combinable_loops.rb +3 -1
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +41 -6
- data/lib/rubocop/cop/style/each_with_object.rb +39 -8
- data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
- data/lib/rubocop/cop/style/for.rb +2 -0
- data/lib/rubocop/cop/style/guard_clause.rb +27 -16
- data/lib/rubocop/cop/style/hash_each_methods.rb +3 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +17 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +8 -6
- data/lib/rubocop/cop/style/magic_comment_format.rb +307 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +4 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +3 -1
- data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +1 -1
- data/lib/rubocop/cop/style/next.rb +3 -5
- data/lib/rubocop/cop/style/nil_lambda.rb +1 -1
- data/lib/rubocop/cop/style/object_then.rb +2 -0
- data/lib/rubocop/cop/style/perl_backrefs.rb +22 -1
- data/lib/rubocop/cop/style/proc.rb +4 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +2 -0
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +4 -0
- data/lib/rubocop/cop/style/redundant_self.rb +2 -0
- data/lib/rubocop/cop/style/redundant_sort_by.rb +24 -8
- data/lib/rubocop/cop/style/safe_navigation.rb +4 -2
- data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +0 -2
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +5 -4
- data/lib/rubocop/cop/style/top_level_method_definition.rb +3 -1
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/feature_loader.rb +6 -2
- data/lib/rubocop/formatter/html_formatter.rb +2 -2
- data/lib/rubocop/runner.rb +4 -0
- data/lib/rubocop/server/cache.rb +11 -8
- data/lib/rubocop/version.rb +3 -2
- data/lib/rubocop.rb +3 -2
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bc2d4bd29fd7e81f4d7118fef9f55bcd2f086fd20ce383d85c2a1b7b26ea4e9
|
4
|
+
data.tar.gz: 9cb3cef8736b03dd0834b94fefe4415a301d78d842df184a1a1d290973376070
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abeba580bae46458f6427c3d21c6532e95ff88e7d981d196f5013fee29c8f911146f229daa8e6f92d2f28bb14790edc46373a4366f9881700df18a7f5a1352fa
|
7
|
+
data.tar.gz: 4bee5fc42db940e95cd6e3fba83680e6d7fd573a8ed3b7c65136a48d5f3b67ba8d299ecdd30a422afb95961d84c9b0452e3d1b6c1952e0edee1cea97ca704952
|
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.36', require: false
|
57
57
|
```
|
58
58
|
|
59
59
|
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
|
data/config/default.yml
CHANGED
@@ -2794,6 +2794,7 @@ Naming/MethodParameterName:
|
|
2794
2794
|
AllowNamesEndingInNumbers: true
|
2795
2795
|
# Allowed names that will not register an offense
|
2796
2796
|
AllowedNames:
|
2797
|
+
- as
|
2797
2798
|
- at
|
2798
2799
|
- by
|
2799
2800
|
- db
|
@@ -2948,6 +2949,7 @@ Style/AccessModifierDeclarations:
|
|
2948
2949
|
- inline
|
2949
2950
|
- group
|
2950
2951
|
AllowModifiersOnSymbols: true
|
2952
|
+
SafeAutoCorrect: false
|
2951
2953
|
|
2952
2954
|
Style/AccessorGrouping:
|
2953
2955
|
Description: 'Checks for grouping of accessors in `class` and `module` bodies.'
|
@@ -3186,6 +3188,15 @@ Style/CaseEquality:
|
|
3186
3188
|
# # good
|
3187
3189
|
# String === "string"
|
3188
3190
|
AllowOnConstant: false
|
3191
|
+
# If `AllowOnSelfClass` option is enabled, the cop will ignore violations when the receiver of
|
3192
|
+
# the case equality operator is `self.class`.
|
3193
|
+
#
|
3194
|
+
# # bad
|
3195
|
+
# some_class === object
|
3196
|
+
#
|
3197
|
+
# # good
|
3198
|
+
# self.class === object
|
3199
|
+
AllowOnSelfClass: false
|
3189
3200
|
|
3190
3201
|
Style/CaseLikeIf:
|
3191
3202
|
Description: 'Identifies places where `if-elsif` constructions can be replaced with `case-when`.'
|
@@ -3839,6 +3850,8 @@ Style/HashSyntax:
|
|
3839
3850
|
- never
|
3840
3851
|
# accepts both shorthand and explicit use of hash literal value.
|
3841
3852
|
- either
|
3853
|
+
# like "always", but will avoid mixing styles in a single hash
|
3854
|
+
- consistent
|
3842
3855
|
# Force hashes that have a symbol value to use hash rockets
|
3843
3856
|
UseHashRocketsWithSymbolValues: false
|
3844
3857
|
# Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style
|
@@ -4015,6 +4028,26 @@ Style/LineEndConcatenation:
|
|
4015
4028
|
VersionAdded: '0.18'
|
4016
4029
|
VersionChanged: '0.64'
|
4017
4030
|
|
4031
|
+
Style/MagicCommentFormat:
|
4032
|
+
Description: 'Use a consistent style for magic comments.'
|
4033
|
+
Enabled: pending
|
4034
|
+
VersionAdded: '1.35'
|
4035
|
+
EnforcedStyle: snake_case
|
4036
|
+
SupportedStyles:
|
4037
|
+
# `snake` will enforce the magic comment is written
|
4038
|
+
# in snake case (words separated by underscores).
|
4039
|
+
# Eg: froze_string_literal: true
|
4040
|
+
- snake_case
|
4041
|
+
# `kebab` will enforce the magic comment is written
|
4042
|
+
# in kebab case (words separated by hyphens).
|
4043
|
+
# Eg: froze-string-literal: true
|
4044
|
+
- kebab_case
|
4045
|
+
DirectiveCapitalization: lowercase
|
4046
|
+
ValueCapitalization: ~
|
4047
|
+
SupportedCapitalizations:
|
4048
|
+
- lowercase
|
4049
|
+
- uppercase
|
4050
|
+
|
4018
4051
|
Style/MapCompactWithConditionalBlock:
|
4019
4052
|
Description: 'Prefer `select` or `reject` over `map { ... }.compact`.'
|
4020
4053
|
Enabled: pending
|
File without changes
|
data/lib/rubocop/config.rb
CHANGED
@@ -242,7 +242,7 @@ module RuboCop
|
|
242
242
|
return nil unless loaded_path
|
243
243
|
|
244
244
|
base_path = base_dir_for_path_parameters
|
245
|
-
['
|
245
|
+
['Gemfile.lock', 'gems.locked'].each do |file_name|
|
246
246
|
path = find_file_upwards(file_name, base_path)
|
247
247
|
return path if path
|
248
248
|
end
|
@@ -7,6 +7,8 @@ module RuboCop
|
|
7
7
|
class << self
|
8
8
|
include RangeHelp
|
9
9
|
|
10
|
+
COMMA_REGEXP = /(?<=\))\s*,/.freeze
|
11
|
+
|
10
12
|
def correct(corrector, node)
|
11
13
|
corrector.remove(node.loc.begin)
|
12
14
|
corrector.remove(node.loc.end)
|
@@ -39,7 +41,15 @@ module RuboCop
|
|
39
41
|
def handle_orphaned_comma(corrector, node)
|
40
42
|
return unless only_closing_paren_before_comma?(node)
|
41
43
|
|
42
|
-
range =
|
44
|
+
range = extend_range_for_heredoc(node, parens_range(node))
|
45
|
+
corrector.remove(range)
|
46
|
+
|
47
|
+
add_heredoc_comma(corrector, node)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Get a range for the closing parenthesis and all whitespace to the left of it
|
51
|
+
def parens_range(node)
|
52
|
+
range_with_surrounding_space(
|
43
53
|
range: node.loc.end,
|
44
54
|
buffer: node.source_range.source_buffer,
|
45
55
|
side: :left,
|
@@ -47,8 +57,28 @@ module RuboCop
|
|
47
57
|
whitespace: true,
|
48
58
|
continuations: true
|
49
59
|
)
|
60
|
+
end
|
50
61
|
|
51
|
-
|
62
|
+
# If the node contains a heredoc, remove the comma too
|
63
|
+
# It'll be added back in the right place later
|
64
|
+
def extend_range_for_heredoc(node, range)
|
65
|
+
return range unless heredoc?(node)
|
66
|
+
|
67
|
+
comma_line = range_by_whole_lines(node.loc.end, buffer: node.source_range.source_buffer)
|
68
|
+
offset = comma_line.source.match(COMMA_REGEXP)[0]&.size || 0
|
69
|
+
|
70
|
+
range.adjust(end_pos: offset)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Add a comma back after the heredoc identifier
|
74
|
+
def add_heredoc_comma(corrector, node)
|
75
|
+
return unless heredoc?(node)
|
76
|
+
|
77
|
+
corrector.insert_after(node.child_nodes.last.loc.expression, ',')
|
78
|
+
end
|
79
|
+
|
80
|
+
def heredoc?(node)
|
81
|
+
node.child_nodes.last.loc.is_a?(Parser::Source::Map::Heredoc)
|
52
82
|
end
|
53
83
|
end
|
54
84
|
end
|
@@ -84,7 +84,7 @@ module RuboCop
|
|
84
84
|
(str "true")
|
85
85
|
PATTERN
|
86
86
|
|
87
|
-
def on_block(node) # rubocop:disable Metrics/MethodLength
|
87
|
+
def on_block(node) # rubocop:disable Metrics/MethodLength, InternalAffairs/NumblockHandler
|
88
88
|
gem_specification(node) do |block_var|
|
89
89
|
metadata_value = metadata(node)
|
90
90
|
mfa_value = mfa_value(metadata_value)
|
@@ -55,8 +55,8 @@ module RuboCop
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
def require_path_fragments(
|
59
|
-
path =
|
58
|
+
def require_path_fragments(require_directive)
|
59
|
+
path = require_directive.match(REQUIRE_PATH)
|
60
60
|
|
61
61
|
path ? path.captures.first.split('/') : []
|
62
62
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Checks for missing `numblock handlers. The blocks with numbered
|
7
|
+
# arguments introduced in Ruby 2.7 are parsed with a node type of
|
8
|
+
# `numblock` instead of block. Cops that define `block` handlers
|
9
|
+
# need to define `numblock` handlers or disable this cope for them.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# class BlockRelatedCop < Base
|
15
|
+
# def on_block(node)
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# class BlockRelatedCop < Base
|
21
|
+
# def on_block(node)
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# alias on_numblock on_block
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# class BlockRelatedCop < Base
|
28
|
+
# def on_block(node)
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# alias_method :on_numblock, :on_block
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# class BlockRelatedCop < Base
|
35
|
+
# def on_block(node)
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# def on_numblock(node)
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
class NumblockHandler < Base
|
42
|
+
MSG = 'Define on_numblock to handle blocks with numbered arguments.'
|
43
|
+
|
44
|
+
def on_def(node)
|
45
|
+
return unless block_handler?(node)
|
46
|
+
return unless node.parent
|
47
|
+
|
48
|
+
add_offense(node) unless numblock_handler?(node.parent)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
# @!method block_handler?(node)
|
54
|
+
def_node_matcher :block_handler?, <<~PATTERN
|
55
|
+
(def :on_block (args (arg :node)) ...)
|
56
|
+
PATTERN
|
57
|
+
|
58
|
+
# @!method numblock_handler?(node)
|
59
|
+
def_node_matcher :numblock_handler?, <<~PATTERN
|
60
|
+
{
|
61
|
+
`(def :on_numblock (args (arg :node)) ...)
|
62
|
+
`(alias (sym :on_numblock) (sym :on_block))
|
63
|
+
`(send nil? :alias_method (sym :on_numblock) (sym :on_block))
|
64
|
+
}
|
65
|
+
PATTERN
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -29,20 +29,21 @@ module RuboCop
|
|
29
29
|
extend AutoCorrector
|
30
30
|
|
31
31
|
MSG = 'Use `%<preferred>s`.'
|
32
|
-
RESTRICT_ON_SEND = %i[==].freeze
|
32
|
+
RESTRICT_ON_SEND = %i[== !=].freeze
|
33
33
|
|
34
34
|
# @!method single_line_comparison(node)
|
35
35
|
def_node_matcher :single_line_comparison, <<~PATTERN
|
36
36
|
{
|
37
|
-
(send (send $_receiver {:line :first_line}) :== (send _receiver :last_line))
|
38
|
-
(send (send $_receiver :last_line) :== (send _receiver {:line :first_line}))
|
37
|
+
(send (send $_receiver {:line :first_line}) {:== :!=} (send _receiver :last_line))
|
38
|
+
(send (send $_receiver :last_line) {:== :!=} (send _receiver {:line :first_line}))
|
39
39
|
}
|
40
40
|
PATTERN
|
41
41
|
|
42
42
|
def on_send(node)
|
43
43
|
return unless (receiver = single_line_comparison(node))
|
44
44
|
|
45
|
-
|
45
|
+
bang = node.method?(:!=) ? '!' : ''
|
46
|
+
preferred = "#{bang}#{extract_receiver(receiver)}.single_line?"
|
46
47
|
|
47
48
|
add_offense(node, message: format(MSG, preferred: preferred)) do |corrector|
|
48
49
|
corrector.replace(node, preferred)
|
@@ -10,6 +10,7 @@ require_relative 'internal_affairs/method_name_equal'
|
|
10
10
|
require_relative 'internal_affairs/node_destructuring'
|
11
11
|
require_relative 'internal_affairs/node_matcher_directive'
|
12
12
|
require_relative 'internal_affairs/node_type_predicate'
|
13
|
+
require_relative 'internal_affairs/numblock_handler'
|
13
14
|
require_relative 'internal_affairs/offense_location_keyword'
|
14
15
|
require_relative 'internal_affairs/redundant_context_config_parameter'
|
15
16
|
require_relative 'internal_affairs/redundant_described_class_as_subject'
|
@@ -22,23 +22,24 @@ module RuboCop
|
|
22
22
|
# # bad
|
23
23
|
#
|
24
24
|
# foo.bar
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
25
|
+
# .each do
|
26
|
+
# baz
|
27
|
+
# end
|
28
28
|
#
|
29
29
|
# # good
|
30
30
|
#
|
31
|
-
#
|
32
|
-
#
|
31
|
+
# foo.bar
|
32
|
+
# .each do
|
33
|
+
# baz
|
33
34
|
# end
|
34
35
|
#
|
35
36
|
# @example EnforcedStyleAlignWith: start_of_block
|
36
37
|
# # bad
|
37
38
|
#
|
38
39
|
# foo.bar
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
40
|
+
# .each do
|
41
|
+
# baz
|
42
|
+
# end
|
42
43
|
#
|
43
44
|
# # good
|
44
45
|
#
|
@@ -51,16 +52,17 @@ module RuboCop
|
|
51
52
|
# # bad
|
52
53
|
#
|
53
54
|
# foo.bar
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
55
|
+
# .each do
|
56
|
+
# baz
|
57
|
+
# end
|
57
58
|
#
|
58
59
|
# # good
|
59
60
|
#
|
60
61
|
# foo.bar
|
61
62
|
# .each do
|
62
|
-
#
|
63
|
+
# baz
|
63
64
|
# end
|
65
|
+
#
|
64
66
|
class BlockAlignment < Base
|
65
67
|
include ConfigurableEnforcedStyle
|
66
68
|
include RangeHelp
|
@@ -82,6 +84,8 @@ module RuboCop
|
|
82
84
|
check_block_alignment(start_for_block_node(node), node)
|
83
85
|
end
|
84
86
|
|
87
|
+
alias on_numblock on_block
|
88
|
+
|
85
89
|
def style_parameter_name
|
86
90
|
'EnforcedStyleAlignWith'
|
87
91
|
end
|
@@ -80,8 +80,11 @@ module RuboCop
|
|
80
80
|
@block_line = node.source_range.first_line
|
81
81
|
end
|
82
82
|
|
83
|
-
|
84
|
-
|
83
|
+
alias on_numblock on_block
|
84
|
+
|
85
|
+
def on_send(node) # rubocop:disable Metrics/CyclomaticComplexity
|
86
|
+
return unless node.bare_access_modifier? &&
|
87
|
+
!(node.parent&.block_type? || node.parent&.numblock_type?)
|
85
88
|
return if expected_empty_lines?(node)
|
86
89
|
|
87
90
|
message = message(node)
|
@@ -22,20 +22,20 @@ module RuboCop
|
|
22
22
|
# # all platforms.
|
23
23
|
#
|
24
24
|
# # bad
|
25
|
-
# puts 'Hello' # Return character is CR+LF on all
|
25
|
+
# puts 'Hello' # Return character is CR+LF on all platforms.
|
26
26
|
#
|
27
27
|
# # good
|
28
|
-
# puts 'Hello' # Return character is LF on all
|
28
|
+
# puts 'Hello' # Return character is LF on all platforms.
|
29
29
|
#
|
30
30
|
# @example EnforcedStyle: crlf
|
31
31
|
# # The `crlf` style means that CR+LF (Carriage Return + Line Feed) is
|
32
32
|
# # enforced on all platforms.
|
33
33
|
#
|
34
34
|
# # bad
|
35
|
-
# puts 'Hello' # Return character is LF on all
|
35
|
+
# puts 'Hello' # Return character is LF on all platforms.
|
36
36
|
#
|
37
37
|
# # good
|
38
|
-
# puts 'Hello' # Return character is CR+LF on all
|
38
|
+
# puts 'Hello' # Return character is CR+LF on all platforms.
|
39
39
|
#
|
40
40
|
class EndOfLine < Base
|
41
41
|
include ConfigurableEnforcedStyle
|
@@ -143,7 +143,7 @@ module RuboCop
|
|
143
143
|
case indent_base_type
|
144
144
|
when :left_brace_or_bracket
|
145
145
|
'the position of the opening bracket'
|
146
|
-
when :
|
146
|
+
when :first_column_after_left_parenthesis
|
147
147
|
'the first position after the preceding left parenthesis'
|
148
148
|
when :parent_hash_key
|
149
149
|
'the parent hash key'
|
@@ -164,7 +164,7 @@ module RuboCop
|
|
164
164
|
case indent_base_type
|
165
165
|
when :left_brace_or_bracket
|
166
166
|
'Indent the right bracket the same as the left bracket.'
|
167
|
-
when :
|
167
|
+
when :first_column_after_left_parenthesis
|
168
168
|
'Indent the right bracket the same as the first position ' \
|
169
169
|
'after the preceding left parenthesis.'
|
170
170
|
when :parent_hash_key
|
@@ -192,7 +192,7 @@ module RuboCop
|
|
192
192
|
case indent_base_type
|
193
193
|
when :left_brace_or_bracket
|
194
194
|
'the position of the opening brace'
|
195
|
-
when :
|
195
|
+
when :first_column_after_left_parenthesis
|
196
196
|
'the first position after the preceding left parenthesis'
|
197
197
|
when :parent_hash_key
|
198
198
|
'the parent hash key'
|
@@ -213,7 +213,7 @@ module RuboCop
|
|
213
213
|
case indent_base_type
|
214
214
|
when :left_brace_or_bracket
|
215
215
|
'Indent the right brace the same as the left brace.'
|
216
|
-
when :
|
216
|
+
when :first_column_after_left_parenthesis
|
217
217
|
'Indent the right brace the same as the first position ' \
|
218
218
|
'after the preceding left parenthesis.'
|
219
219
|
when :parent_hash_key
|
@@ -90,6 +90,8 @@ module RuboCop
|
|
90
90
|
check_members(end_loc, [node.body])
|
91
91
|
end
|
92
92
|
|
93
|
+
alias on_numblock on_block
|
94
|
+
|
93
95
|
def on_class(node)
|
94
96
|
base = node.loc.keyword
|
95
97
|
return if same_line?(base, node.body)
|
@@ -146,7 +148,9 @@ module RuboCop
|
|
146
148
|
check_indentation(in_pattern_node.loc.keyword, in_pattern_node.body)
|
147
149
|
end
|
148
150
|
|
149
|
-
|
151
|
+
else_branch = case_match.else_branch&.empty_else_type? ? nil : case_match.else_branch
|
152
|
+
|
153
|
+
check_indentation(case_match.in_pattern_branches.last.loc.keyword, else_branch)
|
150
154
|
end
|
151
155
|
|
152
156
|
def on_if(node, base = node)
|
@@ -22,6 +22,7 @@ module RuboCop
|
|
22
22
|
# (Many of these are enabled by default.)
|
23
23
|
#
|
24
24
|
# * ArgumentAlignment
|
25
|
+
# * ArrayAlignment
|
25
26
|
# * BlockAlignment
|
26
27
|
# * BlockDelimiters
|
27
28
|
# * BlockEndNewline
|
@@ -74,6 +75,8 @@ module RuboCop
|
|
74
75
|
check_for_breakable_block(node)
|
75
76
|
end
|
76
77
|
|
78
|
+
alias on_numblock on_block
|
79
|
+
|
77
80
|
def on_potential_breakable_node(node)
|
78
81
|
check_for_breakable_node(node)
|
79
82
|
end
|
@@ -131,7 +134,7 @@ module RuboCop
|
|
131
134
|
if block_node.arguments? && !block_node.lambda?
|
132
135
|
block_node.arguments.loc.end
|
133
136
|
else
|
134
|
-
block_node.loc.begin
|
137
|
+
block_node.braces? ? block_node.loc.begin : block_node.loc.begin.adjust(begin_pos: 1)
|
135
138
|
end
|
136
139
|
end
|
137
140
|
|
@@ -101,7 +101,7 @@ module RuboCop
|
|
101
101
|
!comment_within?(node) &&
|
102
102
|
node.each_descendant(:if, :case, :kwbegin, :def).none? &&
|
103
103
|
node.each_descendant(:dstr, :str).none?(&:heredoc?) &&
|
104
|
-
node.each_descendant(:begin).none? { |b| b.
|
104
|
+
node.each_descendant(:begin).none? { |b| !b.single_line? }
|
105
105
|
end
|
106
106
|
|
107
107
|
def convertible_block?(node)
|
@@ -131,7 +131,7 @@ module RuboCop
|
|
131
131
|
args_delimiter = node.arguments.loc.begin if node.block_type? # Can be ( | or nil.
|
132
132
|
|
133
133
|
check_left_brace(inner, node.loc.begin, args_delimiter)
|
134
|
-
check_right_brace(inner, node.loc.begin, node.loc.end, node.single_line?)
|
134
|
+
check_right_brace(node, inner, node.loc.begin, node.loc.end, node.single_line?)
|
135
135
|
end
|
136
136
|
|
137
137
|
def check_left_brace(inner, left_brace, args_delimiter)
|
@@ -142,14 +142,15 @@ module RuboCop
|
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
|
-
def check_right_brace(inner, left_brace, right_brace, single_line)
|
145
|
+
def check_right_brace(node, inner, left_brace, right_brace, single_line)
|
146
146
|
if single_line && /\S$/.match?(inner)
|
147
147
|
no_space(right_brace.begin_pos, right_brace.end_pos, 'Space missing inside }.')
|
148
148
|
else
|
149
|
+
column = node.loc.expression.column
|
149
150
|
return if multiline_block?(left_brace, right_brace) &&
|
150
|
-
aligned_braces?(
|
151
|
+
aligned_braces?(inner, right_brace, column)
|
151
152
|
|
152
|
-
space_inside_right_brace(right_brace)
|
153
|
+
space_inside_right_brace(inner, right_brace, column)
|
153
154
|
end
|
154
155
|
end
|
155
156
|
|
@@ -157,8 +158,12 @@ module RuboCop
|
|
157
158
|
left_brace.first_line != right_brace.first_line
|
158
159
|
end
|
159
160
|
|
160
|
-
def aligned_braces?(
|
161
|
-
|
161
|
+
def aligned_braces?(inner, right_brace, column)
|
162
|
+
column == right_brace.column || column == inner_last_space_count(inner)
|
163
|
+
end
|
164
|
+
|
165
|
+
def inner_last_space_count(inner)
|
166
|
+
inner.split("\n").last.count(' ')
|
162
167
|
end
|
163
168
|
|
164
169
|
def no_space_inside_left_brace(left_brace, args_delimiter)
|
@@ -197,10 +202,21 @@ module RuboCop
|
|
197
202
|
args_delimiter&.is?('|')
|
198
203
|
end
|
199
204
|
|
200
|
-
def space_inside_right_brace(right_brace)
|
205
|
+
def space_inside_right_brace(inner, right_brace, column)
|
201
206
|
brace_with_space = range_with_surrounding_space(right_brace, side: :left)
|
202
|
-
|
203
|
-
|
207
|
+
begin_pos = brace_with_space.begin_pos
|
208
|
+
end_pos = brace_with_space.end_pos - 1
|
209
|
+
|
210
|
+
if brace_with_space.source.match?(/\R/)
|
211
|
+
begin_pos = end_pos - (right_brace.column - column)
|
212
|
+
end
|
213
|
+
|
214
|
+
if inner.end_with?(']')
|
215
|
+
end_pos -= 1
|
216
|
+
begin_pos = end_pos - (inner_last_space_count(inner) - column)
|
217
|
+
end
|
218
|
+
|
219
|
+
space(begin_pos, end_pos, 'Space inside } detected.')
|
204
220
|
end
|
205
221
|
|
206
222
|
def no_space(begin_pos, end_pos, msg)
|
@@ -81,7 +81,7 @@ module RuboCop
|
|
81
81
|
def allowed_method_pattern?(node)
|
82
82
|
node.assignment? || node.operator_method? || node.method?(:[]) ||
|
83
83
|
allowed_method?(node.last_argument.method_name) ||
|
84
|
-
matches_allowed_pattern?(node.last_argument.
|
84
|
+
matches_allowed_pattern?(node.last_argument.send_node.source)
|
85
85
|
end
|
86
86
|
|
87
87
|
def message(send_node)
|
@@ -66,7 +66,7 @@ module RuboCop
|
|
66
66
|
private
|
67
67
|
|
68
68
|
def delimiter
|
69
|
-
|
69
|
+
CLASS_METHOD_DELIMITER
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -89,7 +89,7 @@ module RuboCop
|
|
89
89
|
private
|
90
90
|
|
91
91
|
def delimiter
|
92
|
-
instance_method? ?
|
92
|
+
instance_method? ? INSTANCE_METHOD_DELIMITER : CLASS_METHOD_DELIMITER
|
93
93
|
end
|
94
94
|
|
95
95
|
def instance_method?
|
@@ -126,8 +126,8 @@ module RuboCop
|
|
126
126
|
|
127
127
|
RESTRICT_ON_SEND = DEPRECATED_METHODS_OBJECT.keys.map(&:method).freeze
|
128
128
|
|
129
|
-
|
130
|
-
|
129
|
+
CLASS_METHOD_DELIMITER = '.'
|
130
|
+
INSTANCE_METHOD_DELIMITER = '#'
|
131
131
|
|
132
132
|
def on_send(node)
|
133
133
|
check(node) do |deprecated|
|