rubocop 1.10.0 → 1.11.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 +12 -12
- data/assets/output.html.erb +1 -1
- data/config/default.yml +13 -0
- data/lib/rubocop.rb +1 -0
- data/lib/rubocop/cli/command/execute_runner.rb +1 -1
- data/lib/rubocop/cli/command/suggest_extensions.rb +1 -1
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -0
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -0
- data/lib/rubocop/cop/gemspec/date_assignment.rb +1 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -0
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -0
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +2 -0
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +2 -0
- data/lib/rubocop/cop/generator.rb +2 -2
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +2 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +151 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +2 -0
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +3 -0
- data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +4 -0
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +1 -0
- data/lib/rubocop/cop/layout/extra_spacing.rb +2 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -0
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +2 -0
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -0
- data/lib/rubocop/cop/lint/debugger.rb +3 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -0
- data/lib/rubocop/cop/lint/duplicate_branch.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -0
- data/lib/rubocop/cop/lint/duplicate_require.rb +1 -0
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -0
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -0
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +1 -0
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -0
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -0
- data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -0
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -0
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +7 -0
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -0
- data/lib/rubocop/cop/lint/number_conversion.rb +2 -0
- data/lib/rubocop/cop/lint/raise_exception.rb +2 -0
- data/lib/rubocop/cop/lint/rand_one.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -0
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -0
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -0
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -0
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -0
- data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +3 -0
- data/lib/rubocop/cop/lint/unified_integer.rb +1 -0
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +5 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -0
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -0
- data/lib/rubocop/cop/lint/useless_times.rb +3 -0
- data/lib/rubocop/cop/metrics/module_length.rb +1 -0
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -0
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +6 -4
- data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +2 -0
- data/lib/rubocop/cop/mixin/def_node.rb +1 -0
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -0
- data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -0
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -0
- data/lib/rubocop/cop/mixin/negative_conditional.rb +3 -0
- data/lib/rubocop/cop/mixin/preferred_delimiters.rb +1 -1
- data/lib/rubocop/cop/mixin/rational_literal.rb +1 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +5 -0
- data/lib/rubocop/cop/mixin/visibility_help.rb +1 -0
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -0
- data/lib/rubocop/cop/naming/constant_name.rb +2 -0
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -0
- data/lib/rubocop/cop/naming/method_name.rb +3 -0
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -0
- data/lib/rubocop/cop/security/eval.rb +1 -0
- data/lib/rubocop/cop/security/json_load.rb +1 -0
- data/lib/rubocop/cop/security/marshal_load.rb +1 -0
- data/lib/rubocop/cop/security/open.rb +1 -0
- data/lib/rubocop/cop/security/yaml_load.rb +1 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -0
- data/lib/rubocop/cop/style/alias.rb +1 -0
- data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -0
- data/lib/rubocop/cop/style/array_coercion.rb +2 -0
- data/lib/rubocop/cop/style/array_join.rb +1 -0
- data/lib/rubocop/cop/style/attr.rb +1 -0
- data/lib/rubocop/cop/style/case_equality.rb +2 -1
- data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -0
- data/lib/rubocop/cop/style/collection_compact.rb +2 -0
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -0
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -0
- data/lib/rubocop/cop/style/constant_visibility.rb +1 -0
- data/lib/rubocop/cop/style/date_time.rb +3 -0
- data/lib/rubocop/cop/style/dir.rb +1 -0
- data/lib/rubocop/cop/style/documentation.rb +5 -0
- data/lib/rubocop/cop/style/documentation_method.rb +1 -0
- data/lib/rubocop/cop/style/double_negation.rb +1 -0
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -0
- data/lib/rubocop/cop/style/each_with_object.rb +1 -0
- data/lib/rubocop/cop/style/empty_literal.rb +9 -0
- data/lib/rubocop/cop/style/endless_method.rb +1 -0
- data/lib/rubocop/cop/style/eval_with_location.rb +2 -0
- data/lib/rubocop/cop/style/even_odd.rb +1 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -0
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -0
- data/lib/rubocop/cop/style/float_division.rb +4 -0
- data/lib/rubocop/cop/style/format_string.rb +2 -0
- data/lib/rubocop/cop/style/format_string_token.rb +1 -0
- data/lib/rubocop/cop/style/global_std_stream.rb +1 -0
- data/lib/rubocop/cop/style/hash_conversion.rb +26 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +1 -0
- data/lib/rubocop/cop/style/hash_except.rb +1 -0
- data/lib/rubocop/cop/style/hash_like_case.rb +1 -0
- data/lib/rubocop/cop/style/hash_transform_keys.rb +4 -0
- data/lib/rubocop/cop/style/hash_transform_values.rb +4 -0
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +2 -0
- data/lib/rubocop/cop/style/min_max.rb +1 -0
- data/lib/rubocop/cop/style/mixin_usage.rb +2 -0
- data/lib/rubocop/cop/style/module_function.rb +5 -0
- data/lib/rubocop/cop/style/multiple_comparison.rb +21 -2
- data/lib/rubocop/cop/style/mutable_constant.rb +3 -0
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +3 -0
- data/lib/rubocop/cop/style/nil_lambda.rb +1 -0
- data/lib/rubocop/cop/style/non_nil_check.rb +7 -0
- data/lib/rubocop/cop/style/numeric_predicate.rb +3 -0
- data/lib/rubocop/cop/style/option_hash.rb +1 -0
- data/lib/rubocop/cop/style/or_assignment.rb +2 -0
- data/lib/rubocop/cop/style/parallel_assignment.rb +6 -0
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -0
- data/lib/rubocop/cop/style/proc.rb +1 -0
- data/lib/rubocop/cop/style/random_with_offset.rb +5 -0
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +7 -1
- data/lib/rubocop/cop/style/redundant_conditional.rb +2 -0
- data/lib/rubocop/cop/style/redundant_exception.rb +2 -0
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +2 -0
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +13 -0
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -0
- data/lib/rubocop/cop/style/redundant_sort.rb +1 -0
- data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -0
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -0
- data/lib/rubocop/cop/style/return_nil.rb +6 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -0
- data/lib/rubocop/cop/style/sample.rb +1 -0
- data/lib/rubocop/cop/style/signal_exception.rb +3 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -0
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +1 -0
- data/lib/rubocop/cop/style/string_hash_keys.rb +2 -0
- data/lib/rubocop/cop/style/strip.rb +1 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +1 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +25 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -0
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -0
- data/lib/rubocop/cop/style/unless_logical_operators.rb +99 -0
- data/lib/rubocop/cop/style/unpack_first.rb +1 -0
- data/lib/rubocop/cop/style/yoda_condition.rb +1 -0
- data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -0
- data/lib/rubocop/name_similarity.rb +1 -1
- data/lib/rubocop/target_ruby.rb +21 -13
- data/lib/rubocop/version.rb +1 -1
- 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: dac7fff2f013c47a104cadfc9ca1a02a9f0996c13da30cf53c96f9c427f528bf
|
4
|
+
data.tar.gz: 55120478bfcd4ff14e326c6be7af570852b226ad27a02e9b2835ddda7d8e4324
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b47ab24450c94098487e2efcaf3c6c45314e07523ca7272356908792f06689f95ab4032eed06f9a55a1f68ad75432c599f6bbcec83b5a3ce3e611dab9e2f608
|
7
|
+
data.tar.gz: 1ba4a1fef00d332d644f242d97954cad9ad4cbcb2cf7cad1d2a2bec48540a2ae12d895a107283aac1933dd34230a45b02cb0470290f0c502bae2c5d3e762662f
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
<p align="center">
|
2
|
-
<img src="https://raw.githubusercontent.com/rubocop
|
2
|
+
<img src="https://raw.githubusercontent.com/rubocop/rubocop/master/logo/rubo-logo-horizontal.png" alt="RuboCop Logo"/>
|
3
3
|
</p>
|
4
4
|
|
5
5
|
----------
|
6
|
-
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop
|
6
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
|
7
7
|
[![Gem Version](https://badge.fury.io/rb/rubocop.svg)](https://badge.fury.io/rb/rubocop)
|
8
|
-
[![CircleCI Status](https://circleci.com/gh/rubocop
|
9
|
-
[![Actions Status](https://github.com/rubocop
|
10
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/test_coverage)](https://codeclimate.com/github/rubocop
|
11
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/maintainability)](https://codeclimate.com/github/rubocop
|
8
|
+
[![CircleCI Status](https://circleci.com/gh/rubocop/rubocop/tree/master.svg?style=svg)](https://circleci.com/gh/rubocop/rubocop/tree/master)
|
9
|
+
[![Actions Status](https://github.com/rubocop/rubocop/workflows/CI/badge.svg?branch=master)](https://github.com/rubocop/rubocop/actions?query=workflow%3ACI)
|
10
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/test_coverage)](https://codeclimate.com/github/rubocop/rubocop/test_coverage)
|
11
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/maintainability)](https://codeclimate.com/github/rubocop/rubocop/maintainability)
|
12
12
|
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=rubocop&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=rubocop&package-manager=bundler&version-scheme=semver)
|
13
13
|
|
14
14
|
> Role models are important. <br/>
|
@@ -20,7 +20,7 @@ Guide](https://rubystyle.guide). Apart from reporting the problems discovered in
|
|
20
20
|
RuboCop can also automatically fix many of them for you.
|
21
21
|
|
22
22
|
RuboCop is extremely flexible and most aspects of its behavior can be tweaked via various
|
23
|
-
[configuration options](https://github.com/rubocop
|
23
|
+
[configuration options](https://github.com/rubocop/rubocop/blob/master/config/default.yml).
|
24
24
|
|
25
25
|
----------
|
26
26
|
[![Patreon](https://img.shields.io/badge/patreon-donate-orange.svg)](https://www.patreon.com/bbatsov)
|
@@ -51,7 +51,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
|
|
51
51
|
in your `Gemfile`:
|
52
52
|
|
53
53
|
```rb
|
54
|
-
gem 'rubocop', '~> 1.
|
54
|
+
gem 'rubocop', '~> 1.11', require: false
|
55
55
|
```
|
56
56
|
|
57
57
|
See [versioning](https://docs.rubocop.org/rubocop/1.0/versioning.html) for further details.
|
@@ -82,7 +82,7 @@ See the [compatibility documentation](https://docs.rubocop.org/rubocop/compatibi
|
|
82
82
|
|
83
83
|
If you use RuboCop in your project, you can include one of these badges in your readme to let people know that your code is written following the community Ruby Style Guide.
|
84
84
|
|
85
|
-
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop
|
85
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
|
86
86
|
|
87
87
|
[![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)
|
88
88
|
|
@@ -90,7 +90,7 @@ If you use RuboCop in your project, you can include one of these badges in your
|
|
90
90
|
Here are the Markdown snippets for the two badges:
|
91
91
|
|
92
92
|
``` markdown
|
93
|
-
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop
|
93
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
|
94
94
|
|
95
95
|
[![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)
|
96
96
|
```
|
@@ -116,14 +116,14 @@ See the [team page](https://docs.rubocop.org/rubocop/about/team.html) for more d
|
|
116
116
|
## Logo
|
117
117
|
|
118
118
|
RuboCop's logo was created by [Dimiter Petrov](https://www.chadomoto.com/). You can find the logo in various
|
119
|
-
formats [here](https://github.com/rubocop
|
119
|
+
formats [here](https://github.com/rubocop/rubocop/tree/master/logo).
|
120
120
|
|
121
121
|
The logo is licensed under a
|
122
122
|
[Creative Commons Attribution-NonCommercial 4.0 International License](https://creativecommons.org/licenses/by-nc/4.0/deed.en_GB).
|
123
123
|
|
124
124
|
## Contributors
|
125
125
|
|
126
|
-
Here's a [list](https://github.com/rubocop
|
126
|
+
Here's a [list](https://github.com/rubocop/rubocop/graphs/contributors) of
|
127
127
|
all the people who have contributed to the development of RuboCop.
|
128
128
|
|
129
129
|
I'm extremely grateful to each and every one of them!
|
data/assets/output.html.erb
CHANGED
@@ -254,7 +254,7 @@
|
|
254
254
|
<% end %>
|
255
255
|
</div>
|
256
256
|
<footer>
|
257
|
-
Generated by <a href="https://github.com/rubocop
|
257
|
+
Generated by <a href="https://github.com/rubocop/rubocop">RuboCop</a>
|
258
258
|
<span class="version"><%= RuboCop::Version::STRING %></span>
|
259
259
|
</footer>
|
260
260
|
</body>
|
data/config/default.yml
CHANGED
@@ -3446,6 +3446,8 @@ Style/HashConversion:
|
|
3446
3446
|
Description: 'Avoid Hash[] in favor of ary.to_h or literal hashes.'
|
3447
3447
|
Enabled: pending
|
3448
3448
|
VersionAdded: '1.10'
|
3449
|
+
VersionChanged: '1.11'
|
3450
|
+
AllowSplatArgument: true
|
3449
3451
|
|
3450
3452
|
Style/HashEachMethods:
|
3451
3453
|
Description: 'Use Hash#each_key and Hash#each_value.'
|
@@ -4586,6 +4588,7 @@ Style/SymbolProc:
|
|
4586
4588
|
Safe: false
|
4587
4589
|
VersionAdded: '0.26'
|
4588
4590
|
VersionChanged: '1.5'
|
4591
|
+
AllowMethodsWithArguments: false
|
4589
4592
|
# A list of method names to be ignored by the check.
|
4590
4593
|
# The names should be fairly unique, otherwise you'll end up ignoring lots of code.
|
4591
4594
|
IgnoredMethods:
|
@@ -4738,6 +4741,16 @@ Style/UnlessElse:
|
|
4738
4741
|
Enabled: true
|
4739
4742
|
VersionAdded: '0.9'
|
4740
4743
|
|
4744
|
+
Style/UnlessLogicalOperators:
|
4745
|
+
Description: >-
|
4746
|
+
Checks for use of logical operators in an unless condition.
|
4747
|
+
Enabled: false
|
4748
|
+
VersionAdded: '1.11'
|
4749
|
+
EnforcedStyle: forbid_mixed_logical_operators
|
4750
|
+
SupportedStyles:
|
4751
|
+
- forbid_mixed_logical_operators
|
4752
|
+
- forbid_logical_operators
|
4753
|
+
|
4741
4754
|
Style/UnpackFirst:
|
4742
4755
|
Description: >-
|
4743
4756
|
Checks for accessing the first element of `String#unpack`
|
data/lib/rubocop.rb
CHANGED
@@ -605,6 +605,7 @@ require_relative 'rubocop/cop/style/trailing_method_end_statement'
|
|
605
605
|
require_relative 'rubocop/cop/style/trailing_underscore_variable'
|
606
606
|
require_relative 'rubocop/cop/style/trivial_accessors'
|
607
607
|
require_relative 'rubocop/cop/style/unless_else'
|
608
|
+
require_relative 'rubocop/cop/style/unless_logical_operators'
|
608
609
|
require_relative 'rubocop/cop/style/unpack_first'
|
609
610
|
require_relative 'rubocop/cop/style/variable_interpolation'
|
610
611
|
require_relative 'rubocop/cop/style/when_then'
|
@@ -86,7 +86,7 @@ module RuboCop
|
|
86
86
|
def maybe_print_corrected_source
|
87
87
|
# Integration tools (like RubyMine) expect to have only the JSON result
|
88
88
|
# when specifying JSON format. Similar HTML and JUnit are targeted as well.
|
89
|
-
# See: https://github.com/rubocop
|
89
|
+
# See: https://github.com/rubocop/rubocop/issues/8673
|
90
90
|
return if INTEGRATION_FORMATTERS.include?(@options[:format])
|
91
91
|
|
92
92
|
return unless @options[:stdin] && @options[:auto_correct]
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
22
22
|
'RuboCop extension libraries might be helpful:'
|
23
23
|
|
24
24
|
extensions.sort.each do |extension|
|
25
|
-
puts " * #{extension} (http://github.com/rubocop
|
25
|
+
puts " * #{extension} (http://github.com/rubocop/#{extension})"
|
26
26
|
end
|
27
27
|
|
28
28
|
puts
|
@@ -30,7 +30,7 @@ module RuboCop
|
|
30
30
|
# if Dir.exist?(local)
|
31
31
|
# gem 'rubocop', path: local
|
32
32
|
# elsif ENV['RUBOCOP_VERSION'] == 'master'
|
33
|
-
# gem 'rubocop', git: 'https://github.com/rubocop
|
33
|
+
# gem 'rubocop', git: 'https://github.com/rubocop/rubocop.git'
|
34
34
|
# else
|
35
35
|
# gem 'rubocop', '~> 0.90.0'
|
36
36
|
# end
|
@@ -57,6 +57,7 @@ module RuboCop
|
|
57
57
|
|
58
58
|
private
|
59
59
|
|
60
|
+
# @!method gem_declarations(node)
|
60
61
|
def_node_search :gem_declarations, '(send nil? :gem str ...)'
|
61
62
|
|
62
63
|
def duplicated_gem_nodes
|
@@ -40,6 +40,7 @@ module RuboCop
|
|
40
40
|
MSG = '`%<assignment>s` method calls already given on line '\
|
41
41
|
'%<line_of_first_occurrence>d of the gemspec.'
|
42
42
|
|
43
|
+
# @!method gem_specification(node)
|
43
44
|
def_node_search :gem_specification, <<~PATTERN
|
44
45
|
(block
|
45
46
|
(send
|
@@ -49,6 +50,7 @@ module RuboCop
|
|
49
50
|
(arg $_)) ...)
|
50
51
|
PATTERN
|
51
52
|
|
53
|
+
# @!method assignment_method_declarations(node)
|
52
54
|
def_node_search :assignment_method_declarations, <<~PATTERN
|
53
55
|
(send
|
54
56
|
(lvar #match_block_variable_name?) #assignment_method? ...)
|
@@ -55,10 +55,12 @@ module RuboCop
|
|
55
55
|
'.rubocop.yml) should be equal.'
|
56
56
|
MISSING_MSG = '`required_ruby_version` should be specified.'
|
57
57
|
|
58
|
+
# @!method required_ruby_version(node)
|
58
59
|
def_node_search :required_ruby_version, <<~PATTERN
|
59
60
|
(send _ :required_ruby_version= $_)
|
60
61
|
PATTERN
|
61
62
|
|
63
|
+
# @!method defined_ruby_version(node)
|
62
64
|
def_node_matcher :defined_ruby_version, <<~PATTERN
|
63
65
|
{$(str _) $(array (str _) (str _))
|
64
66
|
(send (const (const nil? :Gem) :Requirement) :new $(str _))}
|
@@ -28,8 +28,10 @@ module RuboCop
|
|
28
28
|
class RubyVersionGlobalsUsage < Base
|
29
29
|
MSG = 'Do not use `RUBY_VERSION` in gemspec file.'
|
30
30
|
|
31
|
+
# @!method ruby_version?(node)
|
31
32
|
def_node_matcher :ruby_version?, '(const {cbase nil?} :RUBY_VERSION)'
|
32
33
|
|
34
|
+
# @!method gem_specification?(node)
|
33
35
|
def_node_search :gem_specification?, <<~PATTERN
|
34
36
|
(block
|
35
37
|
(send
|
@@ -9,7 +9,7 @@ module RuboCop
|
|
9
9
|
# @api private
|
10
10
|
class Generator
|
11
11
|
# NOTE: RDoc 5.1.0 or lower has the following issue.
|
12
|
-
# https://github.com/rubocop
|
12
|
+
# https://github.com/rubocop/rubocop/issues/7043
|
13
13
|
#
|
14
14
|
# The following `String#gsub` can be replaced with
|
15
15
|
# squiggly heredoc when RuboCop supports Ruby 2.5 or higher
|
@@ -58,7 +58,7 @@ module RuboCop
|
|
58
58
|
# TODO: Implement the cop in here.
|
59
59
|
#
|
60
60
|
# In many cases, you can use a node matcher for matching node pattern.
|
61
|
-
# See https://github.com/rubocop
|
61
|
+
# See https://github.com/rubocop/rubocop-ast/blob/master/lib/rubocop/ast/node_pattern.rb
|
62
62
|
#
|
63
63
|
# For example
|
64
64
|
MSG = 'Use `#good_method` instead of `#bad_method`.'
|
@@ -4,6 +4,7 @@ require_relative 'internal_affairs/empty_line_between_expect_offense_and_correct
|
|
4
4
|
require_relative 'internal_affairs/example_description'
|
5
5
|
require_relative 'internal_affairs/method_name_equal'
|
6
6
|
require_relative 'internal_affairs/node_destructuring'
|
7
|
+
require_relative 'internal_affairs/node_matcher_directive'
|
7
8
|
require_relative 'internal_affairs/node_type_predicate'
|
8
9
|
require_relative 'internal_affairs/offense_location_keyword'
|
9
10
|
require_relative 'internal_affairs/redundant_described_class_as_subject'
|
@@ -19,10 +19,12 @@ module RuboCop
|
|
19
19
|
MSG = 'Use the methods provided with the node extensions instead ' \
|
20
20
|
'of manually destructuring nodes.'
|
21
21
|
|
22
|
+
# @!method node_variable?(node)
|
22
23
|
def_node_matcher :node_variable?, <<~PATTERN
|
23
24
|
{(lvar [#node_suffix? _]) (send nil? [#node_suffix? _])}
|
24
25
|
PATTERN
|
25
26
|
|
27
|
+
# @!method node_destructuring?(node)
|
26
28
|
def_node_matcher :node_destructuring?, <<~PATTERN
|
27
29
|
{(masgn (mlhs ...) {(send #node_variable? :children) (array (splat #node_variable?))})}
|
28
30
|
PATTERN
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Checks that node matcher definitions are tagged with a YARD `@!method`
|
7
|
+
# directive so that editors are able to find the dynamically defined
|
8
|
+
# method.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# def_node_matcher :foo?, <<~PATTERN
|
13
|
+
# ...
|
14
|
+
# PATTERN
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# # @!method foo?(node)
|
18
|
+
# def_node_matcher :foo?, <<~PATTERN
|
19
|
+
# ...
|
20
|
+
# PATTERN
|
21
|
+
#
|
22
|
+
class NodeMatcherDirective < Base
|
23
|
+
extend AutoCorrector
|
24
|
+
include RangeHelp
|
25
|
+
|
26
|
+
MSG = 'Preceed `%<method>s` with a `@!method` YARD directive.'
|
27
|
+
MSG_WRONG_NAME = '`@!method` YARD directive has invalid method name, ' \
|
28
|
+
'use `%<expected>s` instead of `%<actual>s`.'
|
29
|
+
MSG_TOO_MANY = 'Multiple `@!method` YARD directives found for this matcher.'
|
30
|
+
|
31
|
+
RESTRICT_ON_SEND = %i[def_node_matcher def_node_search].to_set.freeze
|
32
|
+
REGEXP = /^\s*#\s*@!method\s+(?<method_name>[a-z0-9_]+[?!]?)(?:\((?<args>.*)\))?/.freeze
|
33
|
+
|
34
|
+
# @!method pattern_matcher?(node)
|
35
|
+
def_node_matcher :pattern_matcher?, <<~PATTERN
|
36
|
+
(send _ %RESTRICT_ON_SEND {str sym} {str dstr})
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
def on_send(node)
|
40
|
+
return if node.arguments.none?
|
41
|
+
return unless valid_method_name?(node)
|
42
|
+
|
43
|
+
actual_name = node.arguments.first.value
|
44
|
+
directives = method_directives(node)
|
45
|
+
return too_many_directives(node) if directives.size > 1
|
46
|
+
|
47
|
+
directive = directives.first
|
48
|
+
return if directive_correct?(directive, actual_name)
|
49
|
+
|
50
|
+
register_offense(node, directive, actual_name)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def valid_method_name?(node)
|
56
|
+
node.arguments.first.str_type? || node.arguments.first.sym_type?
|
57
|
+
end
|
58
|
+
|
59
|
+
def method_directives(node)
|
60
|
+
comments = processed_source.ast_with_comments[node]
|
61
|
+
|
62
|
+
comments.map do |comment|
|
63
|
+
match = comment.text.match(REGEXP)
|
64
|
+
next unless match
|
65
|
+
|
66
|
+
{ node: comment, method_name: match[:method_name], args: match[:args] }
|
67
|
+
end.compact
|
68
|
+
end
|
69
|
+
|
70
|
+
def too_many_directives(node)
|
71
|
+
add_offense(node, message: MSG_TOO_MANY)
|
72
|
+
end
|
73
|
+
|
74
|
+
def directive_correct?(directive, actual_name)
|
75
|
+
directive && directive[:method_name] == actual_name.to_s
|
76
|
+
end
|
77
|
+
|
78
|
+
def register_offense(node, directive, actual_name)
|
79
|
+
message = formatted_message(directive, actual_name, node.method_name)
|
80
|
+
|
81
|
+
add_offense(node, message: message) do |corrector|
|
82
|
+
if directive
|
83
|
+
correct_directive(corrector, directive, actual_name)
|
84
|
+
else
|
85
|
+
insert_directive(corrector, node, actual_name)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def formatted_message(directive, actual_name, method_name)
|
91
|
+
if directive
|
92
|
+
format(MSG_WRONG_NAME, expected: actual_name, actual: directive[:method_name])
|
93
|
+
else
|
94
|
+
format(MSG, method: method_name)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def insert_directive(corrector, node, actual_name)
|
99
|
+
# If the pattern matcher uses arguments (`%1`, `%2`, etc.), include them in the directive
|
100
|
+
arguments = pattern_arguments(node.arguments[1].source)
|
101
|
+
|
102
|
+
range = range_with_surrounding_space(
|
103
|
+
range: node.loc.expression,
|
104
|
+
side: :left,
|
105
|
+
newlines: false
|
106
|
+
)
|
107
|
+
indentation = range.source.match(/^\s*/)[0]
|
108
|
+
directive = "#{indentation}# @!method #{actual_name}(#{arguments.join(', ')})\n"
|
109
|
+
directive = "\n#{directive}" if add_newline?(node)
|
110
|
+
|
111
|
+
corrector.insert_before(range, directive)
|
112
|
+
end
|
113
|
+
|
114
|
+
def pattern_arguments(pattern)
|
115
|
+
arguments = %w[node]
|
116
|
+
max_pattern_var = pattern.scan(/(?<=%)\d+/).map(&:to_i).max
|
117
|
+
max_pattern_var&.times { |i| arguments << "arg#{i + 1}" }
|
118
|
+
arguments
|
119
|
+
end
|
120
|
+
|
121
|
+
def add_newline?(node)
|
122
|
+
# Determine if a blank line should be inserted before the new directive
|
123
|
+
# in order to spread out pattern matchers
|
124
|
+
return if node.sibling_index&.zero?
|
125
|
+
return unless node.parent
|
126
|
+
|
127
|
+
prev_sibling = node.parent.child_nodes[node.sibling_index - 1]
|
128
|
+
return unless prev_sibling && pattern_matcher?(prev_sibling)
|
129
|
+
|
130
|
+
node.loc.line == last_line(prev_sibling) + 1
|
131
|
+
end
|
132
|
+
|
133
|
+
def last_line(node)
|
134
|
+
if node.last_argument.heredoc?
|
135
|
+
node.last_argument.loc.heredoc_end.line
|
136
|
+
else
|
137
|
+
node.loc.last_line
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def correct_directive(corrector, directive, actual_name)
|
142
|
+
correct = "@!method #{actual_name}"
|
143
|
+
regexp = /@!method\s+#{Regexp.escape(directive[:method_name])}/
|
144
|
+
|
145
|
+
replacement = directive[:node].text.gsub(regexp, correct)
|
146
|
+
corrector.replace(directive[:node], replacement)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|