rubocop 1.46.0 → 1.52.1
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 +3 -3
- data/config/default.yml +83 -11
- data/lib/rubocop/cli/command/auto_generate_config.rb +7 -0
- data/lib/rubocop/cli/command/execute_runner.rb +7 -2
- data/lib/rubocop/cli.rb +6 -6
- data/lib/rubocop/comment_config.rb +2 -0
- data/lib/rubocop/config.rb +7 -3
- data/lib/rubocop/config_loader.rb +8 -8
- data/lib/rubocop/config_obsoletion.rb +2 -2
- data/lib/rubocop/cop/autocorrect_logic.rb +29 -13
- data/lib/rubocop/cop/base.rb +6 -2
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/cop.rb +2 -2
- data/lib/rubocop/cop/corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/gemspec/dependency_version.rb +1 -1
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -1
- data/lib/rubocop/cop/gemspec/development_dependencies.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +37 -13
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/location_expression.rb +37 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb +1 -1
- 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/internal_affairs/redundant_source_range.rb +66 -0
- data/lib/rubocop/cop/internal_affairs.rb +2 -0
- data/lib/rubocop/cop/layout/block_end_newline.rb +7 -21
- data/lib/rubocop/cop/layout/class_structure.rb +6 -3
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +1 -2
- data/lib/rubocop/cop/layout/empty_comment.rb +3 -3
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -0
- data/lib/rubocop/cop/layout/end_alignment.rb +5 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +6 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +7 -2
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +25 -34
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +7 -19
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +42 -52
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +38 -55
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +4 -4
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +1 -3
- data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +8 -27
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +7 -26
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +4 -21
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +6 -30
- data/lib/rubocop/cop/layout/redundant_line_break.rb +6 -7
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +3 -1
- data/lib/rubocop/cop/layout/space_inside_parens.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +13 -1
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +122 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -2
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -3
- data/lib/rubocop/cop/lint/else_layout.rb +1 -1
- data/lib/rubocop/cop/lint/empty_block.rb +1 -1
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +4 -2
- data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -4
- data/lib/rubocop/cop/lint/identity_comparison.rb +0 -1
- data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +5 -3
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/inherit_exception.rb +9 -0
- data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +46 -4
- data/lib/rubocop/cop/lint/missing_super.rb +34 -2
- data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +2 -2
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +2 -0
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +0 -1
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +2 -2
- data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +4 -4
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -5
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +35 -15
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +3 -3
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +1 -1
- data/lib/rubocop/cop/lint/script_permission.rb +1 -1
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -2
- data/lib/rubocop/cop/lint/shadowed_exception.rb +6 -12
- data/lib/rubocop/cop/lint/syntax.rb +4 -0
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +7 -1
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +23 -9
- data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -3
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +9 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +59 -1
- data/lib/rubocop/cop/lint/useless_method_definition.rb +10 -2
- data/lib/rubocop/cop/lint/useless_rescue.rb +4 -1
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +69 -9
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
- data/lib/rubocop/cop/metrics/class_length.rb +1 -0
- data/lib/rubocop/cop/metrics/collection_literal_length.rb +76 -0
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -2
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +3 -3
- data/lib/rubocop/cop/migration/department_name.rb +1 -1
- data/lib/rubocop/cop/mixin/allowed_receivers.rb +34 -0
- data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +1 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +9 -5
- data/lib/rubocop/cop/mixin/documentation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +4 -2
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +3 -3
- data/lib/rubocop/cop/mixin/min_branches_count.rb +40 -0
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +1 -6
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -3
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +1 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +1 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +23 -4
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +22 -7
- data/lib/rubocop/cop/naming/method_name.rb +3 -3
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +12 -4
- data/lib/rubocop/cop/naming/variable_name.rb +6 -1
- data/lib/rubocop/cop/registry.rb +3 -1
- data/lib/rubocop/cop/style/accessor_grouping.rb +32 -7
- data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -3
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +11 -1
- data/lib/rubocop/cop/style/begin_block.rb +1 -2
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +11 -2
- data/lib/rubocop/cop/style/case_like_if.rb +20 -3
- data/lib/rubocop/cop/style/class_and_module_children.rb +2 -2
- data/lib/rubocop/cop/style/class_equality_comparison.rb +51 -40
- data/lib/rubocop/cop/style/collection_compact.rb +20 -7
- data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
- data/lib/rubocop/cop/style/combinable_loops.rb +26 -6
- data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
- data/lib/rubocop/cop/style/concat_array_literals.rb +10 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +8 -8
- data/lib/rubocop/cop/style/copyright.rb +6 -3
- data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
- data/lib/rubocop/cop/style/dir.rb +1 -1
- data/lib/rubocop/cop/style/dir_empty.rb +54 -0
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +2 -2
- data/lib/rubocop/cop/style/documentation.rb +11 -5
- data/lib/rubocop/cop/style/double_negation.rb +2 -2
- data/lib/rubocop/cop/style/each_with_object.rb +1 -1
- data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +8 -8
- data/lib/rubocop/cop/style/exact_regexp_match.rb +68 -0
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
- data/lib/rubocop/cop/style/file_empty.rb +71 -0
- data/lib/rubocop/cop/style/file_read.rb +3 -3
- data/lib/rubocop/cop/style/file_write.rb +1 -1
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +3 -1
- data/lib/rubocop/cop/style/hash_each_methods.rb +1 -22
- data/lib/rubocop/cop/style/hash_except.rb +23 -12
- data/lib/rubocop/cop/style/hash_like_case.rb +3 -9
- data/lib/rubocop/cop/style/hash_syntax.rb +5 -2
- data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
- data/lib/rubocop/cop/style/if_inside_else.rb +6 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +111 -15
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +5 -5
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +9 -5
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +2 -2
- data/lib/rubocop/cop/style/map_to_hash.rb +4 -1
- data/lib/rubocop/cop/style/map_to_set.rb +4 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +4 -9
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +44 -37
- data/lib/rubocop/cop/style/min_max.rb +3 -3
- data/lib/rubocop/cop/style/mixin_grouping.rb +4 -4
- data/lib/rubocop/cop/style/multiline_method_signature.rb +7 -4
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/multiple_comparison.rb +14 -0
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +12 -7
- data/lib/rubocop/cop/style/nil_lambda.rb +2 -2
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/parallel_assignment.rb +26 -18
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -3
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/redundant_array_constructor.rb +77 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -2
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +2 -2
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +6 -4
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +101 -0
- data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +183 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +46 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +11 -4
- data/lib/rubocop/cop/style/redundant_sort.rb +3 -3
- data/lib/rubocop/cop/style/redundant_string_escape.rb +3 -4
- data/lib/rubocop/cop/style/regexp_literal.rb +11 -2
- data/lib/rubocop/cop/style/require_order.rb +12 -8
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -3
- data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -2
- data/lib/rubocop/cop/style/select_by_regexp.rb +15 -5
- data/lib/rubocop/cop/style/semicolon.rb +12 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +6 -4
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -4
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
- data/lib/rubocop/cop/style/trailing_body_on_class.rb +1 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_logical_operators.rb +1 -0
- data/lib/rubocop/cop/style/unpack_first.rb +3 -3
- data/lib/rubocop/cop/style/yoda_condition.rb +1 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +9 -5
- data/lib/rubocop/cop/team.rb +2 -2
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/variable_force/assignment.rb +33 -1
- data/lib/rubocop/cop/variable_force/variable.rb +5 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
- data/lib/rubocop/cop/variable_force.rb +1 -0
- data/lib/rubocop/cops_documentation_generator.rb +10 -3
- data/lib/rubocop/directive_comment.rb +3 -3
- data/lib/rubocop/ext/comment.rb +18 -0
- data/lib/rubocop/ext/regexp_node.rb +1 -1
- data/lib/rubocop/ext/regexp_parser.rb +1 -1
- data/lib/rubocop/formatter/junit_formatter.rb +4 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/options.rb +4 -1
- data/lib/rubocop/result_cache.rb +2 -2
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/support.rb +1 -0
- data/lib/rubocop/server/cache.rb +1 -1
- data/lib/rubocop/server/client_command/exec.rb +2 -1
- data/lib/rubocop/server/core.rb +1 -1
- data/lib/rubocop/server/helper.rb +1 -1
- data/lib/rubocop/server/server_command/exec.rb +1 -1
- data/lib/rubocop/target_ruby.rb +3 -2
- data/lib/rubocop/version.rb +10 -6
- data/lib/rubocop.rb +13 -0
- metadata +23 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84bada99408af7ceb29d5c6bb4e188f61b27a78cb52639bcbbb144a289ebbc92
|
4
|
+
data.tar.gz: 930174d41acdfd3e0f7da8ef80c496ce7e5b68e5b00312d692a2cd93605fa70a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c1f475617dc4826cef3c543ed35e65117bd93ff6f80605adc2096a06ddb38f9171a95800685a92103924600158ac306c27c9168cea787d5f11dc0616bd1a9ba
|
7
|
+
data.tar.gz: 9aaba3f7148469ce255ee22950f7c11542ca1e8480388493ab90c728831e47eef306372c42769a535beaba95d2d715c4b59161852689468cbd3fcd2c2236a535
|
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.52', require: false
|
57
57
|
```
|
58
58
|
|
59
59
|
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
|
@@ -75,8 +75,8 @@ You can read a lot more about RuboCop in its [official docs](https://docs.ruboco
|
|
75
75
|
|
76
76
|
RuboCop officially supports the following runtime Ruby implementations:
|
77
77
|
|
78
|
-
* MRI 2.
|
79
|
-
* JRuby 9.
|
78
|
+
* MRI 2.7+
|
79
|
+
* JRuby 9.4+
|
80
80
|
|
81
81
|
Targets Ruby 2.0+ code analysis.
|
82
82
|
|
data/config/default.yml
CHANGED
@@ -140,7 +140,7 @@ AllCops:
|
|
140
140
|
# or gems.locked file. (Although the Ruby version is specified in the Gemfile
|
141
141
|
# or gems.rb file, RuboCop reads the final value from the lock file.) If the
|
142
142
|
# Ruby version is still unresolved, RuboCop will use the oldest officially
|
143
|
-
# supported Ruby version (currently Ruby 2.
|
143
|
+
# supported Ruby version (currently Ruby 2.7).
|
144
144
|
TargetRubyVersion: ~
|
145
145
|
# Determines if a notification for extension libraries should be shown when
|
146
146
|
# rubocop is run. Keys are the name of the extension, and values are an array
|
@@ -153,6 +153,8 @@ AllCops:
|
|
153
153
|
rubocop-sequel: [sequel]
|
154
154
|
rubocop-rake: [rake]
|
155
155
|
rubocop-graphql: [graphql]
|
156
|
+
rubocop-capybara: [capybara]
|
157
|
+
rubocop-factory_bot: [factory_bot, factory_bot_rails]
|
156
158
|
# Enable/Disable checking the methods extended by Active Support.
|
157
159
|
ActiveSupportExtensionsEnabled: false
|
158
160
|
|
@@ -1015,8 +1017,6 @@ Layout/LineContinuationLeadingSpace:
|
|
1015
1017
|
Layout/LineContinuationSpacing:
|
1016
1018
|
Description: 'Checks the spacing in front of backslash in line continuations.'
|
1017
1019
|
Enabled: pending
|
1018
|
-
AutoCorrect: true
|
1019
|
-
SafeAutoCorrect: true
|
1020
1020
|
VersionAdded: '1.31'
|
1021
1021
|
EnforcedStyle: space
|
1022
1022
|
SupportedStyles:
|
@@ -1658,6 +1658,7 @@ Lint/Debugger:
|
|
1658
1658
|
- Kernel.binding.remote_pry
|
1659
1659
|
- Kernel.binding.pry_remote
|
1660
1660
|
- Pry.rescue
|
1661
|
+
- pry
|
1661
1662
|
Rails:
|
1662
1663
|
- debugger
|
1663
1664
|
- Kernel.debugger
|
@@ -1750,6 +1751,11 @@ Lint/DuplicateMagicComment:
|
|
1750
1751
|
Enabled: pending
|
1751
1752
|
VersionAdded: '1.37'
|
1752
1753
|
|
1754
|
+
Lint/DuplicateMatchPattern:
|
1755
|
+
Description: 'Do not repeat patterns in `in` keywords.'
|
1756
|
+
Enabled: pending
|
1757
|
+
VersionAdded: '1.50'
|
1758
|
+
|
1753
1759
|
Lint/DuplicateMethods:
|
1754
1760
|
Description: 'Check for duplicate method definitions.'
|
1755
1761
|
Enabled: true
|
@@ -2338,6 +2344,9 @@ Lint/TopLevelReturnWithArgument:
|
|
2338
2344
|
Description: 'Detects top level return statements with argument.'
|
2339
2345
|
Enabled: true
|
2340
2346
|
VersionAdded: '0.89'
|
2347
|
+
# These codes are `eval`-ed in method and their return values may be used.
|
2348
|
+
Exclude:
|
2349
|
+
- '**/*.jb'
|
2341
2350
|
|
2342
2351
|
Lint/TrailingCommaInAttributeDeclaration:
|
2343
2352
|
Description: 'Checks for trailing commas in attribute declarations.'
|
@@ -2446,6 +2455,8 @@ Lint/UselessAssignment:
|
|
2446
2455
|
StyleGuide: '#underscore-unused-vars'
|
2447
2456
|
Enabled: true
|
2448
2457
|
VersionAdded: '0.11'
|
2458
|
+
VersionChanged: '1.51'
|
2459
|
+
SafeAutoCorrect: false
|
2449
2460
|
|
2450
2461
|
Lint/UselessElseWithoutRescue:
|
2451
2462
|
Description: 'Checks for useless `else` in `begin..end` without `rescue`.'
|
@@ -2473,10 +2484,9 @@ Lint/UselessRuby2Keywords:
|
|
2473
2484
|
Lint/UselessSetterCall:
|
2474
2485
|
Description: 'Checks for useless setter call to a local variable.'
|
2475
2486
|
Enabled: true
|
2476
|
-
|
2487
|
+
Safe: false
|
2477
2488
|
VersionAdded: '0.13'
|
2478
2489
|
VersionChanged: '1.2'
|
2479
|
-
Safe: false
|
2480
2490
|
|
2481
2491
|
Lint/UselessTimes:
|
2482
2492
|
Description: 'Checks for useless `Integer#times` calls.'
|
@@ -2543,6 +2553,12 @@ Metrics/ClassLength:
|
|
2543
2553
|
Max: 100
|
2544
2554
|
CountAsOne: []
|
2545
2555
|
|
2556
|
+
Metrics/CollectionLiteralLength:
|
2557
|
+
Description: 'Checks for `Array` or `Hash` literals with many entries.'
|
2558
|
+
Enabled: pending
|
2559
|
+
VersionAdded: '1.47'
|
2560
|
+
LengthThreshold: 250
|
2561
|
+
|
2546
2562
|
# Avoid complex methods.
|
2547
2563
|
Metrics/CyclomaticComplexity:
|
2548
2564
|
Description: >-
|
@@ -2771,7 +2787,7 @@ Naming/InclusiveLanguage:
|
|
2771
2787
|
Description: 'Recommend the use of inclusive language instead of problematic terms.'
|
2772
2788
|
Enabled: false
|
2773
2789
|
VersionAdded: '1.18'
|
2774
|
-
VersionChanged: '1.
|
2790
|
+
VersionChanged: '1.49'
|
2775
2791
|
CheckIdentifiers: true
|
2776
2792
|
CheckConstants: true
|
2777
2793
|
CheckVariables: true
|
@@ -2931,7 +2947,9 @@ Naming/VariableNumber:
|
|
2931
2947
|
Security/CompoundHash:
|
2932
2948
|
Description: 'When overwriting Object#hash to combine values, prefer delegating to Array#hash over writing a custom implementation.'
|
2933
2949
|
Enabled: pending
|
2950
|
+
Safe: false
|
2934
2951
|
VersionAdded: '1.28'
|
2952
|
+
VersionChanged: '1.51'
|
2935
2953
|
|
2936
2954
|
Security/Eval:
|
2937
2955
|
Description: 'The use of eval represents a serious security risk.'
|
@@ -3254,6 +3272,9 @@ Style/CaseLikeIf:
|
|
3254
3272
|
Enabled: true
|
3255
3273
|
Safe: false
|
3256
3274
|
VersionAdded: '0.88'
|
3275
|
+
VersionChanged: '1.48'
|
3276
|
+
# `MinBranchesCount` defines the number of branches `if` needs to have to trigger this cop.
|
3277
|
+
MinBranchesCount: 3
|
3257
3278
|
|
3258
3279
|
Style/CharacterLiteral:
|
3259
3280
|
Description: 'Checks for uses of character literals.'
|
@@ -3266,7 +3287,7 @@ Style/ClassAndModuleChildren:
|
|
3266
3287
|
StyleGuide: '#namespace-definition'
|
3267
3288
|
# Moving from compact to nested children requires knowledge of whether the
|
3268
3289
|
# outer parent is a module or a class. Moving from nested to compact requires
|
3269
|
-
# verification that the outer parent is defined elsewhere.
|
3290
|
+
# verification that the outer parent is defined elsewhere. RuboCop does not
|
3270
3291
|
# have the knowledge to perform either operation safely and thus requires
|
3271
3292
|
# manual oversight.
|
3272
3293
|
SafeAutoCorrect: false
|
@@ -3341,6 +3362,7 @@ Style/CollectionCompact:
|
|
3341
3362
|
Safe: false
|
3342
3363
|
VersionAdded: '1.2'
|
3343
3364
|
VersionChanged: '1.3'
|
3365
|
+
AllowedReceivers: []
|
3344
3366
|
|
3345
3367
|
# Align with the style guide.
|
3346
3368
|
Style/CollectionMethods:
|
@@ -3497,6 +3519,14 @@ Style/Copyright:
|
|
3497
3519
|
Notice: '^Copyright (\(c\) )?2[0-9]{3} .+'
|
3498
3520
|
AutocorrectNotice: ''
|
3499
3521
|
|
3522
|
+
Style/DataInheritance:
|
3523
|
+
Description: 'Checks for inheritance from Data.define.'
|
3524
|
+
StyleGuide: '#no-extend-data-define'
|
3525
|
+
Enabled: pending
|
3526
|
+
SafeAutoCorrect: false
|
3527
|
+
VersionAdded: '1.49'
|
3528
|
+
VersionChanged: '1.51'
|
3529
|
+
|
3500
3530
|
Style/DateTime:
|
3501
3531
|
Description: 'Use Time over DateTime.'
|
3502
3532
|
StyleGuide: '#date-time'
|
@@ -3520,6 +3550,12 @@ Style/Dir:
|
|
3520
3550
|
Enabled: true
|
3521
3551
|
VersionAdded: '0.50'
|
3522
3552
|
|
3553
|
+
Style/DirEmpty:
|
3554
|
+
Description: >-
|
3555
|
+
Prefer to use `Dir.empty?('path/to/dir')` when checking if a directory is empty.
|
3556
|
+
Enabled: pending
|
3557
|
+
VersionAdded: '1.48'
|
3558
|
+
|
3523
3559
|
Style/DisableCopsWithinSourceCodeDirective:
|
3524
3560
|
Description: >-
|
3525
3561
|
Forbids disabling/enabling cops within source code.
|
@@ -3680,6 +3716,11 @@ Style/EvenOdd:
|
|
3680
3716
|
VersionAdded: '0.12'
|
3681
3717
|
VersionChanged: '0.29'
|
3682
3718
|
|
3719
|
+
Style/ExactRegexpMatch:
|
3720
|
+
Description: 'Checks for exact regexp match inside Regexp literals.'
|
3721
|
+
Enabled: pending
|
3722
|
+
VersionAdded: '1.51'
|
3723
|
+
|
3683
3724
|
Style/ExpandPathArguments:
|
3684
3725
|
Description: "Use `expand_path(__dir__)` instead of `expand_path('..', __FILE__)`."
|
3685
3726
|
Enabled: true
|
@@ -3715,6 +3756,13 @@ Style/FetchEnvVar:
|
|
3715
3756
|
# Environment variables to be excluded from the inspection.
|
3716
3757
|
AllowedVars: []
|
3717
3758
|
|
3759
|
+
Style/FileEmpty:
|
3760
|
+
Description: >-
|
3761
|
+
Prefer to use `File.empty?('path/to/file')` when checking if a file is empty.
|
3762
|
+
Enabled: pending
|
3763
|
+
Safe: false
|
3764
|
+
VersionAdded: '1.48'
|
3765
|
+
|
3718
3766
|
Style/FileRead:
|
3719
3767
|
Description: 'Favor `File.(bin)read` convenience methods.'
|
3720
3768
|
StyleGuide: '#file-read'
|
@@ -4034,7 +4082,9 @@ Style/InverseMethods:
|
|
4034
4082
|
Style/InvertibleUnlessCondition:
|
4035
4083
|
Description: 'Favor `if` with inverted condition over `unless`.'
|
4036
4084
|
Enabled: false
|
4085
|
+
Safe: false
|
4037
4086
|
VersionAdded: '1.44'
|
4087
|
+
VersionChanged: '1.50'
|
4038
4088
|
# `InverseMethods` are methods that can be inverted in a `unless` condition.
|
4039
4089
|
# The relationship of inverse methods needs to be defined in both directions.
|
4040
4090
|
# Keys and values both need to be defined as symbols.
|
@@ -4057,8 +4107,6 @@ Style/InvertibleUnlessCondition:
|
|
4057
4107
|
# :blank?: :present?
|
4058
4108
|
# :include?: :exclude?
|
4059
4109
|
# :exclude?: :include?
|
4060
|
-
# :one?: :many?
|
4061
|
-
# :many?: :one?
|
4062
4110
|
|
4063
4111
|
Style/IpAddresses:
|
4064
4112
|
Description: "Don't include literal IP addresses in code."
|
@@ -4335,6 +4383,7 @@ Style/MultipleComparison:
|
|
4335
4383
|
VersionAdded: '0.49'
|
4336
4384
|
VersionChanged: '1.1'
|
4337
4385
|
AllowMethodComparison: true
|
4386
|
+
ComparisonsThreshold: 2
|
4338
4387
|
|
4339
4388
|
Style/MutableConstant:
|
4340
4389
|
Description: 'Do not assign mutable objects to constants.'
|
@@ -4540,11 +4589,10 @@ Style/NumericPredicate:
|
|
4540
4589
|
Checks for the use of predicate- or comparison methods for
|
4541
4590
|
numeric comparisons.
|
4542
4591
|
StyleGuide: '#predicate-methods'
|
4543
|
-
Safe: false
|
4544
4592
|
# This will change to a new method call which isn't guaranteed to be on the
|
4545
4593
|
# object. Switching these methods has to be done with knowledge of the types
|
4546
4594
|
# of the variables which rubocop doesn't have.
|
4547
|
-
|
4595
|
+
Safe: false
|
4548
4596
|
Enabled: true
|
4549
4597
|
VersionAdded: '0.42'
|
4550
4598
|
VersionChanged: '0.59'
|
@@ -4590,7 +4638,9 @@ Style/OpenStructUse:
|
|
4590
4638
|
- https://docs.ruby-lang.org/en/3.0.0/OpenStruct.html#class-OpenStruct-label-Caveats
|
4591
4639
|
|
4592
4640
|
Enabled: pending
|
4641
|
+
Safe: false
|
4593
4642
|
VersionAdded: '1.23'
|
4643
|
+
VersionChanged: '1.51'
|
4594
4644
|
|
4595
4645
|
Style/OperatorMethodCall:
|
4596
4646
|
Description: 'Checks for redundant dot before operator method call.'
|
@@ -4756,6 +4806,11 @@ Style/RedundantArgument:
|
|
4756
4806
|
# String#chomp!
|
4757
4807
|
chomp!: "\n"
|
4758
4808
|
|
4809
|
+
Style/RedundantArrayConstructor:
|
4810
|
+
Description: 'Checks for the instantiation of array using redundant `Array` constructor.'
|
4811
|
+
Enabled: pending
|
4812
|
+
VersionAdded: '1.52'
|
4813
|
+
|
4759
4814
|
Style/RedundantAssignment:
|
4760
4815
|
Description: 'Checks for redundant assignment before returning.'
|
4761
4816
|
Enabled: true
|
@@ -4827,6 +4882,13 @@ Style/RedundantFileExtensionInRequire:
|
|
4827
4882
|
Enabled: true
|
4828
4883
|
VersionAdded: '0.88'
|
4829
4884
|
|
4885
|
+
Style/RedundantFilterChain:
|
4886
|
+
Description: >-
|
4887
|
+
Identifies usages of `any?`, `empty?`, `none?` or `one?` predicate methods chained to
|
4888
|
+
`select`/`filter`/`find_all` and change them to use predicate method instead.
|
4889
|
+
Enabled: pending
|
4890
|
+
VersionAdded: '1.52'
|
4891
|
+
|
4830
4892
|
Style/RedundantFreeze:
|
4831
4893
|
Description: "Checks usages of Object#freeze on immutable objects."
|
4832
4894
|
Enabled: true
|
@@ -4853,6 +4915,11 @@ Style/RedundantInterpolation:
|
|
4853
4915
|
VersionAdded: '0.76'
|
4854
4916
|
VersionChanged: '1.30'
|
4855
4917
|
|
4918
|
+
Style/RedundantLineContinuation:
|
4919
|
+
Description: 'Check for redundant line continuation.'
|
4920
|
+
Enabled: pending
|
4921
|
+
VersionAdded: '1.49'
|
4922
|
+
|
4856
4923
|
Style/RedundantParentheses:
|
4857
4924
|
Description: "Checks for parentheses that seem not to serve any purpose."
|
4858
4925
|
Enabled: true
|
@@ -4869,6 +4936,11 @@ Style/RedundantRegexpCharacterClass:
|
|
4869
4936
|
Enabled: true
|
4870
4937
|
VersionAdded: '0.85'
|
4871
4938
|
|
4939
|
+
Style/RedundantRegexpConstructor:
|
4940
|
+
Description: 'Checks for the instantiation of regexp using redundant `Regexp.new` or `Regexp.compile`.'
|
4941
|
+
Enabled: pending
|
4942
|
+
VersionAdded: '1.52'
|
4943
|
+
|
4872
4944
|
Style/RedundantRegexpEscape:
|
4873
4945
|
Description: 'Checks for redundant escapes in Regexps.'
|
4874
4946
|
Enabled: true
|
@@ -16,6 +16,7 @@ module RuboCop
|
|
16
16
|
|
17
17
|
PHASE_1_OVERRIDDEN = '(skipped because the default Layout/LineLength:Max is overridden)'
|
18
18
|
PHASE_1_DISABLED = '(skipped because Layout/LineLength is disabled)'
|
19
|
+
PHASE_1_SKIPPED = '(skipped because a list of cops is passed to the `--only` flag)'
|
19
20
|
|
20
21
|
def run
|
21
22
|
add_formatter
|
@@ -31,6 +32,8 @@ module RuboCop
|
|
31
32
|
skip_line_length_cop(PHASE_1_DISABLED)
|
32
33
|
elsif !same_max_line_length?(@config_store.for_pwd, ConfigLoader.default_configuration)
|
33
34
|
skip_line_length_cop(PHASE_1_OVERRIDDEN)
|
35
|
+
elsif options_has_only_flag?
|
36
|
+
skip_line_length_cop(PHASE_1_SKIPPED)
|
34
37
|
else
|
35
38
|
run_line_length_cop
|
36
39
|
end
|
@@ -57,6 +60,10 @@ module RuboCop
|
|
57
60
|
config.for_cop('Layout/LineLength')
|
58
61
|
end
|
59
62
|
|
63
|
+
def options_has_only_flag?
|
64
|
+
@options[:only]
|
65
|
+
end
|
66
|
+
|
60
67
|
# Do an initial run with only Layout/LineLength so that cops that
|
61
68
|
# depend on Layout/LineLength:Max get the correct value for that
|
62
69
|
# parameter.
|
@@ -76,13 +76,18 @@ module RuboCop
|
|
76
76
|
warn <<~WARNING
|
77
77
|
Errors are usually caused by RuboCop bugs.
|
78
78
|
Please, report your problems to RuboCop's issue tracker.
|
79
|
-
#{
|
80
|
-
|
79
|
+
#{bug_tracker_uri}
|
81
80
|
Mention the following information in the issue report:
|
82
81
|
#{RuboCop::Version.version(debug: true)}
|
83
82
|
WARNING
|
84
83
|
end
|
85
84
|
|
85
|
+
def bug_tracker_uri
|
86
|
+
return unless Gem.loaded_specs.key?('rubocop')
|
87
|
+
|
88
|
+
"#{Gem.loaded_specs['rubocop'].metadata['bug_tracker_uri']}\n"
|
89
|
+
end
|
90
|
+
|
86
91
|
def maybe_print_corrected_source
|
87
92
|
# Integration tools (like RubyMine) expect to have only the JSON result
|
88
93
|
# when specifying JSON format. Similar HTML and JUnit are targeted as well.
|
data/lib/rubocop/cli.rb
CHANGED
@@ -87,20 +87,20 @@ module RuboCop
|
|
87
87
|
|
88
88
|
tmp_dir = File.join(ConfigFinder.project_root, 'tmp')
|
89
89
|
FileUtils.mkdir_p(tmp_dir)
|
90
|
+
cpu_profile_file = File.join(tmp_dir, 'rubocop-stackprof.dump')
|
90
91
|
status = nil
|
91
92
|
|
92
|
-
StackProf.run(out:
|
93
|
+
StackProf.run(out: cpu_profile_file) do
|
93
94
|
status = yield
|
94
95
|
end
|
95
|
-
puts
|
96
|
+
puts "Profile report generated at #{cpu_profile_file}"
|
96
97
|
|
97
98
|
if with_memory
|
98
99
|
puts 'Building memory report...'
|
99
100
|
report = MemoryProfiler.stop
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
)
|
101
|
+
memory_profile_file = File.join(tmp_dir, 'rubocop-memory_profiler.txt')
|
102
|
+
report.pretty_print(to_file: memory_profile_file, scale_bytes: true)
|
103
|
+
puts "Memory report generated at #{memory_profile_file}"
|
104
104
|
end
|
105
105
|
status
|
106
106
|
end
|
@@ -11,6 +11,8 @@ module RuboCop
|
|
11
11
|
# This class provides an API compatible with RuboCop::DirectiveComment
|
12
12
|
# to be used for cops that are disabled in the config file
|
13
13
|
class ConfigDisabledCopDirectiveComment
|
14
|
+
include RuboCop::Ext::Comment
|
15
|
+
|
14
16
|
attr_reader :text, :loc, :line_number
|
15
17
|
|
16
18
|
Loc = Struct.new(:expression)
|
data/lib/rubocop/config.rb
CHANGED
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# rubocop:disable Metrics/AbcSize
|
32
|
-
def initialize(hash =
|
32
|
+
def initialize(hash = RuboCop::ConfigLoader.default_configuration, loaded_path = nil)
|
33
33
|
@loaded_path = loaded_path
|
34
34
|
@for_cop = Hash.new do |h, cop|
|
35
35
|
cop_name = cop.respond_to?(:cop_name) ? cop.cop_name : cop
|
@@ -284,6 +284,10 @@ module RuboCop
|
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
287
|
+
def inspect # :nodoc:
|
288
|
+
"#<#{self.class.name}:#{object_id} @loaded_path=#{loaded_path}>"
|
289
|
+
end
|
290
|
+
|
287
291
|
private
|
288
292
|
|
289
293
|
def target_rails_version_from_bundler_lock_file
|
@@ -304,8 +308,8 @@ module RuboCop
|
|
304
308
|
end
|
305
309
|
|
306
310
|
def enable_cop?(qualified_cop_name, cop_options)
|
307
|
-
# If the cop is explicitly enabled
|
308
|
-
return true if cop_options['Enabled'] == true
|
311
|
+
# If the cop is explicitly enabled or `Lint/Syntax`, the other checks can be skipped.
|
312
|
+
return true if cop_options['Enabled'] == true || qualified_cop_name == 'Lint/Syntax'
|
309
313
|
|
310
314
|
department = department_of(qualified_cop_name)
|
311
315
|
cop_enabled = cop_options.fetch('Enabled') { !for_all_cops['DisabledByDefault'] }
|
@@ -23,6 +23,14 @@ module RuboCop
|
|
23
23
|
class << self
|
24
24
|
include FileFinder
|
25
25
|
|
26
|
+
PENDING_BANNER = <<~BANNER
|
27
|
+
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
|
28
|
+
|
29
|
+
Please also note that you can opt-in to new cops by default by adding this to your config:
|
30
|
+
AllCops:
|
31
|
+
NewCops: enable
|
32
|
+
BANNER
|
33
|
+
|
26
34
|
attr_accessor :debug, :ignore_parent_exclusion, :disable_pending_cops, :enable_pending_cops,
|
27
35
|
:ignore_unrecognized_cops
|
28
36
|
attr_writer :default_configuration
|
@@ -165,14 +173,6 @@ module RuboCop
|
|
165
173
|
ConfigFinder.project_root
|
166
174
|
end
|
167
175
|
|
168
|
-
PENDING_BANNER = <<~BANNER
|
169
|
-
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
|
170
|
-
|
171
|
-
Please also note that you can opt-in to new cops by default by adding this to your config:
|
172
|
-
AllCops:
|
173
|
-
NewCops: enable
|
174
|
-
BANNER
|
175
|
-
|
176
176
|
def warn_on_pending_cops(pending_cops)
|
177
177
|
warn Rainbow(PENDING_BANNER).yellow
|
178
178
|
|
@@ -68,11 +68,11 @@ module RuboCop
|
|
68
68
|
# Cop rules are keyed by the name of the original cop
|
69
69
|
def load_cop_rules(rules)
|
70
70
|
rules.flat_map do |rule_type, data|
|
71
|
-
data.
|
71
|
+
data.filter_map do |cop_name, configuration|
|
72
72
|
next unless configuration # allow configurations to be disabled with `CopName: ~`
|
73
73
|
|
74
74
|
COP_RULE_CLASSES[rule_type].new(@config, cop_name, configuration)
|
75
|
-
end
|
75
|
+
end
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -35,7 +35,7 @@ module RuboCop
|
|
35
35
|
return false if cop_config['AutoCorrect'] == false
|
36
36
|
|
37
37
|
# :safe_autocorrect is a derived option based on several command-line
|
38
|
-
# arguments - see
|
38
|
+
# arguments - see RuboCop::Options#add_autocorrection_options
|
39
39
|
return safe_autocorrect? if @options.fetch(:safe_autocorrect, false)
|
40
40
|
|
41
41
|
true
|
@@ -43,18 +43,24 @@ module RuboCop
|
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
|
-
def disable_offense(
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
def disable_offense(offense_range)
|
47
|
+
range = surrounding_heredoc(offense_range) || surrounding_percent_array(offense_range)
|
48
|
+
|
49
|
+
if range
|
50
|
+
disable_offense_before_and_after(range_by_lines(range))
|
51
|
+
else
|
52
|
+
disable_offense_with_eol_or_surround_comment(offense_range)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def disable_offense_with_eol_or_surround_comment(range)
|
57
|
+
eol_comment = " # rubocop:todo #{cop_name}"
|
58
|
+
needed_line_length = (range.source_line + eol_comment).length
|
59
|
+
|
60
|
+
if needed_line_length <= max_line_length
|
61
|
+
disable_offense_at_end_of_line(range_of_first_line(range), eol_comment)
|
50
62
|
else
|
51
|
-
|
52
|
-
needed_line_length = (range.source_line + eol_comment).length
|
53
|
-
if needed_line_length <= max_line_length
|
54
|
-
disable_offense_at_end_of_line(range_of_first_line(range), eol_comment)
|
55
|
-
else
|
56
|
-
disable_offense_before_and_after(range_by_lines(range))
|
57
|
-
end
|
63
|
+
disable_offense_before_and_after(range_by_lines(range))
|
58
64
|
end
|
59
65
|
end
|
60
66
|
|
@@ -65,10 +71,20 @@ module RuboCop
|
|
65
71
|
heredoc_nodes = processed_source.ast.each_descendant.select do |node|
|
66
72
|
node.respond_to?(:heredoc?) && node.heredoc?
|
67
73
|
end
|
68
|
-
heredoc_nodes.map { |node| node.
|
74
|
+
heredoc_nodes.map { |node| node.source_range.join(node.loc.heredoc_end) }
|
69
75
|
.find { |range| range.contains?(offense_range) }
|
70
76
|
end
|
71
77
|
|
78
|
+
def surrounding_percent_array(offense_range)
|
79
|
+
return nil if offense_range.empty?
|
80
|
+
|
81
|
+
percent_array = processed_source.ast.each_descendant.select do |node|
|
82
|
+
node.array_type? && node.percent_literal?
|
83
|
+
end
|
84
|
+
|
85
|
+
percent_array.map(&:source_range).find { |range| range.overlaps?(offense_range) }
|
86
|
+
end
|
87
|
+
|
72
88
|
def range_of_first_line(range)
|
73
89
|
begin_of_first_line = range.begin_pos - range.column
|
74
90
|
end_of_first_line = begin_of_first_line + range.source_line.length
|
data/lib/rubocop/cop/base.rb
CHANGED
@@ -284,7 +284,7 @@ module RuboCop
|
|
284
284
|
# @api private
|
285
285
|
def self.callbacks_needed
|
286
286
|
@callbacks_needed ||= public_instance_methods.select do |m|
|
287
|
-
m.
|
287
|
+
m.start_with?(/on_|after_/) &&
|
288
288
|
!Base.method_defined?(m) # exclude standard "callbacks" like 'on_begin_investigation'
|
289
289
|
end
|
290
290
|
end
|
@@ -305,6 +305,10 @@ module RuboCop
|
|
305
305
|
@current_original = original
|
306
306
|
end
|
307
307
|
|
308
|
+
def inspect # :nodoc:
|
309
|
+
"#<#{self.class.name}:#{object_id} @config=#{@config} @options=#{@options}>"
|
310
|
+
end
|
311
|
+
|
308
312
|
private
|
309
313
|
|
310
314
|
### Reserved for Cop::Cop
|
@@ -416,7 +420,7 @@ module RuboCop
|
|
416
420
|
|
417
421
|
def range_from_node_or_range(node_or_range)
|
418
422
|
if node_or_range.respond_to?(:loc)
|
419
|
-
node_or_range.
|
423
|
+
node_or_range.source_range
|
420
424
|
elsif node_or_range.is_a?(::Parser::Source::Range)
|
421
425
|
node_or_range
|
422
426
|
else
|
@@ -124,7 +124,7 @@ module RuboCop
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def preceding_comment?(node1, node2)
|
127
|
-
node1 && node2 && precede?(node2, node1) && comment_line?(node2.
|
127
|
+
node1 && node2 && precede?(node2, node1) && comment_line?(node2.source)
|
128
128
|
end
|
129
129
|
|
130
130
|
def ignored_gem?(node)
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -138,10 +138,10 @@ module RuboCop
|
|
138
138
|
def correction_lambda
|
139
139
|
return unless support_autocorrect?
|
140
140
|
|
141
|
-
|
141
|
+
dedupe_on_node(@v0_argument) { autocorrect(@v0_argument) }
|
142
142
|
end
|
143
143
|
|
144
|
-
def
|
144
|
+
def dedupe_on_node(node)
|
145
145
|
@corrected_nodes ||= {}.compare_by_identity
|
146
146
|
yield unless @corrected_nodes.key?(node)
|
147
147
|
ensure
|
@@ -104,7 +104,7 @@ module RuboCop
|
|
104
104
|
def to_range(node_or_range)
|
105
105
|
range = case node_or_range
|
106
106
|
when ::RuboCop::AST::Node, ::Parser::Source::Comment
|
107
|
-
node_or_range.
|
107
|
+
node_or_range.source_range
|
108
108
|
when ::Parser::Source::Range
|
109
109
|
node_or_range
|
110
110
|
else
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
return unless node
|
17
17
|
|
18
18
|
@processed_source = processed_source
|
19
|
-
expr = node.respond_to?(:loc) ? node.
|
19
|
+
expr = node.respond_to?(:loc) ? node.source_range : node
|
20
20
|
return if block_comment_within?(expr)
|
21
21
|
|
22
22
|
taboo_ranges = inside_string_ranges(node)
|
@@ -54,7 +54,7 @@ module RuboCop
|
|
54
54
|
def inside_string_ranges(node)
|
55
55
|
return [] unless node.is_a?(Parser::AST::Node)
|
56
56
|
|
57
|
-
node.each_node(:str, :dstr, :xstr).
|
57
|
+
node.each_node(:str, :dstr, :xstr).filter_map { |n| inside_string_range(n) }
|
58
58
|
end
|
59
59
|
|
60
60
|
def inside_string_range(node)
|
@@ -80,7 +80,7 @@ module RuboCop
|
|
80
80
|
|
81
81
|
def block_comment_within?(expr)
|
82
82
|
processed_source.comments.select(&:document?).any? do |c|
|
83
|
-
within?(c.
|
83
|
+
within?(c.source_range, expr)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -35,15 +35,15 @@ module RuboCop
|
|
35
35
|
|
36
36
|
def offending_range
|
37
37
|
if block_node.arguments?
|
38
|
-
replacement_range(argument_node.
|
38
|
+
replacement_range(argument_node.source_range.end_pos)
|
39
39
|
else
|
40
40
|
replacement_range(block_node.loc.begin.end_pos)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
def replacement_range(end_pos)
|
45
|
-
Parser::Source::Range.new(block_node.
|
46
|
-
block_node.
|
45
|
+
Parser::Source::Range.new(block_node.source_range.source_buffer,
|
46
|
+
block_node.source_range.begin_pos,
|
47
47
|
end_pos)
|
48
48
|
end
|
49
49
|
end
|
@@ -56,7 +56,7 @@ module RuboCop
|
|
56
56
|
if collection_node.begin_type?
|
57
57
|
collection_node.loc.end
|
58
58
|
else
|
59
|
-
collection_node.
|
59
|
+
collection_node.source_range
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -65,8 +65,8 @@ module RuboCop
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def replacement_range(end_pos)
|
68
|
-
Parser::Source::Range.new(for_node.
|
69
|
-
for_node.
|
68
|
+
Parser::Source::Range.new(for_node.source_range.source_buffer,
|
69
|
+
for_node.source_range.begin_pos,
|
70
70
|
end_pos)
|
71
71
|
end
|
72
72
|
end
|