rubocop 1.30.0 → 1.31.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 +4 -2
- data/config/default.yml +41 -8
- data/config/obsoletion.yml +2 -0
- data/exe/rubocop +15 -7
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +1 -1
- data/lib/rubocop/cli/command/suggest_extensions.rb +3 -3
- data/lib/rubocop/config.rb +4 -0
- data/lib/rubocop/config_loader.rb +1 -0
- data/lib/rubocop/config_validator.rb +9 -5
- data/lib/rubocop/cop/base.rb +4 -0
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
- data/lib/rubocop/cop/bundler/gem_filename.rb +4 -4
- data/lib/rubocop/cop/bundler/ordered_gems.rb +2 -2
- data/lib/rubocop/cop/corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +1 -1
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +31 -16
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +1 -1
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/require_mfa.rb +20 -20
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -5
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -1
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +25 -4
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +4 -4
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +9 -9
- data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +9 -9
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +27 -27
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +17 -11
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +49 -10
- data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +68 -0
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +120 -0
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +10 -10
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +5 -3
- data/lib/rubocop/cop/layout/trailing_empty_lines.rb +7 -7
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +51 -0
- data/lib/rubocop/cop/lint/interpolation_check.rb +1 -1
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +121 -0
- data/lib/rubocop/cop/lint/number_conversion.rb +3 -3
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +5 -5
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -1
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +2 -2
- data/lib/rubocop/cop/lint/struct_new_override.rb +2 -2
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -1
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +44 -0
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +36 -12
- data/lib/rubocop/cop/mixin/range_help.rb +7 -3
- data/lib/rubocop/cop/naming/accessor_method_name.rb +3 -1
- data/lib/rubocop/cop/naming/variable_number.rb +17 -17
- data/lib/rubocop/cop/style/accessor_grouping.rb +1 -1
- data/lib/rubocop/cop/style/and_or.rb +8 -8
- data/lib/rubocop/cop/style/arguments_forwarding.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +4 -2
- data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -0
- data/lib/rubocop/cop/style/empty_else.rb +10 -10
- data/lib/rubocop/cop/style/empty_method.rb +16 -1
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
- data/lib/rubocop/cop/style/fetch_env_var.rb +9 -2
- data/lib/rubocop/cop/style/format_string_token.rb +48 -17
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +8 -6
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +1 -1
- data/lib/rubocop/cop/style/hash_except.rb +88 -8
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +2 -2
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +1 -1
- data/lib/rubocop/cop/style/map_to_hash.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/missing_else.rb +24 -24
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -2
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +1 -3
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +1 -3
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +19 -7
- data/lib/rubocop/cop/style/nil_lambda.rb +1 -1
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/redundant_argument.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/rescue_standard_error.rb +10 -10
- data/lib/rubocop/cop/style/safe_navigation.rb +3 -0
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +2 -2
- data/lib/rubocop/cop/style/string_concatenation.rb +5 -6
- data/lib/rubocop/cop/style/struct_inheritance.rb +2 -2
- data/lib/rubocop/cop/style/swap_values.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +1 -1
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cops_documentation_generator.rb +18 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +8 -5
- data/lib/rubocop/formatter/formatter_set.rb +20 -19
- data/lib/rubocop/formatter/git_hub_actions_formatter.rb +15 -2
- data/lib/rubocop/formatter/html_formatter.rb +0 -1
- data/lib/rubocop/formatter/offense_count_formatter.rb +2 -0
- data/lib/rubocop/formatter/simple_text_formatter.rb +6 -9
- data/lib/rubocop/formatter.rb +31 -0
- data/lib/rubocop/options.rb +25 -2
- data/lib/rubocop/rake_task.rb +30 -9
- data/lib/rubocop/runner.rb +2 -2
- data/lib/rubocop/server/cache.rb +109 -0
- data/lib/rubocop/server/cli.rb +104 -0
- data/lib/rubocop/server/client_command/base.rb +44 -0
- data/lib/rubocop/server/client_command/exec.rb +59 -0
- data/lib/rubocop/server/client_command/restart.rb +25 -0
- data/lib/rubocop/server/client_command/start.rb +43 -0
- data/lib/rubocop/server/client_command/status.rb +28 -0
- data/lib/rubocop/server/client_command/stop.rb +31 -0
- data/lib/rubocop/server/client_command.rb +26 -0
- data/lib/rubocop/server/core.rb +79 -0
- data/lib/rubocop/server/errors.rb +23 -0
- data/lib/rubocop/server/helper.rb +34 -0
- data/lib/rubocop/server/server_command/base.rb +50 -0
- data/lib/rubocop/server/server_command/exec.rb +34 -0
- data/lib/rubocop/server/server_command/stop.rb +24 -0
- data/lib/rubocop/server/server_command.rb +21 -0
- data/lib/rubocop/server/socket_reader.rb +65 -0
- data/lib/rubocop/server.rb +53 -0
- data/lib/rubocop/version.rb +15 -8
- data/lib/rubocop.rb +7 -26
- metadata +27 -4
- data/lib/rubocop/cop/gemspec/date_assignment.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce713e2a82b2cedb9ee589f23d263234dfd7998fbeb1efd1bcaa7cd41fcd9c41
|
4
|
+
data.tar.gz: e60ca60484e5093ee4d266a0041c0f6b5a501fe693ace1969b9d6fb423c46d1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbce1782b8cc7ec39ba95110a4d3feaacd66f73c6aadf572da79c6ca35af0f1339341adfa9a4765056d32e42759c206037153a94619f99ffeade552e43cbd016
|
7
|
+
data.tar.gz: b93cb01f0f1e53302c61bc45ad1d680d89c5e338539aa084b59d072af27dc4eb7b74da88dc05512f879f0277eeaa8e84950fd55fbfcc5d0144eba7be7134df3b
|
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.31', require: false
|
57
57
|
```
|
58
58
|
|
59
59
|
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
|
@@ -73,11 +73,13 @@ You can read a lot more about RuboCop in its [official docs](https://docs.ruboco
|
|
73
73
|
|
74
74
|
## Compatibility
|
75
75
|
|
76
|
-
RuboCop officially supports the following Ruby implementations:
|
76
|
+
RuboCop officially supports the following runtime Ruby implementations:
|
77
77
|
|
78
78
|
* MRI 2.6+
|
79
79
|
* JRuby 9.3+
|
80
80
|
|
81
|
+
Targets Ruby 2.0+ code analysis.
|
82
|
+
|
81
83
|
See the [compatibility documentation](https://docs.rubocop.org/rubocop/compatibility.html) for further details.
|
82
84
|
|
83
85
|
## Readme Badge
|
data/config/default.yml
CHANGED
@@ -153,6 +153,8 @@ AllCops:
|
|
153
153
|
rubocop-sequel: [sequel]
|
154
154
|
rubocop-rake: [rake]
|
155
155
|
rubocop-graphql: [graphql]
|
156
|
+
# Enable/Disable checking the methods extended by Active Support.
|
157
|
+
ActiveSupportExtensionsEnabled: false
|
156
158
|
|
157
159
|
#################### Bundler ###############################
|
158
160
|
|
@@ -235,13 +237,6 @@ Bundler/OrderedGems:
|
|
235
237
|
|
236
238
|
#################### Gemspec ###############################
|
237
239
|
|
238
|
-
Gemspec/DateAssignment:
|
239
|
-
Description: 'Checks that `date =` is not used in gemspec file, it is set automatically when the gem is packaged.'
|
240
|
-
Enabled: pending
|
241
|
-
VersionAdded: '1.10'
|
242
|
-
Include:
|
243
|
-
- '**/*.gemspec'
|
244
|
-
|
245
240
|
Gemspec/DependencyVersion:
|
246
241
|
Description: 'Requires or forbids specifying gem dependency versions.'
|
247
242
|
Enabled: false
|
@@ -974,6 +969,26 @@ Layout/LeadingEmptyLines:
|
|
974
969
|
VersionAdded: '0.57'
|
975
970
|
VersionChanged: '0.77'
|
976
971
|
|
972
|
+
Layout/LineContinuationLeadingSpace:
|
973
|
+
Description: >-
|
974
|
+
Use trailing spaces instead of leading spaces in strings
|
975
|
+
broken over multiple lines (by a backslash).
|
976
|
+
Enabled: pending
|
977
|
+
AutoCorrect: false
|
978
|
+
SafeAutoCorrect: false
|
979
|
+
VersionAdded: '1.31'
|
980
|
+
|
981
|
+
Layout/LineContinuationSpacing:
|
982
|
+
Description: 'Checks the spacing in front of backslash in line continuations.'
|
983
|
+
Enabled: pending
|
984
|
+
AutoCorrect: true
|
985
|
+
SafeAutoCorrect: true
|
986
|
+
VersionAdded: '1.31'
|
987
|
+
EnforcedStyle: space
|
988
|
+
SupportedStyles:
|
989
|
+
- space
|
990
|
+
- no_space
|
991
|
+
|
977
992
|
Layout/LineEndStringConcatenationIndentation:
|
978
993
|
Description: >-
|
979
994
|
Checks the indentation of the next line after a line that
|
@@ -1550,6 +1565,11 @@ Lint/ConstantDefinitionInBlock:
|
|
1550
1565
|
AllowedMethods:
|
1551
1566
|
- enums
|
1552
1567
|
|
1568
|
+
Lint/ConstantOverwrittenInRescue:
|
1569
|
+
Description: 'Checks for overwriting an exception with an exception result by use `rescue =>`.'
|
1570
|
+
Enabled: pending
|
1571
|
+
VersionAdded: '1.31'
|
1572
|
+
|
1553
1573
|
Lint/ConstantResolution:
|
1554
1574
|
Description: 'Check that constants are fully qualified with `::`.'
|
1555
1575
|
Enabled: false
|
@@ -1936,6 +1956,12 @@ Lint/NoReturnInBeginEndBlocks:
|
|
1936
1956
|
Enabled: pending
|
1937
1957
|
VersionAdded: '1.2'
|
1938
1958
|
|
1959
|
+
Lint/NonAtomicFileOperation:
|
1960
|
+
Description: Checks for non-atomic file operations.
|
1961
|
+
Enabled: pending
|
1962
|
+
VersionAdded: '1.31'
|
1963
|
+
SafeAutoCorrect: false
|
1964
|
+
|
1939
1965
|
Lint/NonDeterministicRequireOrder:
|
1940
1966
|
Description: 'Always sort arrays returned by Dir.glob when requiring files.'
|
1941
1967
|
Enabled: true
|
@@ -2348,6 +2374,12 @@ Lint/UselessAssignment:
|
|
2348
2374
|
Enabled: true
|
2349
2375
|
VersionAdded: '0.11'
|
2350
2376
|
|
2377
|
+
Lint/UselessElseWithoutRescue:
|
2378
|
+
Description: 'Checks for useless `else` in `begin..end` without `rescue`.'
|
2379
|
+
Enabled: true
|
2380
|
+
VersionAdded: '0.17'
|
2381
|
+
VersionChanged: '1.31'
|
2382
|
+
|
2351
2383
|
Lint/UselessMethodDefinition:
|
2352
2384
|
Description: 'Checks for useless method definitions.'
|
2353
2385
|
Enabled: true
|
@@ -3677,7 +3709,7 @@ Style/GuardClause:
|
|
3677
3709
|
StyleGuide: '#no-nested-conditionals'
|
3678
3710
|
Enabled: true
|
3679
3711
|
VersionAdded: '0.20'
|
3680
|
-
VersionChanged: '1.
|
3712
|
+
VersionChanged: '1.31'
|
3681
3713
|
# `MinBodyLength` defines the number of lines of the a body of an `if` or `unless`
|
3682
3714
|
# needs to have to trigger this cop
|
3683
3715
|
MinBodyLength: 1
|
@@ -3718,6 +3750,7 @@ Style/HashExcept:
|
|
3718
3750
|
that can be replaced with `Hash#except` method.
|
3719
3751
|
Enabled: pending
|
3720
3752
|
VersionAdded: '1.7'
|
3753
|
+
VersionChanged: '1.31'
|
3721
3754
|
|
3722
3755
|
Style/HashLikeCase:
|
3723
3756
|
Description: >-
|
data/config/obsoletion.yml
CHANGED
data/exe/rubocop
CHANGED
@@ -3,13 +3,21 @@
|
|
3
3
|
|
4
4
|
$LOAD_PATH.unshift("#{__dir__}/../lib")
|
5
5
|
|
6
|
-
require 'rubocop'
|
7
|
-
|
6
|
+
require 'rubocop/server'
|
7
|
+
server_cli = RuboCop::Server::CLI.new
|
8
|
+
exit_status = server_cli.run
|
9
|
+
exit exit_status if server_cli.exit?
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
if RuboCop::Server.running?
|
12
|
+
exit_status = RuboCop::Server::ClientCommand::Exec.new.run
|
13
|
+
else
|
14
|
+
require 'rubocop'
|
15
|
+
require 'benchmark'
|
11
16
|
|
12
|
-
|
17
|
+
cli = RuboCop::CLI.new
|
13
18
|
|
14
|
-
|
15
|
-
|
19
|
+
time = Benchmark.realtime { exit_status = cli.run }
|
20
|
+
|
21
|
+
puts "Finished in #{time} seconds" if cli.options[:debug] || cli.options[:display_time]
|
22
|
+
end
|
23
|
+
exit exit_status
|
@@ -112,7 +112,7 @@ module RuboCop
|
|
112
112
|
|
113
113
|
write_config_file(config_file, file_string, rubocop_yml_contents)
|
114
114
|
|
115
|
-
puts "Added inheritance from `#{relative_path_to_todo_from_options_config}` "\
|
115
|
+
puts "Added inheritance from `#{relative_path_to_todo_from_options_config}` " \
|
116
116
|
"in `#{ConfigLoader::DOTFILE}`."
|
117
117
|
end
|
118
118
|
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
return if skip? || extensions.none?
|
19
19
|
|
20
20
|
puts
|
21
|
-
puts 'Tip: Based on detected gems, the following '\
|
21
|
+
puts 'Tip: Based on detected gems, the following ' \
|
22
22
|
'RuboCop extension libraries might be helpful:'
|
23
23
|
|
24
24
|
extensions.sort.each do |extension|
|
@@ -26,8 +26,8 @@ module RuboCop
|
|
26
26
|
end
|
27
27
|
|
28
28
|
puts
|
29
|
-
puts 'You can opt out of this message by adding the following to your config '\
|
30
|
-
'(see https://docs.rubocop.org/rubocop/extensions.html#extension-suggestions '\
|
29
|
+
puts 'You can opt out of this message by adding the following to your config ' \
|
30
|
+
'(see https://docs.rubocop.org/rubocop/extensions.html#extension-suggestions ' \
|
31
31
|
'for more options):'
|
32
32
|
puts ' AllCops:'
|
33
33
|
puts ' SuggestExtensions: false'
|
data/lib/rubocop/config.rb
CHANGED
@@ -146,6 +146,10 @@ module RuboCop
|
|
146
146
|
for_all_cops['NewCops'] == 'enable'
|
147
147
|
end
|
148
148
|
|
149
|
+
def active_support_extensions_enabled?
|
150
|
+
for_all_cops['ActiveSupportExtensionsEnabled']
|
151
|
+
end
|
152
|
+
|
149
153
|
def file_to_include?(file)
|
150
154
|
relative_file_path = path_relative_to_config(file)
|
151
155
|
|
@@ -104,13 +104,17 @@ module RuboCop
|
|
104
104
|
def alert_about_unrecognized_cops(invalid_cop_names)
|
105
105
|
unknown_cops = list_unknown_cops(invalid_cop_names)
|
106
106
|
|
107
|
+
return if unknown_cops.empty?
|
108
|
+
|
107
109
|
if ConfigLoader.ignore_unrecognized_cops
|
108
|
-
warn Rainbow('The following cops or departments are not '\
|
110
|
+
warn Rainbow('The following cops or departments are not ' \
|
109
111
|
'recognized and will be ignored:').yellow
|
110
112
|
warn unknown_cops.join("\n")
|
111
|
-
|
112
|
-
|
113
|
+
|
114
|
+
return
|
113
115
|
end
|
116
|
+
|
117
|
+
raise ValidationError, unknown_cops.join("\n")
|
114
118
|
end
|
115
119
|
|
116
120
|
def list_unknown_cops(invalid_cop_names)
|
@@ -261,8 +265,8 @@ module RuboCop
|
|
261
265
|
# FIXME: Handling colors in exception messages like this is ugly.
|
262
266
|
def msg_not_boolean(parent, key, value)
|
263
267
|
"#{Rainbow('').reset}" \
|
264
|
-
"Property #{Rainbow(key).yellow} of cop #{Rainbow(parent).yellow}" \
|
265
|
-
"
|
268
|
+
"Property #{Rainbow(key).yellow} of cop #{Rainbow(parent).yellow} " \
|
269
|
+
"is supposed to be a boolean and #{Rainbow(value).yellow} is not."
|
266
270
|
end
|
267
271
|
end
|
268
272
|
end
|
data/lib/rubocop/cop/base.rb
CHANGED
@@ -220,6 +220,10 @@ module RuboCop
|
|
220
220
|
@config.target_rails_version
|
221
221
|
end
|
222
222
|
|
223
|
+
def active_support_extensions_enabled?
|
224
|
+
@config.active_support_extensions_enabled?
|
225
|
+
end
|
226
|
+
|
223
227
|
def relevant_file?(file)
|
224
228
|
file == RuboCop::AST::ProcessedSource::STRING_SOURCE_NAME ||
|
225
229
|
(file_name_matches_any?(file, 'Include', true) &&
|
@@ -38,7 +38,7 @@ module RuboCop
|
|
38
38
|
class DuplicatedGem < Base
|
39
39
|
include RangeHelp
|
40
40
|
|
41
|
-
MSG = 'Gem `%<gem_name>s` requirements already given on line '\
|
41
|
+
MSG = 'Gem `%<gem_name>s` requirements already given on line ' \
|
42
42
|
'%<line_of_first_occurrence>d of the Gemfile.'
|
43
43
|
|
44
44
|
def on_new_investigation
|
@@ -29,13 +29,13 @@ module RuboCop
|
|
29
29
|
include ConfigurableEnforcedStyle
|
30
30
|
include RangeHelp
|
31
31
|
|
32
|
-
MSG_GEMFILE_REQUIRED = '`gems.rb` file was found but `Gemfile` is required '\
|
32
|
+
MSG_GEMFILE_REQUIRED = '`gems.rb` file was found but `Gemfile` is required ' \
|
33
33
|
'(file path: %<file_path>s).'
|
34
|
-
MSG_GEMS_RB_REQUIRED = '`Gemfile` was found but `gems.rb` file is required '\
|
34
|
+
MSG_GEMS_RB_REQUIRED = '`Gemfile` was found but `gems.rb` file is required ' \
|
35
35
|
'(file path: %<file_path>s).'
|
36
|
-
MSG_GEMFILE_MISMATCHED = 'Expected a `Gemfile.lock` with `Gemfile` but found '\
|
36
|
+
MSG_GEMFILE_MISMATCHED = 'Expected a `Gemfile.lock` with `Gemfile` but found ' \
|
37
37
|
'`gems.locked` file (file path: %<file_path>s).'
|
38
|
-
MSG_GEMS_RB_MISMATCHED = 'Expected a `gems.locked` file with `gems.rb` but found '\
|
38
|
+
MSG_GEMS_RB_MISMATCHED = 'Expected a `gems.locked` file with `gems.rb` but found ' \
|
39
39
|
'`Gemfile.lock` (file path: %<file_path>s).'
|
40
40
|
GEMFILE_FILES = %w[Gemfile Gemfile.lock].freeze
|
41
41
|
GEMS_RB_FILES = %w[gems.rb gems.locked].freeze
|
@@ -28,8 +28,8 @@ module RuboCop
|
|
28
28
|
extend AutoCorrector
|
29
29
|
include OrderedGemNode
|
30
30
|
|
31
|
-
MSG = 'Gems should be sorted in an alphabetical order within their '\
|
32
|
-
'section of the Gemfile. '\
|
31
|
+
MSG = 'Gems should be sorted in an alphabetical order within their ' \
|
32
|
+
'section of the Gemfile. ' \
|
33
33
|
'Gem `%<previous>s` should appear before `%<current>s`.'
|
34
34
|
|
35
35
|
def on_new_investigation
|
@@ -109,8 +109,8 @@ module RuboCop
|
|
109
109
|
"Parser::Source::Buffer, but got #{buffer.class}"
|
110
110
|
end
|
111
111
|
raise "Correction target buffer #{buffer.object_id} " \
|
112
|
-
"name:#{buffer.name.inspect}" \
|
113
|
-
"
|
112
|
+
"name:#{buffer.name.inspect} " \
|
113
|
+
"is not current #{@source_buffer.object_id} " \
|
114
114
|
"name:#{@source_buffer.name.inspect} under investigation"
|
115
115
|
end
|
116
116
|
end
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def correct_next_line_brace(corrector)
|
44
|
-
corrector.remove(range_with_surrounding_space(
|
44
|
+
corrector.remove(range_with_surrounding_space(node.loc.end, side: :left))
|
45
45
|
|
46
46
|
corrector.insert_before(
|
47
47
|
last_element_range_with_trailing_comma(node).end,
|
@@ -51,7 +51,7 @@ module RuboCop
|
|
51
51
|
|
52
52
|
def content_if_comment_present(corrector, node)
|
53
53
|
range = range_with_surrounding_space(
|
54
|
-
|
54
|
+
children(node).last.source_range,
|
55
55
|
side: :right
|
56
56
|
).end.resize(1)
|
57
57
|
if range.source == '#'
|
@@ -86,7 +86,7 @@ module RuboCop
|
|
86
86
|
|
87
87
|
def last_element_trailing_comma_range(node)
|
88
88
|
range = range_with_surrounding_space(
|
89
|
-
|
89
|
+
children(node).last.source_range,
|
90
90
|
side: :right
|
91
91
|
).end.resize(1)
|
92
92
|
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def correct_for_blockarg_type(corrector, node)
|
32
|
-
range = range_with_surrounding_space(
|
32
|
+
range = range_with_surrounding_space(node.source_range, side: :left)
|
33
33
|
range = range_with_surrounding_comma(range, :left)
|
34
34
|
|
35
35
|
corrector.remove(range)
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Gemspec
|
6
6
|
# Checks that deprecated attribute attributes are not set in a gemspec file.
|
7
|
-
# Removing
|
7
|
+
# Removing deprecated attributes allows the user to receive smaller packed gems.
|
8
8
|
#
|
9
9
|
# @example
|
10
10
|
#
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
include RangeHelp
|
30
30
|
extend AutoCorrector
|
31
31
|
|
32
|
-
MSG = 'Do not set `
|
32
|
+
MSG = 'Do not set `%<attribute>s` in gemspec.'
|
33
33
|
|
34
34
|
# @!method gem_specification(node)
|
35
35
|
def_node_matcher :gem_specification, <<~PATTERN
|
@@ -45,14 +45,14 @@ module RuboCop
|
|
45
45
|
|
46
46
|
block_parameter = block_node.arguments.first.source
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
assignment = block_node.descendants.detect do |node|
|
49
|
+
use_deprecated_attributes?(node, block_parameter)
|
50
50
|
end
|
51
|
+
return unless assignment
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
range = range_by_whole_lines(date_assignment.source_range, include_final_newline: true)
|
53
|
+
message = format_message_from
|
54
|
+
add_offense(assignment, message: message) do |corrector|
|
55
|
+
range = range_by_whole_lines(assignment.source_range, include_final_newline: true)
|
56
56
|
|
57
57
|
corrector.remove(range)
|
58
58
|
end
|
@@ -60,16 +60,31 @@ module RuboCop
|
|
60
60
|
|
61
61
|
private
|
62
62
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
63
|
+
def node_and_method_name(node, attribute)
|
64
|
+
if node.op_asgn_type?
|
65
|
+
lhs, _op, _rhs = *node
|
66
|
+
[lhs, attribute]
|
67
|
+
else
|
68
|
+
[node, "#{attribute}=".to_sym]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def use_deprecated_attributes?(node, block_parameter)
|
73
|
+
%i[test_files date specification_version rubygems_version].each do |attribute|
|
74
|
+
node, method_name = node_and_method_name(node, attribute)
|
75
|
+
unless node.send_type? && node.receiver&.source == block_parameter &&
|
76
|
+
node.method?(method_name)
|
77
|
+
next
|
78
|
+
end
|
66
79
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
80
|
+
@attribute = attribute.to_s
|
81
|
+
return true
|
82
|
+
end
|
83
|
+
false
|
84
|
+
end
|
71
85
|
|
72
|
-
|
86
|
+
def format_message_from
|
87
|
+
format(MSG, attribute: @attribute)
|
73
88
|
end
|
74
89
|
end
|
75
90
|
end
|
@@ -38,7 +38,7 @@ module RuboCop
|
|
38
38
|
include RangeHelp
|
39
39
|
include GemspecHelp
|
40
40
|
|
41
|
-
MSG = '`%<assignment>s` method calls already given on line '\
|
41
|
+
MSG = '`%<assignment>s` method calls already given on line ' \
|
42
42
|
'%<line_of_first_occurrence>d of the gemspec.'
|
43
43
|
|
44
44
|
# @!method assignment_method_declarations(node)
|
@@ -55,7 +55,7 @@ module RuboCop
|
|
55
55
|
include OrderedGemNode
|
56
56
|
|
57
57
|
MSG = 'Dependencies should be sorted in an alphabetical order within ' \
|
58
|
-
'their section of the gemspec. '\
|
58
|
+
'their section of the gemspec. ' \
|
59
59
|
'Dependency `%<previous>s` should appear before `%<current>s`.'
|
60
60
|
|
61
61
|
def on_new_investigation
|
@@ -36,29 +36,29 @@ module RuboCop
|
|
36
36
|
# spec.metadata['rubygems_mfa_required'] = 'true'
|
37
37
|
# end
|
38
38
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
39
|
+
# # bad
|
40
|
+
# Gem::Specification.new do |spec|
|
41
|
+
# spec.metadata = {
|
42
|
+
# 'rubygems_mfa_required' => 'false'
|
43
|
+
# }
|
44
|
+
# end
|
45
45
|
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
46
|
+
# # good
|
47
|
+
# Gem::Specification.new do |spec|
|
48
|
+
# spec.metadata = {
|
49
|
+
# 'rubygems_mfa_required' => 'true'
|
50
|
+
# }
|
51
|
+
# end
|
52
52
|
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
53
|
+
# # bad
|
54
|
+
# Gem::Specification.new do |spec|
|
55
|
+
# spec.metadata['rubygems_mfa_required'] = 'false'
|
56
|
+
# end
|
57
57
|
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
58
|
+
# # good
|
59
|
+
# Gem::Specification.new do |spec|
|
60
|
+
# spec.metadata['rubygems_mfa_required'] = 'true'
|
61
|
+
# end
|
62
62
|
#
|
63
63
|
class RequireMFA < Base
|
64
64
|
include GemspecHelp
|
@@ -99,11 +99,7 @@ module RuboCop
|
|
99
99
|
# If the pattern matcher uses arguments (`%1`, `%2`, etc.), include them in the directive
|
100
100
|
arguments = pattern_arguments(node.arguments[1].source)
|
101
101
|
|
102
|
-
range = range_with_surrounding_space(
|
103
|
-
range: node.loc.expression,
|
104
|
-
side: :left,
|
105
|
-
newlines: false
|
106
|
-
)
|
102
|
+
range = range_with_surrounding_space(node.loc.expression, side: :left, newlines: false)
|
107
103
|
indentation = range.source.match(/^\s*/)[0]
|
108
104
|
directive = "#{indentation}# @!method #{actual_name}(#{arguments.join(', ')})\n"
|
109
105
|
directive = "\n#{directive}" if add_newline?(node)
|
@@ -145,7 +145,7 @@ module RuboCop
|
|
145
145
|
return false unless hash_argument_config['Enabled']
|
146
146
|
|
147
147
|
RuboCop::Cop::Layout::HashAlignment::SEPARATOR_ALIGNMENT_STYLES.any? do |style|
|
148
|
-
hash_argument_config[style]
|
148
|
+
hash_argument_config[style]&.include?('separator')
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
@@ -97,7 +97,7 @@ module RuboCop
|
|
97
97
|
def autocorrect(corrector, node)
|
98
98
|
previous_token = previous_token(node)
|
99
99
|
range = if previous_token && same_line?(node, previous_token)
|
100
|
-
range_with_surrounding_space(
|
100
|
+
range_with_surrounding_space(node.loc.expression, newlines: false)
|
101
101
|
else
|
102
102
|
range_by_whole_lines(node.loc.expression, include_final_newline: true)
|
103
103
|
end
|
@@ -70,18 +70,39 @@ module RuboCop
|
|
70
70
|
def on_send(node)
|
71
71
|
return unless node.attribute_accessor?
|
72
72
|
return if next_line_empty?(node.last_line)
|
73
|
+
return if next_line_empty_or_enable_directive_comment?(node.last_line)
|
73
74
|
|
74
75
|
next_line_node = next_line_node(node)
|
75
76
|
return unless require_empty_line?(next_line_node)
|
76
77
|
|
77
|
-
add_offense(node)
|
78
|
-
|
78
|
+
add_offense(node) { |corrector| autocorrect(corrector, node) }
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
79
82
|
|
80
|
-
|
83
|
+
def autocorrect(corrector, node)
|
84
|
+
node_range = range_by_whole_lines(node.source_range)
|
85
|
+
|
86
|
+
next_line = node_range.last_line + 1
|
87
|
+
if next_line_enable_directive_comment?(next_line)
|
88
|
+
node_range = processed_source.comment_at_line(next_line)
|
81
89
|
end
|
90
|
+
|
91
|
+
corrector.insert_after(node_range, "\n")
|
82
92
|
end
|
83
93
|
|
84
|
-
|
94
|
+
def next_line_empty_or_enable_directive_comment?(line)
|
95
|
+
return true if next_line_empty?(line)
|
96
|
+
|
97
|
+
next_line = line + 1
|
98
|
+
next_line_enable_directive_comment?(next_line) && next_line_empty?(next_line)
|
99
|
+
end
|
100
|
+
|
101
|
+
def next_line_enable_directive_comment?(line)
|
102
|
+
return false unless (comment = processed_source.comment_at_line(line))
|
103
|
+
|
104
|
+
DirectiveComment.new(comment).enabled?
|
105
|
+
end
|
85
106
|
|
86
107
|
def next_line_empty?(line)
|
87
108
|
processed_source[line].nil? || processed_source[line].blank?
|
@@ -6,20 +6,20 @@ module RuboCop
|
|
6
6
|
# Checks if empty lines around the bodies of blocks match
|
7
7
|
# the configuration.
|
8
8
|
#
|
9
|
-
# @example EnforcedStyle:
|
9
|
+
# @example EnforcedStyle: no_empty_lines (default)
|
10
10
|
# # good
|
11
11
|
#
|
12
12
|
# foo do |bar|
|
13
|
-
#
|
14
13
|
# # ...
|
15
|
-
#
|
16
14
|
# end
|
17
15
|
#
|
18
|
-
# @example EnforcedStyle:
|
16
|
+
# @example EnforcedStyle: empty_lines
|
19
17
|
# # good
|
20
18
|
#
|
21
19
|
# foo do |bar|
|
20
|
+
#
|
22
21
|
# # ...
|
22
|
+
#
|
23
23
|
# end
|
24
24
|
class EmptyLinesAroundBlockBody < Base
|
25
25
|
include EmptyLinesAroundBody
|