rubocop 0.79.0 → 0.80.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +3 -3
- data/config/default.yml +33 -19
- data/lib/rubocop.rb +5 -1
- data/lib/rubocop/ast/node.rb +0 -12
- data/lib/rubocop/ast/node/regexp_node.rb +2 -4
- data/lib/rubocop/ast/traversal.rb +9 -0
- data/lib/rubocop/comment_config.rb +6 -1
- data/lib/rubocop/config_obsoletion.rb +2 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +33 -2
- data/lib/rubocop/cop/layout/line_length.rb +30 -1
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +0 -4
- data/lib/rubocop/cop/layout/space_around_operators.rb +18 -0
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +8 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -9
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +12 -7
- data/lib/rubocop/cop/lint/useless_setter_call.rb +4 -0
- data/lib/rubocop/cop/migration/department_name.rb +14 -1
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +4 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +6 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +172 -0
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -9
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +60 -1
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +89 -11
- data/lib/rubocop/cop/style/hash_each_methods.rb +87 -0
- data/lib/rubocop/cop/style/hash_transform_keys.rb +79 -0
- data/lib/rubocop/cop/style/hash_transform_values.rb +79 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +5 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +5 -4
- data/lib/rubocop/cop/style/or_assignment.rb +3 -2
- data/lib/rubocop/cop/style/symbol_array.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +0 -22
- data/lib/rubocop/cop/variable_force.rb +4 -1
- data/lib/rubocop/formatter/formatter_set.rb +1 -0
- data/lib/rubocop/formatter/junit_formatter.rb +63 -0
- data/lib/rubocop/node_pattern.rb +96 -10
- data/lib/rubocop/version.rb +1 -1
- metadata +21 -3
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -209
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7143484124cd6cb7ebff12de736d4ed5a17b5189d26ab6da3f8072cf9b3d6f7e
|
4
|
+
data.tar.gz: acd2182467726955151e8dc249833ed1fffacae4dc988037ec5fe73e1d5bb0c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae462c69bb5933c60f6254c4778fcddf4c778776b1d4c64247091bf36837c6899636d0d79a433c99aa5c64d1c4cccfbb9d1d8531a2b3a8418558899f6be61481
|
7
|
+
data.tar.gz: 844dd51ef4fef218ab42a742dbd7717b1a47c18b4cee630ba3da77279832292417a8e4c07486b59f821bc7d28ace0cdfaa917f574b1a35fa52bca7fc17da822f
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -41,7 +41,7 @@ automatically fix some of the problems for you.
|
|
41
41
|
$ gem install rubocop
|
42
42
|
```
|
43
43
|
|
44
|
-
If you'd rather install RuboCop using `bundler`,
|
44
|
+
If you'd rather install RuboCop using `bundler`, add a line for it in your `Gemfile` (but set the `require` option to `false`, as it is a standalone tool):
|
45
45
|
|
46
46
|
```rb
|
47
47
|
gem 'rubocop', require: false
|
@@ -53,7 +53,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
|
|
53
53
|
might want to use a conservative version lock in your `Gemfile`:
|
54
54
|
|
55
55
|
```rb
|
56
|
-
gem 'rubocop', '~> 0.
|
56
|
+
gem 'rubocop', '~> 0.80.0', require: false
|
57
57
|
```
|
58
58
|
|
59
59
|
## Quickstart
|
@@ -213,5 +213,5 @@ RuboCop's changelog is available [here](CHANGELOG.md).
|
|
213
213
|
|
214
214
|
## Copyright
|
215
215
|
|
216
|
-
Copyright (c) 2012-
|
216
|
+
Copyright (c) 2012-2020 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for
|
217
217
|
further details.
|
data/config/default.yml
CHANGED
@@ -54,6 +54,7 @@ AllCops:
|
|
54
54
|
- '**/Puppetfile'
|
55
55
|
- '**/Rakefile'
|
56
56
|
- '**/Snapfile'
|
57
|
+
- '**/Steepfile'
|
57
58
|
- '**/Thorfile'
|
58
59
|
- '**/Vagabondfile'
|
59
60
|
- '**/Vagrantfile'
|
@@ -794,6 +795,7 @@ Layout/LeadingCommentSpace:
|
|
794
795
|
VersionAdded: '0.49'
|
795
796
|
VersionChanged: '0.73'
|
796
797
|
AllowDoxygenCommentStyle: false
|
798
|
+
AllowGemfileRubyComment: false
|
797
799
|
|
798
800
|
Layout/LeadingEmptyLines:
|
799
801
|
Description: Check for unnecessary blank lines at the beginning of a file.
|
@@ -1782,6 +1784,8 @@ Lint/UselessSetterCall:
|
|
1782
1784
|
Description: 'Checks for useless setter call to a local variable.'
|
1783
1785
|
Enabled: true
|
1784
1786
|
VersionAdded: '0.13'
|
1787
|
+
VersionChanged: '0.80'
|
1788
|
+
Safe: false
|
1785
1789
|
|
1786
1790
|
Lint/Void:
|
1787
1791
|
Description: 'Possible use of operator/literal/variable in void context.'
|
@@ -1883,7 +1887,7 @@ Migration/DepartmentName:
|
|
1883
1887
|
Description: >-
|
1884
1888
|
Check that cop names in rubocop:disable (etc) comments are
|
1885
1889
|
given with department name.
|
1886
|
-
Enabled:
|
1890
|
+
Enabled: true
|
1887
1891
|
|
1888
1892
|
#################### Naming ##############################
|
1889
1893
|
|
@@ -2065,6 +2069,7 @@ Naming/MethodParameterName:
|
|
2065
2069
|
- ip
|
2066
2070
|
- db
|
2067
2071
|
- os
|
2072
|
+
- pp
|
2068
2073
|
# Forbidden names that will register an offense
|
2069
2074
|
ForbiddenNames: []
|
2070
2075
|
|
@@ -2355,24 +2360,12 @@ Style/BlockDelimiters:
|
|
2355
2360
|
# # also good
|
2356
2361
|
# collection.each do |element| puts element end
|
2357
2362
|
AllowBracesOnProceduralOneLiners: false
|
2358
|
-
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2362
|
-
|
2363
|
-
|
2364
|
-
EnforcedStyle: no_braces
|
2365
|
-
SupportedStyles:
|
2366
|
-
# The `braces` style enforces braces around all method parameters that are
|
2367
|
-
# hashes.
|
2368
|
-
- braces
|
2369
|
-
# The `no_braces` style checks that the last parameter doesn't have braces
|
2370
|
-
# around it.
|
2371
|
-
- no_braces
|
2372
|
-
# The `context_dependent` style checks that the last parameter doesn't have
|
2373
|
-
# braces around it, but requires braces if the second to last parameter is
|
2374
|
-
# also a hash literal.
|
2375
|
-
- context_dependent
|
2363
|
+
# The BracesRequiredMethods overrides all other configurations except
|
2364
|
+
# IgnoredMethods. It can be used to enforce that all blocks for specific
|
2365
|
+
# methods use braces. For example, you can use this to enforce Sorbet
|
2366
|
+
# signatures use braces even when the rest of your codebase enforces
|
2367
|
+
# the `line_count_based` style.
|
2368
|
+
BracesRequiredMethods: []
|
2376
2369
|
|
2377
2370
|
Style/CaseEquality:
|
2378
2371
|
Description: 'Avoid explicit use of the case equality operator(===).'
|
@@ -2766,6 +2759,10 @@ Style/FrozenStringLiteralComment:
|
|
2766
2759
|
# string literal. If you run code against multiple versions of Ruby, it is
|
2767
2760
|
# possible that this will create errors in Ruby 2.3.0+.
|
2768
2761
|
- always
|
2762
|
+
# `always_true` will add the frozen string literal comment to a file,
|
2763
|
+
# similarly to the `always` style, but will also change any disabled
|
2764
|
+
# comments (e.g. `# frozen_string_literal: false`) to be enabled.
|
2765
|
+
- always_true
|
2769
2766
|
# `never` will enforce that the frozen string literal comment does not
|
2770
2767
|
# exist in a file.
|
2771
2768
|
- never
|
@@ -2790,6 +2787,13 @@ Style/GuardClause:
|
|
2790
2787
|
# needs to have to trigger this cop
|
2791
2788
|
MinBodyLength: 1
|
2792
2789
|
|
2790
|
+
Style/HashEachMethods:
|
2791
|
+
Description: 'Use Hash#each_key and Hash#each_value.'
|
2792
|
+
StyleGuide: '#hash-each'
|
2793
|
+
Enabled: pending
|
2794
|
+
VersionAdded: '0.80'
|
2795
|
+
Safe: false
|
2796
|
+
|
2793
2797
|
Style/HashSyntax:
|
2794
2798
|
Description: >-
|
2795
2799
|
Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax
|
@@ -2813,6 +2817,16 @@ Style/HashSyntax:
|
|
2813
2817
|
# Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style
|
2814
2818
|
PreferHashRocketsForNonAlnumEndingSymbols: false
|
2815
2819
|
|
2820
|
+
Style/HashTransformKeys:
|
2821
|
+
Description: 'Prefer `transform_keys` over `each_with_object` and `map`.'
|
2822
|
+
Enabled: 'pending'
|
2823
|
+
Safe: false
|
2824
|
+
|
2825
|
+
Style/HashTransformValues:
|
2826
|
+
Description: 'Prefer `transform_values` over `each_with_object` and `map`.'
|
2827
|
+
Enabled: 'pending'
|
2828
|
+
Safe: false
|
2829
|
+
|
2816
2830
|
Style/IdenticalConditionalBranches:
|
2817
2831
|
Description: >-
|
2818
2832
|
Checks that conditional statements do not have an identical
|
data/lib/rubocop.rb
CHANGED
@@ -120,6 +120,7 @@ require_relative 'rubocop/cop/mixin/enforce_superclass'
|
|
120
120
|
require_relative 'rubocop/cop/mixin/first_element_line_break'
|
121
121
|
require_relative 'rubocop/cop/mixin/frozen_string_literal'
|
122
122
|
require_relative 'rubocop/cop/mixin/hash_alignment_styles'
|
123
|
+
require_relative 'rubocop/cop/mixin/hash_transform_method'
|
123
124
|
require_relative 'rubocop/cop/mixin/ignored_pattern'
|
124
125
|
require_relative 'rubocop/cop/mixin/ignored_methods'
|
125
126
|
require_relative 'rubocop/cop/mixin/integer_node'
|
@@ -402,7 +403,6 @@ require_relative 'rubocop/cop/style/bare_percent_literals'
|
|
402
403
|
require_relative 'rubocop/cop/style/begin_block'
|
403
404
|
require_relative 'rubocop/cop/style/block_comments'
|
404
405
|
require_relative 'rubocop/cop/style/block_delimiters'
|
405
|
-
require_relative 'rubocop/cop/style/braces_around_hash_parameters'
|
406
406
|
require_relative 'rubocop/cop/style/case_equality'
|
407
407
|
require_relative 'rubocop/cop/style/character_literal'
|
408
408
|
require_relative 'rubocop/cop/style/class_and_module_children'
|
@@ -445,7 +445,10 @@ require_relative 'rubocop/cop/style/format_string_token'
|
|
445
445
|
require_relative 'rubocop/cop/style/frozen_string_literal_comment'
|
446
446
|
require_relative 'rubocop/cop/style/global_vars'
|
447
447
|
require_relative 'rubocop/cop/style/guard_clause'
|
448
|
+
require_relative 'rubocop/cop/style/hash_each_methods'
|
448
449
|
require_relative 'rubocop/cop/style/hash_syntax'
|
450
|
+
require_relative 'rubocop/cop/style/hash_transform_keys'
|
451
|
+
require_relative 'rubocop/cop/style/hash_transform_values'
|
449
452
|
require_relative 'rubocop/cop/style/identical_conditional_branches'
|
450
453
|
require_relative 'rubocop/cop/style/if_inside_else'
|
451
454
|
require_relative 'rubocop/cop/style/if_unless_modifier'
|
@@ -585,6 +588,7 @@ require_relative 'rubocop/formatter/file_list_formatter'
|
|
585
588
|
require_relative 'rubocop/formatter/fuubar_style_formatter'
|
586
589
|
require_relative 'rubocop/formatter/html_formatter'
|
587
590
|
require_relative 'rubocop/formatter/json_formatter'
|
591
|
+
require_relative 'rubocop/formatter/junit_formatter'
|
588
592
|
require_relative 'rubocop/formatter/offense_count_formatter'
|
589
593
|
require_relative 'rubocop/formatter/progress_formatter'
|
590
594
|
require_relative 'rubocop/formatter/quiet_formatter'
|
data/lib/rubocop/ast/node.rb
CHANGED
@@ -141,9 +141,6 @@ module RuboCop
|
|
141
141
|
# Yield only nodes matching any of the types.
|
142
142
|
# @param [Symbol] type_a a node type
|
143
143
|
# @param [Symbol] type_b a node type
|
144
|
-
# @overload each_ancestor(types)
|
145
|
-
# Yield only nodes matching any of types in the array.
|
146
|
-
# @param [Array<Symbol>] types an array containing node types
|
147
144
|
# @yieldparam [Node] node each ancestor node
|
148
145
|
# @return [self] if a block is given
|
149
146
|
# @return [Enumerator] if no block is given
|
@@ -178,9 +175,6 @@ module RuboCop
|
|
178
175
|
# Yield only nodes matching any of the types.
|
179
176
|
# @param [Symbol] type_a a node type
|
180
177
|
# @param [Symbol] type_b a node type
|
181
|
-
# @overload each_child_node(types)
|
182
|
-
# Yield only nodes matching any of types in the array.
|
183
|
-
# @param [Array<Symbol>] types an array containing node types
|
184
178
|
# @yieldparam [Node] node each child node
|
185
179
|
# @return [self] if a block is given
|
186
180
|
# @return [Enumerator] if no block is given
|
@@ -216,9 +210,6 @@ module RuboCop
|
|
216
210
|
# Yield only nodes matching any of the types.
|
217
211
|
# @param [Symbol] type_a a node type
|
218
212
|
# @param [Symbol] type_b a node type
|
219
|
-
# @overload each_descendant(types)
|
220
|
-
# Yield only nodes matching any of types in the array.
|
221
|
-
# @param [Array<Symbol>] types an array containing node types
|
222
213
|
# @yieldparam [Node] node each descendant node
|
223
214
|
# @return [self] if a block is given
|
224
215
|
# @return [Enumerator] if no block is given
|
@@ -254,9 +245,6 @@ module RuboCop
|
|
254
245
|
# Yield only nodes matching any of the types.
|
255
246
|
# @param [Symbol] type_a a node type
|
256
247
|
# @param [Symbol] type_b a node type
|
257
|
-
# @overload each_node(types)
|
258
|
-
# Yield only nodes matching any of types in the array.
|
259
|
-
# @param [Array<Symbol>] types an array containing node types
|
260
248
|
# @yieldparam [Node] node each node
|
261
249
|
# @return [self] if a block is given
|
262
250
|
# @return [Enumerator] if no block is given
|
@@ -21,14 +21,12 @@ module RuboCop
|
|
21
21
|
|
22
22
|
# @return [RuboCop::AST::Node] a regopt node
|
23
23
|
def regopt
|
24
|
-
|
25
|
-
first.regopt_type? ? first : second
|
24
|
+
children.last
|
26
25
|
end
|
27
26
|
|
28
27
|
# @return [String] a string of regexp content
|
29
28
|
def content
|
30
|
-
|
31
|
-
str.str_content || ''
|
29
|
+
children.select(&:str_type?).map(&:str_content).join
|
32
30
|
end
|
33
31
|
end
|
34
32
|
end
|
@@ -185,6 +185,15 @@ module RuboCop
|
|
185
185
|
alias on_when on_case
|
186
186
|
alias on_irange on_case
|
187
187
|
alias on_erange on_case
|
188
|
+
|
189
|
+
def on_numblock(node)
|
190
|
+
children = node.children
|
191
|
+
child = children[0]
|
192
|
+
send(:"on_#{child.type}", child)
|
193
|
+
return unless (child = children[2])
|
194
|
+
|
195
|
+
send(:"on_#{child.type}", child)
|
196
|
+
end
|
188
197
|
end
|
189
198
|
end
|
190
199
|
end
|
@@ -113,7 +113,8 @@ module RuboCop
|
|
113
113
|
def each_mentioned_cop
|
114
114
|
each_directive do |comment, cop_names, disabled|
|
115
115
|
comment_line_number = comment.loc.expression.line
|
116
|
-
single_line = !comment_only_line?(comment_line_number)
|
116
|
+
single_line = !comment_only_line?(comment_line_number) ||
|
117
|
+
directive_on_comment_line?(comment)
|
117
118
|
|
118
119
|
cop_names.each do |cop_name|
|
119
120
|
yield qualified_cop_name(cop_name), disabled, comment_line_number,
|
@@ -122,6 +123,10 @@ module RuboCop
|
|
122
123
|
end
|
123
124
|
end
|
124
125
|
|
126
|
+
def directive_on_comment_line?(comment)
|
127
|
+
comment.text[1..-1].match(COMMENT_DIRECTIVE_REGEXP)
|
128
|
+
end
|
129
|
+
|
125
130
|
def each_directive
|
126
131
|
return if processed_source.comments.nil?
|
127
132
|
|
@@ -69,7 +69,8 @@ module RuboCop
|
|
69
69
|
'Style/TrailingCommaInHashLiteral',
|
70
70
|
'Style/TrailingCommaInLiteral' => 'Style/TrailingCommaInArrayLiteral ' \
|
71
71
|
'and/or ' \
|
72
|
-
'Style/TrailingCommaInHashLiteral'
|
72
|
+
'Style/TrailingCommaInHashLiteral',
|
73
|
+
'Style/BracesAroundHashParameters' => nil
|
73
74
|
}.map do |old_name, other_cops|
|
74
75
|
if other_cops
|
75
76
|
more = ". Please use #{other_cops} instead".gsub(%r{[A-Z]\w+/\w+},
|
@@ -56,7 +56,8 @@ module RuboCop
|
|
56
56
|
return if nodes.all?(&:single_line?) &&
|
57
57
|
cop_config['AllowAdjacentOneLineDefs']
|
58
58
|
|
59
|
-
|
59
|
+
location = nodes.last.loc.keyword.join(nodes.last.loc.name)
|
60
|
+
add_offense(nodes.last, location: location)
|
60
61
|
end
|
61
62
|
|
62
63
|
def autocorrect(node)
|
@@ -35,6 +35,20 @@ module RuboCop
|
|
35
35
|
# # Another line of comment
|
36
36
|
# #*
|
37
37
|
#
|
38
|
+
# @example AllowGemfileRubyComment: false (default)
|
39
|
+
#
|
40
|
+
# # bad
|
41
|
+
#
|
42
|
+
# #ruby=2.7.0
|
43
|
+
# #ruby-gemset=myproject
|
44
|
+
#
|
45
|
+
# @example AllowGemfileRubyComment: true
|
46
|
+
#
|
47
|
+
# # good
|
48
|
+
#
|
49
|
+
# #ruby=2.7.0
|
50
|
+
# #ruby-gemset=myproject
|
51
|
+
#
|
38
52
|
class LeadingCommentSpace < Cop
|
39
53
|
include RangeHelp
|
40
54
|
|
@@ -44,7 +58,8 @@ module RuboCop
|
|
44
58
|
processed_source.each_comment do |comment|
|
45
59
|
next unless comment.text =~ /\A#+[^#\s=:+-]/
|
46
60
|
next if comment.loc.line == 1 && allowed_on_first_line?(comment)
|
47
|
-
next if
|
61
|
+
next if doxygen_comment_style?(comment)
|
62
|
+
next if gemfile_ruby_comment?(comment)
|
48
63
|
|
49
64
|
add_offense(comment)
|
50
65
|
end
|
@@ -80,7 +95,23 @@ module RuboCop
|
|
80
95
|
end
|
81
96
|
|
82
97
|
def doxygen_comment_style?(comment)
|
83
|
-
comment.text.start_with?('#*')
|
98
|
+
allow_doxygen_comment? && comment.text.start_with?('#*')
|
99
|
+
end
|
100
|
+
|
101
|
+
def allow_gemfile_ruby_comment?
|
102
|
+
cop_config['AllowGemfileRubyComment']
|
103
|
+
end
|
104
|
+
|
105
|
+
def gemfile?
|
106
|
+
File.basename(processed_source.file_path).eql?('Gemfile')
|
107
|
+
end
|
108
|
+
|
109
|
+
def ruby_comment_in_gemfile?(comment)
|
110
|
+
gemfile? && comment.text.start_with?('#ruby')
|
111
|
+
end
|
112
|
+
|
113
|
+
def gemfile_ruby_comment?(comment)
|
114
|
+
allow_gemfile_ruby_comment? && ruby_comment_in_gemfile?(comment)
|
84
115
|
end
|
85
116
|
end
|
86
117
|
end
|
@@ -19,19 +19,25 @@ module RuboCop
|
|
19
19
|
#
|
20
20
|
# If autocorrection is enabled, the following Layout cops
|
21
21
|
# are recommended to further format the broken lines.
|
22
|
+
# (Many of these are enabled by default.)
|
22
23
|
#
|
23
|
-
# - ParameterAlignment
|
24
24
|
# - ArgumentAlignment
|
25
|
+
# - BlockAlignment
|
26
|
+
# - BlockDelimiters
|
27
|
+
# - BlockEndNewline
|
25
28
|
# - ClosingParenthesisIndentation
|
26
29
|
# - FirstArgumentIndentation
|
27
30
|
# - FirstArrayElementIndentation
|
28
31
|
# - FirstHashElementIndentation
|
29
32
|
# - FirstParameterIndentation
|
30
33
|
# - HashAlignment
|
34
|
+
# - IndentationWidth
|
31
35
|
# - MultilineArrayLineBreaks
|
36
|
+
# - MultilineBlockLayout
|
32
37
|
# - MultilineHashBraceLayout
|
33
38
|
# - MultilineHashKeyLineBreaks
|
34
39
|
# - MultilineMethodArgumentLineBreaks
|
40
|
+
# - ParameterAlignment
|
35
41
|
#
|
36
42
|
# Together, these cops will pretty print hashes, arrays,
|
37
43
|
# method calls, etc. For example, let's say the max columns
|
@@ -61,6 +67,10 @@ module RuboCop
|
|
61
67
|
|
62
68
|
MSG = 'Line is too long. [%<length>d/%<max>d]'
|
63
69
|
|
70
|
+
def on_block(node)
|
71
|
+
check_for_breakable_block(node)
|
72
|
+
end
|
73
|
+
|
64
74
|
def on_potential_breakable_node(node)
|
65
75
|
check_for_breakable_node(node)
|
66
76
|
end
|
@@ -109,6 +119,25 @@ module RuboCop
|
|
109
119
|
end
|
110
120
|
end
|
111
121
|
|
122
|
+
def check_for_breakable_block(block_node)
|
123
|
+
return unless block_node.single_line?
|
124
|
+
|
125
|
+
line_index = block_node.loc.line - 1
|
126
|
+
range = breakable_block_range(block_node)
|
127
|
+
pos = range.begin_pos + 1
|
128
|
+
|
129
|
+
breakable_range_by_line_index[line_index] =
|
130
|
+
range_between(pos, pos + 1)
|
131
|
+
end
|
132
|
+
|
133
|
+
def breakable_block_range(block_node)
|
134
|
+
if block_node.arguments?
|
135
|
+
block_node.arguments.loc.end
|
136
|
+
else
|
137
|
+
block_node.loc.begin
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
112
141
|
def breakable_range_after_semicolon(semicolon_token)
|
113
142
|
range = semicolon_token.pos
|
114
143
|
end_pos = range.end_pos
|
@@ -105,10 +105,6 @@ module RuboCop
|
|
105
105
|
ALWAYS_SAME_LINE_MESSAGE = 'Closing hash brace must be on the same ' \
|
106
106
|
'line as the last hash element.'
|
107
107
|
|
108
|
-
def self.autocorrect_incompatible_with
|
109
|
-
[Style::BracesAroundHashParameters]
|
110
|
-
end
|
111
|
-
|
112
108
|
def on_hash(node)
|
113
109
|
check_brace_layout(node)
|
114
110
|
end
|
@@ -6,6 +6,10 @@ module RuboCop
|
|
6
6
|
# Checks that operators have space around them, except for ** which
|
7
7
|
# should or shouldn't have surrounding space depending on configuration.
|
8
8
|
#
|
9
|
+
# This cop has `AllowForAlignment` option. When `true`, allows most
|
10
|
+
# uses of extra spacing if the intent is to align with an operator on
|
11
|
+
# the previous or next line, not counting empty lines or comment lines.
|
12
|
+
#
|
9
13
|
# @example
|
10
14
|
# # bad
|
11
15
|
# total = 3*4
|
@@ -17,6 +21,20 @@ module RuboCop
|
|
17
21
|
# "apple" + "juice"
|
18
22
|
# my_number = 38 / 4
|
19
23
|
#
|
24
|
+
# @example AllowForAlignment: true (default)
|
25
|
+
# # good
|
26
|
+
# {
|
27
|
+
# 1 => 2,
|
28
|
+
# 11 => 3
|
29
|
+
# }
|
30
|
+
#
|
31
|
+
# @example AllowForAlignment: false
|
32
|
+
# # bad
|
33
|
+
# {
|
34
|
+
# 1 => 2,
|
35
|
+
# 11 => 3
|
36
|
+
# }
|
37
|
+
#
|
20
38
|
# @example EnforcedStyleForExponentOperator: no_space (default)
|
21
39
|
# # bad
|
22
40
|
# a ** b
|