rubocop 1.19.0 → 1.22.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 +86 -14
- data/lib/rubocop/config.rb +5 -0
- data/lib/rubocop/config_loader.rb +4 -2
- data/lib/rubocop/config_validator.rb +9 -1
- data/lib/rubocop/cop/base.rb +3 -3
- data/lib/rubocop/cop/bundler/gem_filename.rb +103 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +45 -21
- data/lib/rubocop/cop/bundler/ordered_gems.rb +3 -12
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +11 -10
- data/lib/rubocop/cop/documentation.rb +1 -1
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +3 -12
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
- data/lib/rubocop/cop/generator.rb +14 -8
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +2 -1
- data/lib/rubocop/cop/layout/dot_position.rb +25 -2
- data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +8 -6
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +3 -0
- data/lib/rubocop/cop/layout/redundant_line_break.rb +1 -0
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +5 -4
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +15 -4
- data/lib/rubocop/cop/layout/space_after_not.rb +1 -0
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +2 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_before_brackets.rb +1 -0
- data/lib/rubocop/cop/layout/space_inside_parens.rb +74 -24
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_operator_precedence.rb +111 -0
- data/lib/rubocop/cop/lint/ambiguous_range.rb +8 -8
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +7 -5
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +18 -5
- data/lib/rubocop/cop/lint/boolean_symbol.rb +5 -0
- data/lib/rubocop/cop/lint/debugger.rb +2 -4
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
- data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +24 -1
- data/lib/rubocop/cop/lint/else_layout.rb +9 -5
- data/lib/rubocop/cop/lint/empty_in_pattern.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +12 -3
- data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +67 -0
- data/lib/rubocop/cop/lint/interpolation_check.rb +5 -0
- data/lib/rubocop/cop/lint/loop.rb +4 -3
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +5 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +12 -1
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -1
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +4 -2
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +17 -0
- data/lib/rubocop/cop/lint/percent_string_array.rb +10 -0
- data/lib/rubocop/cop/lint/raise_exception.rb +4 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +5 -4
- data/lib/rubocop/cop/lint/require_relative_self_path.rb +49 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
- data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/triple_quotes.rb +1 -1
- data/lib/rubocop/cop/lint/unexpected_block_arity.rb +8 -3
- data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -3
- data/lib/rubocop/cop/lint/useless_method_definition.rb +3 -2
- data/lib/rubocop/cop/lint/useless_setter_call.rb +7 -4
- data/lib/rubocop/cop/lint/useless_times.rb +4 -3
- data/lib/rubocop/cop/metrics/abc_size.rb +6 -0
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/annotation_comment.rb +57 -34
- data/lib/rubocop/cop/mixin/code_length.rb +1 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +5 -2
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +23 -1
- data/lib/rubocop/cop/mixin/heredoc.rb +1 -3
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -2
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +9 -1
- data/lib/rubocop/cop/mixin/percent_array.rb +11 -3
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +9 -1
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +0 -3
- data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +1 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +9 -9
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +5 -4
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +7 -0
- data/lib/rubocop/cop/security/io_methods.rb +49 -0
- data/lib/rubocop/cop/security/json_load.rb +8 -7
- data/lib/rubocop/cop/security/open.rb +4 -0
- data/lib/rubocop/cop/security/yaml_load.rb +4 -0
- data/lib/rubocop/cop/style/accessor_grouping.rb +2 -2
- data/lib/rubocop/cop/style/and_or.rb +5 -0
- data/lib/rubocop/cop/style/arguments_forwarding.rb +13 -2
- data/lib/rubocop/cop/style/array_coercion.rb +21 -3
- data/lib/rubocop/cop/style/ascii_comments.rb +0 -3
- data/lib/rubocop/cop/style/block_delimiters.rb +23 -6
- data/lib/rubocop/cop/style/case_equality.rb +6 -9
- data/lib/rubocop/cop/style/case_like_if.rb +5 -0
- data/lib/rubocop/cop/style/class_and_module_children.rb +9 -0
- data/lib/rubocop/cop/style/collection_compact.rb +7 -5
- data/lib/rubocop/cop/style/collection_methods.rb +8 -6
- data/lib/rubocop/cop/style/combinable_loops.rb +3 -2
- data/lib/rubocop/cop/style/comment_annotation.rb +25 -39
- data/lib/rubocop/cop/style/commented_keyword.rb +4 -1
- data/lib/rubocop/cop/style/date_time.rb +5 -0
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +23 -8
- data/lib/rubocop/cop/style/double_negation.rb +27 -6
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/encoding.rb +26 -15
- data/lib/rubocop/cop/style/explicit_block_argument.rb +21 -11
- data/lib/rubocop/cop/style/float_division.rb +10 -2
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +7 -2
- data/lib/rubocop/cop/style/global_std_stream.rb +4 -0
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +11 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +5 -0
- data/lib/rubocop/cop/style/hash_except.rb +4 -3
- data/lib/rubocop/cop/style/hash_transform_keys.rb +4 -6
- data/lib/rubocop/cop/style/hash_transform_values.rb +4 -6
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +18 -16
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +18 -4
- data/lib/rubocop/cop/style/infinite_loop.rb +4 -3
- data/lib/rubocop/cop/style/inverse_methods.rb +9 -2
- data/lib/rubocop/cop/style/lambda_call.rb +1 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +13 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +6 -6
- data/lib/rubocop/cop/style/module_function.rb +8 -9
- data/lib/rubocop/cop/style/mutable_constant.rb +73 -6
- data/lib/rubocop/cop/style/negated_if.rb +1 -1
- data/lib/rubocop/cop/style/negated_unless.rb +1 -1
- data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
- data/lib/rubocop/cop/style/not.rb +2 -2
- data/lib/rubocop/cop/style/numbered_parameters.rb +46 -0
- data/lib/rubocop/cop/style/numbered_parameters_limit.rb +50 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +7 -8
- data/lib/rubocop/cop/style/numeric_predicate.rb +5 -0
- data/lib/rubocop/cop/style/optional_arguments.rb +4 -0
- data/lib/rubocop/cop/style/optional_boolean_parameter.rb +14 -4
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +2 -2
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +9 -4
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/redundant_argument.rb +14 -7
- data/lib/rubocop/cop/style/redundant_begin.rb +25 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -3
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +4 -0
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +12 -3
- data/lib/rubocop/cop/style/redundant_freeze.rb +4 -4
- data/lib/rubocop/cop/style/redundant_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -3
- data/lib/rubocop/cop/style/redundant_self.rb +10 -0
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +4 -3
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +23 -28
- data/lib/rubocop/cop/style/redundant_sort.rb +51 -18
- data/lib/rubocop/cop/style/regexp_literal.rb +3 -3
- data/lib/rubocop/cop/style/return_nil.rb +2 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +13 -2
- data/lib/rubocop/cop/style/select_by_regexp.rb +106 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +5 -0
- data/lib/rubocop/cop/style/slicing_with_range.rb +13 -0
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +4 -0
- data/lib/rubocop/cop/style/special_global_vars.rb +4 -0
- data/lib/rubocop/cop/style/static_class.rb +5 -5
- data/lib/rubocop/cop/style/string_chars.rb +4 -2
- data/lib/rubocop/cop/style/string_concatenation.rb +5 -1
- data/lib/rubocop/cop/style/string_hash_keys.rb +4 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +4 -0
- data/lib/rubocop/cop/style/swap_values.rb +4 -2
- data/lib/rubocop/cop/style/symbol_array.rb +3 -3
- data/lib/rubocop/cop/style/symbol_proc.rb +26 -0
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +19 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +3 -3
- data/lib/rubocop/cop/style/yoda_condition.rb +24 -7
- data/lib/rubocop/cop/style/zero_length_predicate.rb +6 -0
- data/lib/rubocop/cop/util.rb +2 -2
- data/lib/rubocop/cops_documentation_generator.rb +17 -5
- data/lib/rubocop/magic_comment.rb +44 -15
- data/lib/rubocop/options.rb +126 -112
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +6 -2
- data/lib/rubocop/runner.rb +1 -2
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +10 -2
- metadata +13 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08520f6dcf324dcb95ce7191673f070e86c3b5c2613942d19e4c951119a43476'
|
4
|
+
data.tar.gz: 90fd28bb4692e3feb9973d0b711a181c90608b205741b4b68cc23df9a9d42142
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27a14f94b096be10618d7670ff591f4443ab4e09d8fce7f2604e686a1f7ab5544aaf53136c09a6ec62198f9f56950b5ab0c3cea64ee0ccd565e328b7ba131a5d
|
7
|
+
data.tar.gz: 419cf3d94cf235cf31b09d26cbed550937dcb1930797e3e28c97cfb27116b160732aeec5434de8e0c3417f6900bf795c1826d7941e49cf8f12e9a15c245472b4
|
data/README.md
CHANGED
@@ -54,7 +54,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
|
|
54
54
|
in your `Gemfile`:
|
55
55
|
|
56
56
|
```rb
|
57
|
-
gem 'rubocop', '~> 1.
|
57
|
+
gem 'rubocop', '~> 1.22', require: false
|
58
58
|
```
|
59
59
|
|
60
60
|
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
|
data/config/default.yml
CHANGED
@@ -130,7 +130,7 @@ AllCops:
|
|
130
130
|
# What MRI version of the Ruby interpreter is the inspected code intended to
|
131
131
|
# run on? (If there is more than one, set this to the lowest version.)
|
132
132
|
# If a value is specified for TargetRubyVersion then it is used. Acceptable
|
133
|
-
# values are
|
133
|
+
# values are specified as a float (i.e. 3.0); the teeny version of Ruby
|
134
134
|
# should not be included. If the project specifies a Ruby version in the
|
135
135
|
# .tool-versions or .ruby-version files, Gemfile or gems.rb file, RuboCop will
|
136
136
|
# try to determine the desired version of Ruby by inspecting the
|
@@ -174,6 +174,20 @@ Bundler/GemComment:
|
|
174
174
|
IgnoredGems: []
|
175
175
|
OnlyFor: []
|
176
176
|
|
177
|
+
Bundler/GemFilename:
|
178
|
+
Description: 'Enforces the filename for managing gems.'
|
179
|
+
Enabled: true
|
180
|
+
VersionAdded: '1.20'
|
181
|
+
EnforcedStyle: 'Gemfile'
|
182
|
+
SupportedStyles:
|
183
|
+
- 'Gemfile'
|
184
|
+
- 'gems.rb'
|
185
|
+
Include:
|
186
|
+
- '**/Gemfile'
|
187
|
+
- '**/gems.rb'
|
188
|
+
- '**/Gemfile.lock'
|
189
|
+
- '**/gems.locked'
|
190
|
+
|
177
191
|
Bundler/GemVersion:
|
178
192
|
Description: 'Requires or forbids specifying gem versions.'
|
179
193
|
Enabled: false
|
@@ -195,6 +209,7 @@ Bundler/InsecureProtocolSource:
|
|
195
209
|
'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
|
196
210
|
Enabled: true
|
197
211
|
VersionAdded: '0.50'
|
212
|
+
AllowHttpProtocol: true
|
198
213
|
Include:
|
199
214
|
- '**/*.gemfile'
|
200
215
|
- '**/Gemfile'
|
@@ -943,7 +958,6 @@ Layout/LineLength:
|
|
943
958
|
Enabled: true
|
944
959
|
VersionAdded: '0.25'
|
945
960
|
VersionChanged: '1.4'
|
946
|
-
AutoCorrect: true
|
947
961
|
Max: 120
|
948
962
|
# To make it possible to copy or click on URIs in the code, we allow lines
|
949
963
|
# containing a URI to be longer than Max.
|
@@ -1347,10 +1361,11 @@ Layout/SpaceInsideParens:
|
|
1347
1361
|
StyleGuide: '#spaces-braces'
|
1348
1362
|
Enabled: true
|
1349
1363
|
VersionAdded: '0.49'
|
1350
|
-
VersionChanged: '
|
1364
|
+
VersionChanged: '1.22'
|
1351
1365
|
EnforcedStyle: no_space
|
1352
1366
|
SupportedStyles:
|
1353
1367
|
- space
|
1368
|
+
- compact
|
1354
1369
|
- no_space
|
1355
1370
|
|
1356
1371
|
Layout/SpaceInsidePercentLiteralDelimiters:
|
@@ -1434,6 +1449,13 @@ Lint/AmbiguousOperator:
|
|
1434
1449
|
VersionAdded: '0.17'
|
1435
1450
|
VersionChanged: '0.83'
|
1436
1451
|
|
1452
|
+
Lint/AmbiguousOperatorPrecedence:
|
1453
|
+
Description: >-
|
1454
|
+
Checks for expressions containing multiple binary operations with
|
1455
|
+
ambiguous precedence.
|
1456
|
+
Enabled: pending
|
1457
|
+
VersionAdded: '1.21'
|
1458
|
+
|
1437
1459
|
Lint/AmbiguousRange:
|
1438
1460
|
Description: Checks for ranges with ambiguous boundaries.
|
1439
1461
|
Enabled: pending
|
@@ -1471,9 +1493,9 @@ Lint/BinaryOperatorWithIdenticalOperands:
|
|
1471
1493
|
Lint/BooleanSymbol:
|
1472
1494
|
Description: 'Check for `:true` and `:false` symbols.'
|
1473
1495
|
Enabled: true
|
1474
|
-
|
1496
|
+
SafeAutoCorrect: false
|
1475
1497
|
VersionAdded: '0.50'
|
1476
|
-
VersionChanged: '
|
1498
|
+
VersionChanged: '1.22'
|
1477
1499
|
|
1478
1500
|
Lint/CircularArgumentReference:
|
1479
1501
|
Description: "Default values in optional keyword arguments and optional ordinal arguments should not refer back to the name of the argument."
|
@@ -1519,6 +1541,11 @@ Lint/Debugger:
|
|
1519
1541
|
Capybara:
|
1520
1542
|
- save_and_open_page
|
1521
1543
|
- save_and_open_screenshot
|
1544
|
+
debug.rb:
|
1545
|
+
- binding.b
|
1546
|
+
- binding.break
|
1547
|
+
- Kernel.binding.b
|
1548
|
+
- Kernel.binding.break
|
1522
1549
|
Pry:
|
1523
1550
|
- binding.pry
|
1524
1551
|
- binding.remote_pry
|
@@ -1527,6 +1554,8 @@ Lint/Debugger:
|
|
1527
1554
|
Rails:
|
1528
1555
|
- debugger
|
1529
1556
|
- Kernel.debugger
|
1557
|
+
RubyJard:
|
1558
|
+
- jard
|
1530
1559
|
WebConsole:
|
1531
1560
|
- binding.console
|
1532
1561
|
|
@@ -1750,6 +1779,11 @@ Lint/ImplicitStringConcatenation:
|
|
1750
1779
|
Enabled: true
|
1751
1780
|
VersionAdded: '0.36'
|
1752
1781
|
|
1782
|
+
Lint/IncompatibleIoSelectWithFiberScheduler:
|
1783
|
+
Description: 'Checks for `IO.select` that is incompatible with Fiber Scheduler.'
|
1784
|
+
Enabled: pending
|
1785
|
+
VersionAdded: '1.21'
|
1786
|
+
|
1753
1787
|
Lint/IneffectiveAccessModifier:
|
1754
1788
|
Description: >-
|
1755
1789
|
Checks for attempts to use `private` or `protected` to set
|
@@ -2013,6 +2047,11 @@ Lint/RequireParentheses:
|
|
2013
2047
|
Enabled: true
|
2014
2048
|
VersionAdded: '0.18'
|
2015
2049
|
|
2050
|
+
Lint/RequireRelativeSelfPath:
|
2051
|
+
Description: 'Checks for uses a file requiring itself with `require_relative`.'
|
2052
|
+
Enabled: pending
|
2053
|
+
VersionAdded: '1.22'
|
2054
|
+
|
2016
2055
|
Lint/RescueException:
|
2017
2056
|
Description: 'Avoid rescuing the Exception class.'
|
2018
2057
|
StyleGuide: '#no-blind-rescues'
|
@@ -2542,8 +2581,9 @@ Naming/HeredocDelimiterNaming:
|
|
2542
2581
|
|
2543
2582
|
Naming/InclusiveLanguage:
|
2544
2583
|
Description: 'Recommend the use of inclusive language instead of problematic terms.'
|
2545
|
-
Enabled:
|
2584
|
+
Enabled: false
|
2546
2585
|
VersionAdded: '1.18'
|
2586
|
+
VersionChanged: '1.21'
|
2547
2587
|
CheckIdentifiers: true
|
2548
2588
|
CheckConstants: true
|
2549
2589
|
CheckVariables: true
|
@@ -2699,6 +2739,14 @@ Security/Eval:
|
|
2699
2739
|
Enabled: true
|
2700
2740
|
VersionAdded: '0.47'
|
2701
2741
|
|
2742
|
+
Security/IoMethods:
|
2743
|
+
Description: >-
|
2744
|
+
Checks for the first argument to `IO.read`, `IO.binread`, `IO.write`, `IO.binwrite`,
|
2745
|
+
`IO.foreach`, and `IO.readlines`.
|
2746
|
+
Enabled: pending
|
2747
|
+
Safe: false
|
2748
|
+
VersionAdded: '1.22'
|
2749
|
+
|
2702
2750
|
Security/JSONLoad:
|
2703
2751
|
Description: >-
|
2704
2752
|
Prefer usage of `JSON.parse` over `JSON.load` due to potential
|
@@ -2775,8 +2823,9 @@ Style/AndOr:
|
|
2775
2823
|
Description: 'Use &&/|| instead of and/or.'
|
2776
2824
|
StyleGuide: '#no-and-or-or'
|
2777
2825
|
Enabled: true
|
2826
|
+
SafeAutoCorrect: false
|
2778
2827
|
VersionAdded: '0.9'
|
2779
|
-
VersionChanged: '
|
2828
|
+
VersionChanged: '1.21'
|
2780
2829
|
# Whether `and` and `or` are banned only in conditionals (conditionals)
|
2781
2830
|
# or completely (always).
|
2782
2831
|
EnforcedStyle: conditionals
|
@@ -2810,9 +2859,9 @@ Style/ArrayJoin:
|
|
2810
2859
|
Style/AsciiComments:
|
2811
2860
|
Description: 'Use only ascii symbols in comments.'
|
2812
2861
|
StyleGuide: '#english-comments'
|
2813
|
-
Enabled:
|
2862
|
+
Enabled: false
|
2814
2863
|
VersionAdded: '0.9'
|
2815
|
-
VersionChanged: '
|
2864
|
+
VersionChanged: '1.21'
|
2816
2865
|
AllowedChars:
|
2817
2866
|
- ©
|
2818
2867
|
|
@@ -2974,7 +3023,7 @@ Style/CaseEquality:
|
|
2974
3023
|
Enabled: true
|
2975
3024
|
VersionAdded: '0.9'
|
2976
3025
|
VersionChanged: '0.89'
|
2977
|
-
# If AllowOnConstant is enabled, the cop will ignore violations when the receiver of
|
3026
|
+
# If `AllowOnConstant` option is enabled, the cop will ignore violations when the receiver of
|
2978
3027
|
# the case equality operator is a constant.
|
2979
3028
|
#
|
2980
3029
|
# # bad
|
@@ -3149,7 +3198,7 @@ Style/CommentAnnotation:
|
|
3149
3198
|
StyleGuide: '#annotate-keywords'
|
3150
3199
|
Enabled: true
|
3151
3200
|
VersionAdded: '0.10'
|
3152
|
-
VersionChanged: '1.
|
3201
|
+
VersionChanged: '1.20'
|
3153
3202
|
Keywords:
|
3154
3203
|
- TODO
|
3155
3204
|
- FIXME
|
@@ -3669,7 +3718,7 @@ Style/InPatternThen:
|
|
3669
3718
|
Style/InfiniteLoop:
|
3670
3719
|
Description: >-
|
3671
3720
|
Use Kernel#loop for infinite loops.
|
3672
|
-
This cop is unsafe
|
3721
|
+
This cop is unsafe if the body may raise a `StopIteration` exception.
|
3673
3722
|
Safe: false
|
3674
3723
|
StyleGuide: '#infinite-loop'
|
3675
3724
|
Enabled: true
|
@@ -4095,6 +4144,21 @@ Style/Not:
|
|
4095
4144
|
VersionAdded: '0.9'
|
4096
4145
|
VersionChanged: '0.20'
|
4097
4146
|
|
4147
|
+
Style/NumberedParameters:
|
4148
|
+
Description: 'Restrict the usage of numbered parameters.'
|
4149
|
+
Enabled: pending
|
4150
|
+
VersionAdded: '1.22'
|
4151
|
+
EnforcedStyle: allow_single_line
|
4152
|
+
SupportedStyles:
|
4153
|
+
- allow_single_line
|
4154
|
+
- disallow
|
4155
|
+
|
4156
|
+
Style/NumberedParametersLimit:
|
4157
|
+
Description: 'Avoid excessive numbered params in a single block.'
|
4158
|
+
Enabled: pending
|
4159
|
+
VersionAdded: '1.22'
|
4160
|
+
Max: 1
|
4161
|
+
|
4098
4162
|
Style/NumericLiteralPrefix:
|
4099
4163
|
Description: 'Use smallcase prefixes for numeric literals.'
|
4100
4164
|
StyleGuide: '#numeric-literal-prefixes'
|
@@ -4105,7 +4169,6 @@ Style/NumericLiteralPrefix:
|
|
4105
4169
|
- zero_with_o
|
4106
4170
|
- zero_only
|
4107
4171
|
|
4108
|
-
|
4109
4172
|
Style/NumericLiterals:
|
4110
4173
|
Description: >-
|
4111
4174
|
Add underscores to large numeric literals to improve their
|
@@ -4426,6 +4489,8 @@ Style/RedundantSort:
|
|
4426
4489
|
`max_by` instead of `sort_by...last`, etc.
|
4427
4490
|
Enabled: true
|
4428
4491
|
VersionAdded: '0.76'
|
4492
|
+
VersionChanged: '1.22'
|
4493
|
+
Safe: false
|
4429
4494
|
|
4430
4495
|
Style/RedundantSortBy:
|
4431
4496
|
Description: 'Use `sort` instead of `sort_by { |x| x }`.'
|
@@ -4506,6 +4571,12 @@ Style/Sample:
|
|
4506
4571
|
Enabled: true
|
4507
4572
|
VersionAdded: '0.30'
|
4508
4573
|
|
4574
|
+
Style/SelectByRegexp:
|
4575
|
+
Description: 'Prefer grep/grep_v to select/reject with a regexp match.'
|
4576
|
+
Enabled: pending
|
4577
|
+
SafeAutoCorrect: false
|
4578
|
+
VersionAdded: '1.22'
|
4579
|
+
|
4509
4580
|
Style/SelfAssignment:
|
4510
4581
|
Description: >-
|
4511
4582
|
Checks for places where self-assignment shorthand should have
|
@@ -4692,8 +4763,9 @@ Style/StructInheritance:
|
|
4692
4763
|
Description: 'Checks for inheritance from Struct.new.'
|
4693
4764
|
StyleGuide: '#no-extend-struct-new'
|
4694
4765
|
Enabled: true
|
4766
|
+
SafeAutoCorrect: false
|
4695
4767
|
VersionAdded: '0.29'
|
4696
|
-
VersionChanged: '
|
4768
|
+
VersionChanged: '1.20'
|
4697
4769
|
|
4698
4770
|
Style/SwapValues:
|
4699
4771
|
Description: 'This cop enforces the use of shorthand-style swapping of 2 variables.'
|
data/lib/rubocop/config.rb
CHANGED
@@ -51,6 +51,11 @@ module RuboCop
|
|
51
51
|
self
|
52
52
|
end
|
53
53
|
|
54
|
+
def validate_after_resolution
|
55
|
+
@validator.validate_after_resolution
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
54
59
|
def_delegators :@hash, :[], :[]=, :delete, :dig, :each, :key?, :keys, :each_key,
|
55
60
|
:fetch, :map, :merge, :replace, :to_h, :to_hash, :transform_values
|
56
61
|
def_delegators :@validator, :validate, :target_ruby_version
|
@@ -101,6 +101,8 @@ module RuboCop
|
|
101
101
|
return default_configuration if config_file == DEFAULT_FILE
|
102
102
|
|
103
103
|
config = load_file(config_file, check: check)
|
104
|
+
config.validate_after_resolution if check
|
105
|
+
|
104
106
|
if ignore_parent_exclusion?
|
105
107
|
print 'Ignoring AllCops/Exclude from parent folders' if debug?
|
106
108
|
else
|
@@ -143,7 +145,7 @@ module RuboCop
|
|
143
145
|
PENDING_BANNER = <<~BANNER
|
144
146
|
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
|
145
147
|
|
146
|
-
Please also note that can
|
148
|
+
Please also note that you can opt-in to new cops by default by adding this to your config:
|
147
149
|
AllCops:
|
148
150
|
NewCops: enable
|
149
151
|
BANNER
|
@@ -161,7 +163,7 @@ module RuboCop
|
|
161
163
|
def warn_pending_cop(cop)
|
162
164
|
version = cop.metadata['VersionAdded'] || 'N/A'
|
163
165
|
|
164
|
-
warn Rainbow("#{cop.name}: #
|
166
|
+
warn Rainbow("#{cop.name}: # new in #{version}").yellow
|
165
167
|
warn Rainbow(' Enabled: true').yellow
|
166
168
|
end
|
167
169
|
|
@@ -44,7 +44,6 @@ module RuboCop
|
|
44
44
|
check_obsoletions
|
45
45
|
|
46
46
|
alert_about_unrecognized_cops(invalid_cop_names)
|
47
|
-
check_target_ruby
|
48
47
|
validate_new_cops_parameter
|
49
48
|
validate_parameter_names(valid_cop_names)
|
50
49
|
validate_enforced_styles(valid_cop_names)
|
@@ -52,6 +51,15 @@ module RuboCop
|
|
52
51
|
reject_mutually_exclusive_defaults
|
53
52
|
end
|
54
53
|
|
54
|
+
# Validations that should only be run after all config resolving has
|
55
|
+
# taken place:
|
56
|
+
# * The target ruby version is only checked once the entire inheritance
|
57
|
+
# chain has been loaded so that only the final value is validated, and
|
58
|
+
# any obsolete but overridden values are ignored.
|
59
|
+
def validate_after_resolution
|
60
|
+
check_target_ruby
|
61
|
+
end
|
62
|
+
|
55
63
|
def target_ruby_version
|
56
64
|
target_ruby.version
|
57
65
|
end
|
data/lib/rubocop/cop/base.rb
CHANGED
@@ -24,7 +24,7 @@ module RuboCop
|
|
24
24
|
# `add_global_offense`. Use the `processed_source` method to
|
25
25
|
# get the currently processed source being investigated.
|
26
26
|
#
|
27
|
-
# In case of invalid syntax /
|
27
|
+
# In case of invalid syntax / unparsable content,
|
28
28
|
# the callback `on_other_file` is called instead of all the other
|
29
29
|
# `on_...` callbacks.
|
30
30
|
#
|
@@ -222,8 +222,8 @@ module RuboCop
|
|
222
222
|
|
223
223
|
def relevant_file?(file)
|
224
224
|
file == RuboCop::AST::ProcessedSource::STRING_SOURCE_NAME ||
|
225
|
-
file_name_matches_any?(file, 'Include', true) &&
|
226
|
-
!file_name_matches_any?(file, 'Exclude', false)
|
225
|
+
(file_name_matches_any?(file, 'Include', true) &&
|
226
|
+
!file_name_matches_any?(file, 'Exclude', false))
|
227
227
|
end
|
228
228
|
|
229
229
|
def excluded_file?(file)
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Bundler
|
6
|
+
# This cop verifies that a project contains Gemfile or gems.rb file and correct
|
7
|
+
# associated lock file based on the configuration.
|
8
|
+
#
|
9
|
+
# @example EnforcedStyle: Gemfile (default)
|
10
|
+
# # bad
|
11
|
+
# Project contains gems.rb and gems.locked files
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# Project contains Gemfile and gems.locked file
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# Project contains Gemfile and Gemfile.lock
|
18
|
+
#
|
19
|
+
# @example EnforcedStyle: gems.rb
|
20
|
+
# # bad
|
21
|
+
# Project contains Gemfile and Gemfile.lock files
|
22
|
+
#
|
23
|
+
# # bad
|
24
|
+
# Project contains gems.rb and Gemfile.lock file
|
25
|
+
#
|
26
|
+
# # good
|
27
|
+
# Project contains gems.rb and gems.locked files
|
28
|
+
class GemFilename < Base
|
29
|
+
include ConfigurableEnforcedStyle
|
30
|
+
include RangeHelp
|
31
|
+
|
32
|
+
MSG_GEMFILE_REQUIRED = '`gems.rb` file was found but `Gemfile` is required '\
|
33
|
+
'(file path: %<file_path>s).'
|
34
|
+
MSG_GEMS_RB_REQUIRED = '`Gemfile` was found but `gems.rb` file is required '\
|
35
|
+
'(file path: %<file_path>s).'
|
36
|
+
MSG_GEMFILE_MISMATCHED = 'Expected a `Gemfile.lock` with `Gemfile` but found '\
|
37
|
+
'`gems.locked` file (file path: %<file_path>s).'
|
38
|
+
MSG_GEMS_RB_MISMATCHED = 'Expected a `gems.locked` file with `gems.rb` but found '\
|
39
|
+
'`Gemfile.lock` (file path: %<file_path>s).'
|
40
|
+
GEMFILE_FILES = %w[Gemfile Gemfile.lock].freeze
|
41
|
+
GEMS_RB_FILES = %w[gems.rb gems.locked].freeze
|
42
|
+
|
43
|
+
def on_new_investigation
|
44
|
+
file_path = processed_source.file_path
|
45
|
+
basename = File.basename(file_path)
|
46
|
+
return if expected_gemfile?(basename)
|
47
|
+
|
48
|
+
register_offense(file_path, basename)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def register_offense(file_path, basename)
|
54
|
+
register_gemfile_offense(file_path, basename) if gemfile_offense?(basename)
|
55
|
+
register_gems_rb_offense(file_path, basename) if gems_rb_offense?(basename)
|
56
|
+
end
|
57
|
+
|
58
|
+
def register_gemfile_offense(file_path, basename)
|
59
|
+
message = case basename
|
60
|
+
when 'gems.rb'
|
61
|
+
MSG_GEMFILE_REQUIRED
|
62
|
+
when 'gems.locked'
|
63
|
+
MSG_GEMFILE_MISMATCHED
|
64
|
+
end
|
65
|
+
|
66
|
+
add_global_offense(format(message, file_path: file_path))
|
67
|
+
end
|
68
|
+
|
69
|
+
def register_gems_rb_offense(file_path, basename)
|
70
|
+
message = case basename
|
71
|
+
when 'Gemfile'
|
72
|
+
MSG_GEMS_RB_REQUIRED
|
73
|
+
when 'Gemfile.lock'
|
74
|
+
MSG_GEMS_RB_MISMATCHED
|
75
|
+
end
|
76
|
+
|
77
|
+
add_global_offense(format(message, file_path: file_path))
|
78
|
+
end
|
79
|
+
|
80
|
+
def gemfile_offense?(basename)
|
81
|
+
gemfile_required? && GEMS_RB_FILES.include?(basename)
|
82
|
+
end
|
83
|
+
|
84
|
+
def gems_rb_offense?(basename)
|
85
|
+
gems_rb_required? && GEMFILE_FILES.include?(basename)
|
86
|
+
end
|
87
|
+
|
88
|
+
def expected_gemfile?(basename)
|
89
|
+
(gemfile_required? && GEMFILE_FILES.include?(basename)) ||
|
90
|
+
(gems_rb_required? && GEMS_RB_FILES.include?(basename))
|
91
|
+
end
|
92
|
+
|
93
|
+
def gemfile_required?
|
94
|
+
style == :Gemfile
|
95
|
+
end
|
96
|
+
|
97
|
+
def gems_rb_required?
|
98
|
+
style == :'gems.rb'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -3,18 +3,21 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Bundler
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# 'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
|
6
|
+
# Passing symbol arguments to `source` (e.g. `source :rubygems`) is
|
7
|
+
# deprecated because they default to using HTTP requests. Instead, specify
|
8
|
+
# `'https://rubygems.org'` if possible, or `'http://rubygems.org'` if not.
|
9
9
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# most use cases HTTPS will be fine.
|
10
|
+
# When autocorrecting, this cop will replace symbol arguments with
|
11
|
+
# `'https://rubygems.org'`.
|
13
12
|
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
13
|
+
# This cop will not replace existing sources that use `http://`. This may
|
14
|
+
# be necessary where HTTPS is not available. For example, where using an
|
15
|
+
# internal gem server via an intranet, or where HTTPS is prohibited.
|
16
|
+
# However, you should strongly prefer `https://` where possible, as it is
|
17
|
+
# more secure.
|
18
|
+
#
|
19
|
+
# If you don't allow `http://`, please set `false` to `AllowHttpProtocol`.
|
20
|
+
# This option is `true` by default for safe autocorrection.
|
18
21
|
#
|
19
22
|
# @example
|
20
23
|
# # bad
|
@@ -24,7 +27,17 @@ module RuboCop
|
|
24
27
|
#
|
25
28
|
# # good
|
26
29
|
# source 'https://rubygems.org' # strongly recommended
|
30
|
+
#
|
31
|
+
# @example AllowHttpProtocol: true (default)
|
32
|
+
#
|
33
|
+
# # good
|
34
|
+
# source 'http://rubygems.org' # use only if HTTPS is unavailable
|
35
|
+
#
|
36
|
+
# @example AllowHttpProtocol: false
|
37
|
+
#
|
38
|
+
# # bad
|
27
39
|
# source 'http://rubygems.org'
|
40
|
+
#
|
28
41
|
class InsecureProtocolSource < Base
|
29
42
|
include RangeHelp
|
30
43
|
extend AutoCorrector
|
@@ -33,29 +46,40 @@ module RuboCop
|
|
33
46
|
'are insecure. ' \
|
34
47
|
"Please change your source to 'https://rubygems.org' " \
|
35
48
|
"if possible, or 'http://rubygems.org' if not."
|
49
|
+
MSG_HTTP_PROTOCOL = 'Use `https://rubygems.org` instead of `http://rubygems.org`.'
|
36
50
|
|
37
51
|
RESTRICT_ON_SEND = %i[source].freeze
|
38
52
|
|
39
53
|
# @!method insecure_protocol_source?(node)
|
40
54
|
def_node_matcher :insecure_protocol_source?, <<~PATTERN
|
41
55
|
(send nil? :source
|
42
|
-
$(sym
|
56
|
+
${(sym :gemcutter) (sym :rubygems) (sym :rubyforge) (:str "http://rubygems.org")})
|
43
57
|
PATTERN
|
44
58
|
|
45
59
|
def on_send(node)
|
46
|
-
insecure_protocol_source?(node) do |source_node
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
60
|
+
insecure_protocol_source?(node) do |source_node|
|
61
|
+
source = source_node.value
|
62
|
+
use_http_protocol = source == 'http://rubygems.org'
|
63
|
+
|
64
|
+
return if allow_http_protocol? && use_http_protocol
|
65
|
+
|
66
|
+
message = if use_http_protocol
|
67
|
+
MSG_HTTP_PROTOCOL
|
68
|
+
else
|
69
|
+
format(MSG, source: source)
|
70
|
+
end
|
71
|
+
|
72
|
+
add_offense(source_node, message: message) do |corrector|
|
73
|
+
corrector.replace(source_node, "'https://rubygems.org'")
|
56
74
|
end
|
57
75
|
end
|
58
76
|
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def allow_http_protocol?
|
81
|
+
cop_config.fetch('AllowHttpProtocol', true)
|
82
|
+
end
|
59
83
|
end
|
60
84
|
end
|
61
85
|
end
|
@@ -24,15 +24,15 @@ module RuboCop
|
|
24
24
|
# gem 'rubocop'
|
25
25
|
# # For tests
|
26
26
|
# gem 'rspec'
|
27
|
-
class OrderedGems <
|
28
|
-
|
27
|
+
class OrderedGems < Base
|
28
|
+
extend AutoCorrector
|
29
29
|
include OrderedGemNode
|
30
30
|
|
31
31
|
MSG = 'Gems should be sorted in an alphabetical order within their '\
|
32
32
|
'section of the Gemfile. '\
|
33
33
|
'Gem `%<previous>s` should appear before `%<current>s`.'
|
34
34
|
|
35
|
-
def
|
35
|
+
def on_new_investigation
|
36
36
|
return if processed_source.blank?
|
37
37
|
|
38
38
|
gem_declarations(processed_source.ast)
|
@@ -44,15 +44,6 @@ module RuboCop
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def autocorrect(node)
|
48
|
-
OrderedGemCorrector.correct(
|
49
|
-
processed_source,
|
50
|
-
node,
|
51
|
-
previous_declaration(node),
|
52
|
-
treat_comments_as_separators
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
47
|
private
|
57
48
|
|
58
49
|
def previous_declaration(node)
|
@@ -87,8 +87,8 @@ module RuboCop
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def needs_separating_space?
|
90
|
-
block_begin.begin_pos == arguments_end_pos &&
|
91
|
-
selector_end.end_pos == arguments_begin_pos ||
|
90
|
+
(block_begin.begin_pos == arguments_end_pos &&
|
91
|
+
selector_end.end_pos == arguments_begin_pos) ||
|
92
92
|
block_begin.begin_pos == selector_end.end_pos
|
93
93
|
end
|
94
94
|
|
@@ -4,9 +4,10 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
# This auto-corrects gem dependency order
|
6
6
|
class OrderedGemCorrector
|
7
|
-
extend OrderedGemNode
|
8
|
-
|
9
7
|
class << self
|
8
|
+
include OrderedGemNode
|
9
|
+
include RangeHelp
|
10
|
+
|
10
11
|
attr_reader :processed_source, :comments_as_separators
|
11
12
|
|
12
13
|
def correct(processed_source, node,
|
@@ -17,24 +18,24 @@ module RuboCop
|
|
17
18
|
current_range = declaration_with_comment(node)
|
18
19
|
previous_range = declaration_with_comment(previous_declaration)
|
19
20
|
|
20
|
-
->(corrector)
|
21
|
+
->(corrector) { swap_range(corrector, current_range, previous_range) }
|
21
22
|
end
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
26
|
def declaration_with_comment(node)
|
26
27
|
buffer = processed_source.buffer
|
27
|
-
begin_pos = get_source_range(node, comments_as_separators).begin_pos
|
28
|
+
begin_pos = range_by_whole_lines(get_source_range(node, comments_as_separators)).begin_pos
|
28
29
|
end_line = buffer.line_for_position(node.loc.expression.end_pos)
|
29
|
-
end_pos = buffer.line_range(end_line)
|
30
|
-
|
30
|
+
end_pos = range_by_whole_lines(buffer.line_range(end_line),
|
31
|
+
include_final_newline: true).end_pos
|
32
|
+
|
33
|
+
range_between(begin_pos, end_pos)
|
31
34
|
end
|
32
35
|
|
33
36
|
def swap_range(corrector, range1, range2)
|
34
|
-
|
35
|
-
|
36
|
-
corrector.replace(range1, src2)
|
37
|
-
corrector.replace(range2, src1)
|
37
|
+
corrector.insert_before(range2, range1.source)
|
38
|
+
corrector.remove(range1)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|