rubocop 1.54.1 → 1.64.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +5 -4
- data/assets/output.css.erb +159 -0
- data/assets/output.html.erb +1 -160
- data/config/default.yml +155 -26
- data/config/obsoletion.yml +5 -0
- data/lib/rubocop/cached_data.rb +11 -3
- data/lib/rubocop/cli/command/auto_generate_config.rb +22 -8
- data/lib/rubocop/cli/command/lsp.rb +2 -2
- data/lib/rubocop/cli/command/show_docs_url.rb +2 -2
- data/lib/rubocop/cli.rb +11 -2
- data/lib/rubocop/config.rb +36 -12
- data/lib/rubocop/config_finder.rb +14 -4
- data/lib/rubocop/config_loader.rb +0 -1
- data/lib/rubocop/config_obsoletion/parameter_rule.rb +9 -1
- data/lib/rubocop/config_obsoletion.rb +11 -8
- data/lib/rubocop/config_validator.rb +14 -7
- data/lib/rubocop/cop/autocorrect_logic.rb +9 -2
- data/lib/rubocop/cop/base.rb +64 -17
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -0
- data/lib/rubocop/cop/bundler/duplicated_group.rb +127 -0
- data/lib/rubocop/cop/bundler/gem_comment.rb +2 -2
- data/lib/rubocop/cop/bundler/gem_version.rb +3 -5
- data/lib/rubocop/cop/bundler/ordered_gems.rb +9 -1
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +4 -8
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +5 -13
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +7 -4
- data/lib/rubocop/cop/documentation.rb +16 -6
- data/lib/rubocop/cop/exclude_limit.rb +1 -1
- data/lib/rubocop/cop/force.rb +12 -0
- data/lib/rubocop/cop/gemspec/dependency_version.rb +3 -5
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +9 -1
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +5 -1
- data/lib/rubocop/cop/generator/require_file_injector.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/example_description.rb +46 -24
- data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +8 -6
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +19 -20
- data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +53 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +123 -29
- data/lib/rubocop/cop/internal_affairs/redundant_expect_offense_arguments.rb +34 -0
- data/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb +11 -2
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
- data/lib/rubocop/cop/internal_affairs.rb +2 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +1 -5
- data/lib/rubocop/cop/layout/empty_comment.rb +3 -1
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +42 -9
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +14 -7
- data/lib/rubocop/cop/layout/end_alignment.rb +15 -3
- data/lib/rubocop/cop/layout/extra_spacing.rb +4 -10
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +24 -7
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +4 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +17 -9
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +18 -3
- data/lib/rubocop/cop/layout/redundant_line_break.rb +29 -6
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +4 -4
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +5 -0
- data/lib/rubocop/cop/layout/space_after_not.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_operators.rb +50 -20
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +19 -10
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_parens.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +3 -4
- data/lib/rubocop/cop/layout/trailing_empty_lines.rb +5 -0
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +6 -6
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +2 -2
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +38 -3
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
- data/lib/rubocop/cop/lint/empty_block.rb +1 -1
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +2 -2
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +24 -17
- data/lib/rubocop/cop/lint/float_comparison.rb +10 -0
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +2 -1
- data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +56 -0
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +85 -0
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/mixed_case_range.rb +10 -5
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +6 -21
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +10 -7
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -5
- data/lib/rubocop/cop/lint/number_conversion.rb +9 -4
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +4 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +72 -8
- data/lib/rubocop/cop/lint/redundant_with_index.rb +6 -2
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
- data/lib/rubocop/cop/lint/rescue_type.rb +1 -3
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +14 -8
- data/lib/rubocop/cop/lint/script_permission.rb +3 -3
- data/lib/rubocop/cop/lint/self_assignment.rb +38 -0
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +7 -1
- data/lib/rubocop/cop/lint/struct_new_override.rb +12 -12
- data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/symbol_conversion.rb +7 -2
- data/lib/rubocop/cop/lint/syntax.rb +6 -3
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +12 -5
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -1
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +2 -2
- data/lib/rubocop/cop/lint/unreachable_code.rb +4 -2
- data/lib/rubocop/cop/lint/unreachable_loop.rb +8 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -2
- data/lib/rubocop/cop/lint/useless_assignment.rb +38 -12
- data/lib/rubocop/cop/lint/useless_times.rb +2 -2
- data/lib/rubocop/cop/lint/void.rb +48 -12
- data/lib/rubocop/cop/metrics/abc_size.rb +3 -3
- data/lib/rubocop/cop/metrics/block_length.rb +1 -1
- data/lib/rubocop/cop/metrics/class_length.rb +8 -3
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +7 -7
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +12 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +16 -12
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -0
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +23 -13
- data/lib/rubocop/cop/mixin/method_complexity.rb +15 -6
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +4 -3
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +6 -8
- data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -1
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/string_help.rb +4 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +34 -7
- data/lib/rubocop/cop/naming/constant_name.rb +1 -2
- data/lib/rubocop/cop/naming/file_name.rb +3 -3
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +3 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +1 -2
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +2 -2
- data/lib/rubocop/cop/registry.rb +1 -1
- data/lib/rubocop/cop/security/compound_hash.rb +2 -2
- data/lib/rubocop/cop/security/open.rb +2 -2
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +52 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +1 -1
- data/lib/rubocop/cop/style/alias.rb +10 -8
- data/lib/rubocop/cop/style/arguments_forwarding.rb +414 -63
- data/lib/rubocop/cop/style/array_first_last.rb +64 -0
- data/lib/rubocop/cop/style/array_intersect.rb +13 -5
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +21 -14
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +2 -2
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -1
- data/lib/rubocop/cop/style/case_like_if.rb +5 -5
- data/lib/rubocop/cop/style/class_check.rb +1 -0
- data/lib/rubocop/cop/style/class_equality_comparison.rb +7 -0
- data/lib/rubocop/cop/style/class_vars.rb +3 -3
- data/lib/rubocop/cop/style/collection_compact.rb +21 -11
- data/lib/rubocop/cop/style/collection_methods.rb +2 -0
- data/lib/rubocop/cop/style/combinable_loops.rb +17 -9
- data/lib/rubocop/cop/style/commented_keyword.rb +5 -2
- data/lib/rubocop/cop/style/concat_array_literals.rb +2 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +7 -8
- data/lib/rubocop/cop/style/copyright.rb +31 -21
- data/lib/rubocop/cop/style/date_time.rb +5 -4
- data/lib/rubocop/cop/style/documentation.rb +24 -24
- data/lib/rubocop/cop/style/documentation_method.rb +20 -0
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +7 -7
- data/lib/rubocop/cop/style/each_with_object.rb +2 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +6 -1
- data/lib/rubocop/cop/style/empty_literal.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +6 -15
- data/lib/rubocop/cop/style/exact_regexp_match.rb +4 -2
- data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -2
- data/lib/rubocop/cop/style/for.rb +3 -1
- data/lib/rubocop/cop/style/format_string.rb +33 -12
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -1
- data/lib/rubocop/cop/style/guard_clause.rb +26 -0
- data/lib/rubocop/cop/style/hash_conversion.rb +10 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +105 -11
- data/lib/rubocop/cop/style/hash_except.rb +2 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +24 -2
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +28 -3
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +5 -3
- data/lib/rubocop/cop/style/inverse_methods.rb +14 -13
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +44 -2
- data/lib/rubocop/cop/style/lambda_call.rb +5 -0
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +8 -10
- data/lib/rubocop/cop/style/map_into_array.rb +175 -0
- data/lib/rubocop/cop/style/map_to_hash.rb +18 -8
- data/lib/rubocop/cop/style/map_to_set.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +22 -6
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +20 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/missing_respond_to_missing.rb +2 -2
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
- data/lib/rubocop/cop/style/multiline_method_signature.rb +10 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +6 -4
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +3 -11
- data/lib/rubocop/cop/style/next.rb +1 -1
- data/lib/rubocop/cop/style/nil_comparison.rb +2 -0
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +10 -2
- data/lib/rubocop/cop/style/object_then.rb +5 -3
- data/lib/rubocop/cop/style/one_line_conditional.rb +1 -1
- data/lib/rubocop/cop/style/open_struct_use.rb +1 -1
- data/lib/rubocop/cop/style/operator_method_call.rb +8 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +3 -5
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -0
- data/lib/rubocop/cop/style/raise_args.rb +4 -1
- data/lib/rubocop/cop/style/redundant_argument.rb +33 -4
- data/lib/rubocop/cop/style/redundant_assignment.rb +10 -2
- data/lib/rubocop/cop/style/redundant_begin.rb +9 -1
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -9
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +5 -4
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +93 -5
- data/lib/rubocop/cop/style/redundant_each.rb +7 -4
- data/lib/rubocop/cop/style/redundant_exception.rb +32 -12
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +3 -3
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +23 -6
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +19 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +71 -22
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +14 -3
- data/lib/rubocop/cop/style/redundant_self.rb +17 -2
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +5 -0
- data/lib/rubocop/cop/style/redundant_sort.rb +9 -8
- data/lib/rubocop/cop/style/redundant_sort_by.rb +2 -2
- data/lib/rubocop/cop/style/redundant_string_escape.rb +1 -1
- data/lib/rubocop/cop/style/require_order.rb +1 -1
- data/lib/rubocop/cop/style/return_nil.rb +6 -2
- data/lib/rubocop/cop/style/return_nil_in_predicate_method_definition.rb +23 -9
- data/lib/rubocop/cop/style/sample.rb +3 -4
- data/lib/rubocop/cop/style/select_by_regexp.rb +7 -6
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +8 -3
- data/lib/rubocop/cop/style/send.rb +4 -4
- data/lib/rubocop/cop/style/send_with_literal_method_name.rb +90 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +7 -3
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +67 -0
- data/lib/rubocop/cop/style/slicing_with_range.rb +76 -10
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +3 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -2
- data/lib/rubocop/cop/style/string_chars.rb +1 -0
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +30 -5
- data/lib/rubocop/cop/style/strip.rb +7 -4
- data/lib/rubocop/cop/style/super_arguments.rb +156 -0
- data/lib/rubocop/cop/style/super_with_args_parentheses.rb +35 -0
- data/lib/rubocop/cop/style/symbol_array.rb +35 -15
- data/lib/rubocop/cop/style/symbol_proc.rb +68 -5
- data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +11 -14
- data/lib/rubocop/cop/style/yoda_expression.rb +8 -7
- data/lib/rubocop/cop/team.rb +5 -0
- data/lib/rubocop/cop/utils/regexp_ranges.rb +27 -14
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -3
- data/lib/rubocop/cops_documentation_generator.rb +15 -3
- data/lib/rubocop/directive_comment.rb +10 -8
- data/lib/rubocop/ext/regexp_node.rb +9 -4
- data/lib/rubocop/file_finder.rb +4 -7
- data/lib/rubocop/formatter/clang_style_formatter.rb +3 -7
- data/lib/rubocop/formatter/disabled_config_formatter.rb +23 -8
- data/lib/rubocop/formatter/formatter_set.rb +7 -1
- data/lib/rubocop/formatter/html_formatter.rb +35 -14
- data/lib/rubocop/formatter/json_formatter.rb +0 -1
- data/lib/rubocop/formatter/junit_formatter.rb +1 -1
- data/lib/rubocop/formatter/offense_count_formatter.rb +12 -2
- data/lib/rubocop/formatter/tap_formatter.rb +3 -7
- data/lib/rubocop/formatter.rb +1 -1
- data/lib/rubocop/lockfile.rb +56 -7
- data/lib/rubocop/lsp/logger.rb +1 -1
- data/lib/rubocop/lsp/routes.rb +43 -31
- data/lib/rubocop/lsp/runtime.rb +21 -4
- data/lib/rubocop/lsp/server.rb +13 -6
- data/lib/rubocop/lsp/severity.rb +1 -1
- data/lib/rubocop/lsp.rb +36 -0
- data/lib/rubocop/magic_comment.rb +13 -11
- data/lib/rubocop/options.rb +14 -11
- data/lib/rubocop/path_util.rb +6 -2
- data/lib/rubocop/rake_task.rb +1 -1
- data/lib/rubocop/result_cache.rb +4 -1
- data/lib/rubocop/rspec/cop_helper.rb +8 -2
- data/lib/rubocop/rspec/expect_offense.rb +16 -8
- data/lib/rubocop/rspec/shared_contexts.rb +55 -19
- data/lib/rubocop/rspec/support.rb +2 -0
- data/lib/rubocop/runner.rb +19 -6
- data/lib/rubocop/server/cache.rb +1 -1
- data/lib/rubocop/server/client_command/exec.rb +1 -2
- data/lib/rubocop/server/server_command/exec.rb +0 -1
- data/lib/rubocop/string_interpreter.rb +3 -3
- data/lib/rubocop/target_finder.rb +91 -81
- data/lib/rubocop/target_ruby.rb +82 -76
- data/lib/rubocop/version.rb +19 -4
- data/lib/rubocop.rb +9 -0
- metadata +29 -16
- /data/lib/rubocop/formatter/{git_hub_actions_formatter.rb → github_actions_formatter.rb} +0 -0
data/lib/rubocop/cli.rb
CHANGED
@@ -11,8 +11,8 @@ module RuboCop
|
|
11
11
|
STATUS_ERROR = 2
|
12
12
|
STATUS_INTERRUPTED = Signal.list['INT'] + 128
|
13
13
|
DEFAULT_PARALLEL_OPTIONS = %i[
|
14
|
-
color debug display_style_guide display_time display_only_fail_level_offenses
|
15
|
-
display_only_failed except extra_details fail_level fix_layout format
|
14
|
+
color config debug display_style_guide display_time display_only_fail_level_offenses
|
15
|
+
display_only_failed editor_mode except extra_details fail_level fix_layout format
|
16
16
|
ignore_disable_comments lint only only_guide_cops require safe
|
17
17
|
autocorrect safe_autocorrect autocorrect_all
|
18
18
|
].freeze
|
@@ -57,6 +57,10 @@ module RuboCop
|
|
57
57
|
rescue RuboCop::Error => e
|
58
58
|
warn Rainbow("Error: #{e.message}").red
|
59
59
|
STATUS_ERROR
|
60
|
+
rescue Interrupt
|
61
|
+
warn ''
|
62
|
+
warn 'Exiting...'
|
63
|
+
STATUS_INTERRUPTED
|
60
64
|
rescue Finished
|
61
65
|
STATUS_SUCCESS
|
62
66
|
rescue OptionParser::InvalidOption => e
|
@@ -151,6 +155,7 @@ module RuboCop
|
|
151
155
|
|
152
156
|
def act_on_options
|
153
157
|
set_options_to_config_loader
|
158
|
+
handle_editor_mode
|
154
159
|
|
155
160
|
@config_store.options_config = @options[:config] if @options[:config]
|
156
161
|
@config_store.force_default_config! if @options[:force_default_config]
|
@@ -174,6 +179,10 @@ module RuboCop
|
|
174
179
|
ConfigLoader.ignore_unrecognized_cops = @options[:ignore_unrecognized_cops]
|
175
180
|
end
|
176
181
|
|
182
|
+
def handle_editor_mode
|
183
|
+
RuboCop::LSP.enable if @options[:editor_mode]
|
184
|
+
end
|
185
|
+
|
177
186
|
# rubocop:disable Metrics/CyclomaticComplexity
|
178
187
|
def handle_exiting_options
|
179
188
|
return unless Options::EXITING_OPTIONS.any? { |o| @options.key? o }
|
data/lib/rubocop/config.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'pathname'
|
4
|
-
|
5
3
|
# FIXME: Moving Rails department code to RuboCop Rails will remove
|
6
4
|
# the following rubocop:disable comment.
|
7
5
|
# rubocop:disable Metrics/ClassLength
|
@@ -246,6 +244,10 @@ module RuboCop
|
|
246
244
|
end
|
247
245
|
end
|
248
246
|
|
247
|
+
def parser_engine
|
248
|
+
@parser_engine ||= for_all_cops.fetch('ParserEngine', :parser_whitequark).to_sym
|
249
|
+
end
|
250
|
+
|
249
251
|
def target_rails_version
|
250
252
|
@target_rails_version ||=
|
251
253
|
if for_all_cops['TargetRailsVersion']
|
@@ -261,6 +263,7 @@ module RuboCop
|
|
261
263
|
PathUtil.smart_path(@loaded_path)
|
262
264
|
end
|
263
265
|
|
266
|
+
# @return [String, nil]
|
264
267
|
def bundler_lock_file_path
|
265
268
|
return nil unless loaded_path
|
266
269
|
|
@@ -284,27 +287,48 @@ module RuboCop
|
|
284
287
|
end
|
285
288
|
end
|
286
289
|
|
290
|
+
# Returns target's locked gem versions (i.e. from Gemfile.lock or gems.locked)
|
291
|
+
# @returns [Hash{String => Gem::Version}] The locked gem versions, keyed by the gems' names.
|
292
|
+
def gem_versions_in_target
|
293
|
+
@gem_versions_in_target ||= read_gem_versions_from_target_lockfile
|
294
|
+
end
|
295
|
+
|
287
296
|
def inspect # :nodoc:
|
288
297
|
"#<#{self.class.name}:#{object_id} @loaded_path=#{loaded_path}>"
|
289
298
|
end
|
290
299
|
|
291
300
|
private
|
292
301
|
|
302
|
+
# @return [Float, nil] The Rails version as a `major.minor` Float.
|
293
303
|
def target_rails_version_from_bundler_lock_file
|
294
304
|
@target_rails_version_from_bundler_lock_file ||= read_rails_version_from_bundler_lock_file
|
295
305
|
end
|
296
306
|
|
307
|
+
# @return [Float, nil] The Rails version as a `major.minor` Float.
|
297
308
|
def read_rails_version_from_bundler_lock_file
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
309
|
+
return nil unless gem_versions_in_target
|
310
|
+
|
311
|
+
# Look for `railties` instead of `rails`, to support apps that only use a subset of `rails`
|
312
|
+
# See https://github.com/rubocop/rubocop/pull/11289
|
313
|
+
rails_version_in_target = gem_versions_in_target['railties']
|
314
|
+
return nil unless rails_version_in_target
|
315
|
+
|
316
|
+
gem_version_to_major_minor_float(rails_version_in_target)
|
317
|
+
end
|
318
|
+
|
319
|
+
# @param [Gem::Version] gem_version an object like `Gem::Version.new("7.1.2.3")`
|
320
|
+
# @return [Float] The major and minor version, like `7.1`
|
321
|
+
def gem_version_to_major_minor_float(gem_version)
|
322
|
+
segments = gem_version.segments
|
323
|
+
Float("#{segments[0]}.#{segments[1]}")
|
324
|
+
end
|
325
|
+
|
326
|
+
# @returns [Hash{String => Gem::Version}] The locked gem versions, keyed by the gems' names.
|
327
|
+
def read_gem_versions_from_target_lockfile
|
328
|
+
lockfile_path = bundler_lock_file_path
|
329
|
+
return nil unless lockfile_path
|
330
|
+
|
331
|
+
Lockfile.new(lockfile_path).gem_versions
|
308
332
|
end
|
309
333
|
|
310
334
|
def enable_cop?(qualified_cop_name, cop_options)
|
@@ -17,8 +17,8 @@ module RuboCop
|
|
17
17
|
attr_writer :project_root
|
18
18
|
|
19
19
|
def find_config_path(target_dir)
|
20
|
-
find_project_dotfile(target_dir) ||
|
21
|
-
DEFAULT_FILE
|
20
|
+
find_project_dotfile(target_dir) || find_project_root_dot_config ||
|
21
|
+
find_user_dotfile || find_user_xdg_config || DEFAULT_FILE
|
22
22
|
end
|
23
23
|
|
24
24
|
# Returns the path RuboCop inferred as the root of the project. No file
|
@@ -41,19 +41,29 @@ module RuboCop
|
|
41
41
|
find_file_upwards(DOTFILE, target_dir, project_root)
|
42
42
|
end
|
43
43
|
|
44
|
+
def find_project_root_dot_config
|
45
|
+
return unless project_root
|
46
|
+
|
47
|
+
dotfile = File.join(project_root, '.config', DOTFILE)
|
48
|
+
return dotfile if File.exist?(dotfile)
|
49
|
+
|
50
|
+
xdg_config = File.join(project_root, '.config', 'rubocop', XDG_CONFIG)
|
51
|
+
xdg_config if File.exist?(xdg_config)
|
52
|
+
end
|
53
|
+
|
44
54
|
def find_user_dotfile
|
45
55
|
return unless ENV.key?('HOME')
|
46
56
|
|
47
57
|
file = File.join(Dir.home, DOTFILE)
|
48
58
|
|
49
|
-
|
59
|
+
file if File.exist?(file)
|
50
60
|
end
|
51
61
|
|
52
62
|
def find_user_xdg_config
|
53
63
|
xdg_config_home = expand_path(ENV.fetch('XDG_CONFIG_HOME', '~/.config'))
|
54
64
|
xdg_config = File.join(xdg_config_home, 'rubocop', XDG_CONFIG)
|
55
65
|
|
56
|
-
|
66
|
+
xdg_config if File.exist?(xdg_config)
|
57
67
|
end
|
58
68
|
|
59
69
|
def expand_path(path)
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def violated?
|
22
|
-
config[cop]&.key?(parameter)
|
22
|
+
applies_to_current_ruby_version? && config[cop]&.key?(parameter)
|
23
23
|
end
|
24
24
|
|
25
25
|
def warning?
|
@@ -28,6 +28,14 @@ module RuboCop
|
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
+
def applies_to_current_ruby_version?
|
32
|
+
minimum_ruby_version = metadata['minimum_ruby_version']
|
33
|
+
|
34
|
+
return true unless minimum_ruby_version
|
35
|
+
|
36
|
+
config.target_ruby_version >= minimum_ruby_version
|
37
|
+
end
|
38
|
+
|
31
39
|
def alternative
|
32
40
|
metadata['alternative']
|
33
41
|
end
|
@@ -15,6 +15,8 @@ module RuboCop
|
|
15
15
|
'changed_parameters' => ChangedParameter,
|
16
16
|
'changed_enforced_styles' => ChangedEnforcedStyles
|
17
17
|
}.freeze
|
18
|
+
LOAD_RULES_CACHE = {} # rubocop:disable Style/MutableConstant
|
19
|
+
private_constant :LOAD_RULES_CACHE
|
18
20
|
|
19
21
|
attr_reader :rules, :warnings
|
20
22
|
|
@@ -48,16 +50,17 @@ module RuboCop
|
|
48
50
|
# Default rules for obsoletions are in config/obsoletion.yml
|
49
51
|
# Additional rules files can be added with `RuboCop::ConfigObsoletion.files << filename`
|
50
52
|
def load_rules # rubocop:disable Metrics/AbcSize
|
51
|
-
rules = self.class.files
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
rules = LOAD_RULES_CACHE[self.class.files] ||=
|
54
|
+
self.class.files.each_with_object({}) do |filename, hash|
|
55
|
+
hash.merge!(YAML.safe_load(File.read(filename)) || {}) do |_key, first, second|
|
56
|
+
case first
|
57
|
+
when Hash
|
58
|
+
first.merge(second)
|
59
|
+
when Array
|
60
|
+
first.concat(second)
|
61
|
+
end
|
58
62
|
end
|
59
63
|
end
|
60
|
-
end
|
61
64
|
|
62
65
|
cop_rules = rules.slice(*COP_RULE_CLASSES.keys)
|
63
66
|
parameter_rules = rules.slice(*PARAMETER_RULE_CLASSES.keys)
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'pathname'
|
4
|
-
|
5
3
|
module RuboCop
|
6
4
|
# Handles validation of configuration, for example cop names, parameter
|
7
5
|
# names, and Ruby versions.
|
@@ -20,6 +18,7 @@ module RuboCop
|
|
20
18
|
# @api private
|
21
19
|
CONFIG_CHECK_KEYS = %w[Enabled Safe SafeAutoCorrect AutoCorrect].to_set.freeze
|
22
20
|
CONFIG_CHECK_DEPARTMENTS = %w[pending override_department].freeze
|
21
|
+
CONFIG_CHECK_AUTOCORRECTS = %w[always contextual disabled].freeze
|
23
22
|
private_constant :CONFIG_CHECK_KEYS, :CONFIG_CHECK_DEPARTMENTS
|
24
23
|
|
25
24
|
def_delegators :@config, :smart_loaded_path, :for_all_cops
|
@@ -250,23 +249,31 @@ module RuboCop
|
|
250
249
|
end
|
251
250
|
end
|
252
251
|
|
252
|
+
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
253
253
|
def check_cop_config_value(hash, parent = nil)
|
254
254
|
hash.each do |key, value|
|
255
255
|
check_cop_config_value(value, key) if value.is_a?(Hash)
|
256
256
|
|
257
257
|
next unless CONFIG_CHECK_KEYS.include?(key) && value.is_a?(String)
|
258
258
|
|
259
|
-
|
259
|
+
if key == 'Enabled' && !CONFIG_CHECK_DEPARTMENTS.include?(value)
|
260
|
+
supposed_values = 'a boolean'
|
261
|
+
elsif key == 'AutoCorrect' && !CONFIG_CHECK_AUTOCORRECTS.include?(value)
|
262
|
+
supposed_values = '`always`, `contextual`, `disabled`, or a boolean'
|
263
|
+
else
|
264
|
+
next
|
265
|
+
end
|
260
266
|
|
261
|
-
raise ValidationError,
|
267
|
+
raise ValidationError, param_error_message(parent, key, value, supposed_values)
|
262
268
|
end
|
263
269
|
end
|
270
|
+
# rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
264
271
|
|
265
272
|
# FIXME: Handling colors in exception messages like this is ugly.
|
266
|
-
def
|
273
|
+
def param_error_message(parent, key, value, supposed_values)
|
267
274
|
"#{Rainbow('').reset}" \
|
268
|
-
"Property #{Rainbow(key).yellow} of
|
269
|
-
"is supposed to be
|
275
|
+
"Property #{Rainbow(key).yellow} of #{Rainbow(parent).yellow} cop " \
|
276
|
+
"is supposed to be #{supposed_values} and #{Rainbow(value).yellow} is not."
|
270
277
|
end
|
271
278
|
end
|
272
279
|
end
|
@@ -32,7 +32,12 @@ module RuboCop
|
|
32
32
|
# allow turning off autocorrect on a cop by cop basis
|
33
33
|
return true unless cop_config
|
34
34
|
|
35
|
-
|
35
|
+
# `false` is the same as `disabled` for backward compatibility.
|
36
|
+
return false if ['disabled', false].include?(cop_config['AutoCorrect'])
|
37
|
+
|
38
|
+
# When LSP is enabled, it is considered as editing source code,
|
39
|
+
# and autocorrection with `AutoCorrect: contextual` will not be performed.
|
40
|
+
return false if contextual_autocorrect? && LSP.enabled?
|
36
41
|
|
37
42
|
# :safe_autocorrect is a derived option based on several command-line
|
38
43
|
# arguments - see RuboCop::Options#add_autocorrection_options
|
@@ -82,7 +87,9 @@ module RuboCop
|
|
82
87
|
node.array_type? && node.percent_literal?
|
83
88
|
end
|
84
89
|
|
85
|
-
percent_array.map(&:source_range).find
|
90
|
+
percent_array.map(&:source_range).find do |range|
|
91
|
+
offense_range.begin_pos > range.begin_pos && range.overlaps?(offense_range)
|
92
|
+
end
|
86
93
|
end
|
87
94
|
|
88
95
|
def range_of_first_line(range)
|
data/lib/rubocop/cop/base.rb
CHANGED
@@ -53,23 +53,27 @@ module RuboCop
|
|
53
53
|
# List of cops that should not try to autocorrect at the same
|
54
54
|
# time as this cop
|
55
55
|
#
|
56
|
-
# @return [Array<RuboCop::Cop::
|
56
|
+
# @return [Array<RuboCop::Cop::Base>]
|
57
57
|
#
|
58
58
|
# @api public
|
59
59
|
def self.autocorrect_incompatible_with
|
60
60
|
[]
|
61
61
|
end
|
62
62
|
|
63
|
-
#
|
63
|
+
# Returns an url to view this cops documentation online.
|
64
|
+
# Requires 'DocumentationBaseURL' to be set for your department.
|
65
|
+
# Will follow the convention of RuboCops own documentation structure,
|
66
|
+
# overwrite this method to accommodate your custom layout.
|
64
67
|
# @return [String, nil]
|
65
68
|
#
|
66
69
|
# @api public
|
67
|
-
def self.documentation_url
|
68
|
-
Documentation.url_for(self)
|
70
|
+
def self.documentation_url(config = nil)
|
71
|
+
Documentation.url_for(self, config)
|
69
72
|
end
|
70
73
|
|
71
74
|
def self.inherited(subclass)
|
72
75
|
super
|
76
|
+
subclass.instance_variable_set(:@gem_requirements, gem_requirements.dup)
|
73
77
|
Registry.global.enlist(subclass)
|
74
78
|
end
|
75
79
|
|
@@ -126,6 +130,29 @@ module RuboCop
|
|
126
130
|
false
|
127
131
|
end
|
128
132
|
|
133
|
+
## Gem requirements
|
134
|
+
|
135
|
+
@gem_requirements = {}
|
136
|
+
|
137
|
+
class << self
|
138
|
+
attr_reader :gem_requirements
|
139
|
+
|
140
|
+
# Register a version requirement for the given gem name.
|
141
|
+
# This cop will be skipped unless the target satisfies *all* requirements.
|
142
|
+
# @param [String] gem_name
|
143
|
+
# @param [Array<String>] version_requirements The version requirements,
|
144
|
+
# using the same syntax as a Gemfile, e.g. ">= 1.2.3"
|
145
|
+
#
|
146
|
+
# If omitted, any version of the gem will be accepted.
|
147
|
+
#
|
148
|
+
# https://guides.rubygems.org/patterns/#declaring-dependencies
|
149
|
+
#
|
150
|
+
# @api public
|
151
|
+
def requires_gem(gem_name, *version_requirements)
|
152
|
+
@gem_requirements[gem_name] = Gem::Requirement.new(version_requirements)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
129
156
|
def initialize(config = nil, options = nil)
|
130
157
|
@config = config || Config.new
|
131
158
|
@options = options || { debug: false }
|
@@ -162,7 +189,9 @@ module RuboCop
|
|
162
189
|
def add_global_offense(message = nil, severity: nil)
|
163
190
|
severity = find_severity(nil, severity)
|
164
191
|
message = find_message(nil, message)
|
165
|
-
|
192
|
+
range = Offense::NO_LOCATION
|
193
|
+
status = enabled_line?(range.line) ? :unsupported : :disabled
|
194
|
+
current_offenses << Offense.new(severity, range, message, name, status)
|
166
195
|
end
|
167
196
|
|
168
197
|
# Adds an offense on the specified range (or node with an expression)
|
@@ -232,6 +261,10 @@ module RuboCop
|
|
232
261
|
@config.target_ruby_version
|
233
262
|
end
|
234
263
|
|
264
|
+
def parser_engine
|
265
|
+
@config.parser_engine
|
266
|
+
end
|
267
|
+
|
235
268
|
def target_rails_version
|
236
269
|
@config.target_rails_version
|
237
270
|
end
|
@@ -241,6 +274,7 @@ module RuboCop
|
|
241
274
|
end
|
242
275
|
|
243
276
|
def relevant_file?(file)
|
277
|
+
return false unless target_satisfies_all_gem_version_requirements?
|
244
278
|
return true unless @config.clusivity_config_for_badge?(self.class.badge)
|
245
279
|
|
246
280
|
file == RuboCop::AST::ProcessedSource::STRING_SOURCE_NAME ||
|
@@ -254,7 +288,7 @@ module RuboCop
|
|
254
288
|
|
255
289
|
# There should be very limited reasons for a Cop to do it's own parsing
|
256
290
|
def parse(source, path = nil)
|
257
|
-
ProcessedSource.new(source, target_ruby_version, path)
|
291
|
+
ProcessedSource.new(source, target_ruby_version, path, parser_engine: parser_engine)
|
258
292
|
end
|
259
293
|
|
260
294
|
# @api private
|
@@ -305,6 +339,17 @@ module RuboCop
|
|
305
339
|
@current_original = original
|
306
340
|
end
|
307
341
|
|
342
|
+
# @api private
|
343
|
+
def always_autocorrect?
|
344
|
+
# `true` is the same as `'always'` for backward compatibility.
|
345
|
+
['always', true].include?(cop_config.fetch('AutoCorrect', 'always'))
|
346
|
+
end
|
347
|
+
|
348
|
+
# @api private
|
349
|
+
def contextual_autocorrect?
|
350
|
+
cop_config.fetch('AutoCorrect', 'always') == 'contextual'
|
351
|
+
end
|
352
|
+
|
308
353
|
def inspect # :nodoc:
|
309
354
|
"#<#{self.class.name}:#{object_id} @config=#{@config} @options=#{@options}>"
|
310
355
|
end
|
@@ -356,16 +401,6 @@ module RuboCop
|
|
356
401
|
|
357
402
|
### Actually private methods
|
358
403
|
|
359
|
-
# rubocop:disable Layout/ClassStructure
|
360
|
-
def self.builtin?
|
361
|
-
return false unless (m = instance_methods(false).first) # any custom method will do
|
362
|
-
|
363
|
-
path, _line = instance_method(m).source_location
|
364
|
-
path.start_with?(__dir__)
|
365
|
-
end
|
366
|
-
private_class_method :builtin?
|
367
|
-
# rubocop:enable Layout/ClassStructure
|
368
|
-
|
369
404
|
def reset_investigation
|
370
405
|
@currently_disabled_lines = @current_offenses = @processed_source = @current_corrector = nil
|
371
406
|
end
|
@@ -389,7 +424,7 @@ module RuboCop
|
|
389
424
|
def use_corrector(range, corrector)
|
390
425
|
if autocorrect?
|
391
426
|
attempt_correction(range, corrector)
|
392
|
-
elsif corrector &&
|
427
|
+
elsif corrector && (always_autocorrect? || (contextual_autocorrect? && !LSP.enabled?))
|
393
428
|
:uncorrected
|
394
429
|
else
|
395
430
|
:unsupported
|
@@ -481,6 +516,18 @@ module RuboCop
|
|
481
516
|
range.end_pos + @current_offset
|
482
517
|
)
|
483
518
|
end
|
519
|
+
|
520
|
+
def target_satisfies_all_gem_version_requirements?
|
521
|
+
self.class.gem_requirements.all? do |gem_name, version_req|
|
522
|
+
all_gem_versions_in_target = @config.gem_versions_in_target
|
523
|
+
next false unless all_gem_versions_in_target
|
524
|
+
|
525
|
+
gem_version_in_target = all_gem_versions_in_target[gem_name]
|
526
|
+
next false unless gem_version_in_target
|
527
|
+
|
528
|
+
version_req.satisfied_by?(gem_version_in_target)
|
529
|
+
end
|
530
|
+
end
|
484
531
|
end
|
485
532
|
end
|
486
533
|
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Bundler
|
6
|
+
# A Gem group, or a set of groups, should be listed only once in a Gemfile.
|
7
|
+
#
|
8
|
+
# For example, if the values of `source`, `git`, `platforms`, or `path`
|
9
|
+
# surrounding `group` are different, no offense will be registered:
|
10
|
+
#
|
11
|
+
# [source,ruby]
|
12
|
+
# -----
|
13
|
+
# platforms :ruby do
|
14
|
+
# group :default do
|
15
|
+
# gem 'openssl'
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# platforms :jruby do
|
20
|
+
# group :default do
|
21
|
+
# gem 'jruby-openssl'
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# -----
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# # bad
|
28
|
+
# group :development do
|
29
|
+
# gem 'rubocop'
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# group :development do
|
33
|
+
# gem 'rubocop-rails'
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# # bad (same set of groups declared twice)
|
37
|
+
# group :development, :test do
|
38
|
+
# gem 'rubocop'
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# group :test, :development do
|
42
|
+
# gem 'rspec'
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# # good
|
46
|
+
# group :development do
|
47
|
+
# gem 'rubocop'
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# group :development, :test do
|
51
|
+
# gem 'rspec'
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# # good
|
55
|
+
# gem 'rubocop', groups: [:development, :test]
|
56
|
+
# gem 'rspec', groups: [:development, :test]
|
57
|
+
#
|
58
|
+
class DuplicatedGroup < Base
|
59
|
+
include RangeHelp
|
60
|
+
|
61
|
+
MSG = 'Gem group `%<group_name>s` already defined on line ' \
|
62
|
+
'%<line_of_first_occurrence>d of the Gemfile.'
|
63
|
+
SOURCE_BLOCK_NAMES = %i[source git platforms path].freeze
|
64
|
+
|
65
|
+
# @!method group_declarations(node)
|
66
|
+
def_node_search :group_declarations, '(send nil? :group ...)'
|
67
|
+
|
68
|
+
def on_new_investigation
|
69
|
+
return if processed_source.blank?
|
70
|
+
|
71
|
+
duplicated_group_nodes.each do |nodes|
|
72
|
+
nodes[1..].each do |node|
|
73
|
+
group_name = node.arguments.map(&:source).join(', ')
|
74
|
+
|
75
|
+
register_offense(node, group_name, nodes.first.first_line)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def duplicated_group_nodes
|
83
|
+
group_declarations = group_declarations(processed_source.ast)
|
84
|
+
group_keys = group_declarations.group_by do |node|
|
85
|
+
source_key = find_source_key(node)
|
86
|
+
group_attributes = group_attributes(node).sort.join
|
87
|
+
|
88
|
+
"#{source_key}#{group_attributes}"
|
89
|
+
end
|
90
|
+
|
91
|
+
group_keys.values.select { |nodes| nodes.size > 1 }
|
92
|
+
end
|
93
|
+
|
94
|
+
def register_offense(node, group_name, line_of_first_occurrence)
|
95
|
+
line_range = node.loc.column...node.loc.last_column
|
96
|
+
offense_location = source_range(processed_source.buffer, node.first_line, line_range)
|
97
|
+
message = format(
|
98
|
+
MSG,
|
99
|
+
group_name: group_name,
|
100
|
+
line_of_first_occurrence: line_of_first_occurrence
|
101
|
+
)
|
102
|
+
add_offense(offense_location, message: message)
|
103
|
+
end
|
104
|
+
|
105
|
+
def find_source_key(node)
|
106
|
+
source_block = node.each_ancestor(:block).find do |block_node|
|
107
|
+
SOURCE_BLOCK_NAMES.include?(block_node.method_name)
|
108
|
+
end
|
109
|
+
|
110
|
+
return unless source_block
|
111
|
+
|
112
|
+
"#{source_block.method_name}#{source_block.send_node.first_argument&.source}"
|
113
|
+
end
|
114
|
+
|
115
|
+
def group_attributes(node)
|
116
|
+
node.arguments.map do |argument|
|
117
|
+
if argument.hash_type?
|
118
|
+
argument.pairs.map(&:source).sort.join(', ')
|
119
|
+
else
|
120
|
+
argument.respond_to?(:value) ? argument.value.to_s : argument.source
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -161,9 +161,9 @@ module RuboCop
|
|
161
161
|
end
|
162
162
|
|
163
163
|
def gem_options(node)
|
164
|
-
return [] unless node.
|
164
|
+
return [] unless node.last_argument&.type == :hash
|
165
165
|
|
166
|
-
node.
|
166
|
+
node.last_argument.keys.map(&:value)
|
167
167
|
end
|
168
168
|
end
|
169
169
|
end
|
@@ -90,13 +90,11 @@ module RuboCop
|
|
90
90
|
Array(cop_config['AllowedGems'])
|
91
91
|
end
|
92
92
|
|
93
|
-
def message(
|
94
|
-
gem_specification = range.source
|
95
|
-
|
93
|
+
def message(_range)
|
96
94
|
if required_style?
|
97
|
-
|
95
|
+
REQUIRED_MSG
|
98
96
|
elsif forbidden_style?
|
99
|
-
|
97
|
+
FORBIDDEN_MSG
|
100
98
|
end
|
101
99
|
end
|
102
100
|
|
@@ -19,7 +19,15 @@ module RuboCop
|
|
19
19
|
#
|
20
20
|
# gem 'rspec'
|
21
21
|
#
|
22
|
-
#
|
22
|
+
# @example TreatCommentsAsGroupSeparators: true (default)
|
23
|
+
# # good
|
24
|
+
# # For code quality
|
25
|
+
# gem 'rubocop'
|
26
|
+
# # For tests
|
27
|
+
# gem 'rspec'
|
28
|
+
#
|
29
|
+
# @example TreatCommentsAsGroupSeparators: false
|
30
|
+
# # bad
|
23
31
|
# # For code quality
|
24
32
|
# gem 'rubocop'
|
25
33
|
# # For tests
|
@@ -34,18 +34,14 @@ module RuboCop
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def offending_range
|
37
|
+
begin_range = block_node.source_range.begin
|
38
|
+
|
37
39
|
if block_node.arguments?
|
38
|
-
|
40
|
+
begin_range.join(argument_node.source_range.end)
|
39
41
|
else
|
40
|
-
|
42
|
+
begin_range.join(block_node.loc.begin.end)
|
41
43
|
end
|
42
44
|
end
|
43
|
-
|
44
|
-
def replacement_range(end_pos)
|
45
|
-
Parser::Source::Range.new(block_node.source_range.source_buffer,
|
46
|
-
block_node.source_range.begin_pos,
|
47
|
-
end_pos)
|
48
|
-
end
|
49
45
|
end
|
50
46
|
end
|
51
47
|
end
|