rubocop 1.57.1 → 1.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +4 -5
- data/assets/output.css.erb +159 -0
- data/assets/output.html.erb +1 -160
- data/config/default.yml +136 -19
- 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 +10 -1
- data/lib/rubocop/config.rb +36 -12
- data/lib/rubocop/config_finder.rb +12 -2
- data/lib/rubocop/config_loader.rb +1 -2
- data/lib/rubocop/config_loader_resolver.rb +9 -3
- data/lib/rubocop/config_obsoletion.rb +11 -8
- data/lib/rubocop/config_validator.rb +14 -7
- data/lib/rubocop/cop/autocorrect_logic.rb +6 -1
- data/lib/rubocop/cop/base.rb +63 -16
- data/lib/rubocop/cop/bundler/gem_comment.rb +2 -2
- data/lib/rubocop/cop/bundler/gem_version.rb +3 -5
- data/lib/rubocop/cop/cop.rb +20 -2
- 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/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/add_runtime_dependency.rb +38 -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/duplicated_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +5 -1
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +3 -3
- data/lib/rubocop/cop/internal_affairs/example_description.rb +6 -5
- 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.rb +2 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/empty_comment.rb +3 -1
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +14 -7
- data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +1 -1
- 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_argument_indentation.rb +2 -2
- 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 +2 -2
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +20 -20
- data/lib/rubocop/cop/layout/redundant_line_break.rb +16 -3
- 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_around_operators.rb +53 -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_string_interpolation.rb +3 -4
- data/lib/rubocop/cop/legacy/corrector.rb +12 -2
- 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 +29 -3
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +2 -2
- data/lib/rubocop/cop/lint/empty_when.rb +1 -1
- 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/implicit_string_concatenation.rb +14 -7
- data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +56 -0
- data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -1
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +85 -0
- data/lib/rubocop/cop/lint/mixed_case_range.rb +9 -4
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +6 -21
- 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_safe_navigation.rb +54 -6
- 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 +3 -4
- 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/symbol_conversion.rb +7 -2
- data/lib/rubocop/cop/lint/syntax.rb +6 -3
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -3
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -1
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +3 -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_times.rb +2 -2
- data/lib/rubocop/cop/lint/void.rb +53 -12
- data/lib/rubocop/cop/metrics/abc_size.rb +3 -3
- data/lib/rubocop/cop/metrics/block_nesting.rb +19 -7
- data/lib/rubocop/cop/metrics/class_length.rb +6 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +5 -5
- data/lib/rubocop/cop/mixin/alignment.rb +5 -1
- data/lib/rubocop/cop/mixin/allowed_methods.rb +7 -1
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +15 -3
- 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/configurable_max.rb +5 -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 +1 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/rescue_node.rb +4 -0
- 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/naming/block_forwarding.rb +34 -7
- data/lib/rubocop/cop/naming/constant_name.rb +1 -2
- data/lib/rubocop/cop/naming/file_name.rb +2 -2
- 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 +1 -0
- data/lib/rubocop/cop/style/arguments_forwarding.rb +155 -21
- data/lib/rubocop/cop/style/array_first_last.rb +64 -0
- 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/case_like_if.rb +5 -5
- data/lib/rubocop/cop/style/class_check.rb +1 -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/combinable_loops.rb +13 -7
- data/lib/rubocop/cop/style/commented_keyword.rb +5 -2
- data/lib/rubocop/cop/style/concat_array_literals.rb +1 -0
- 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_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 +2 -0
- data/lib/rubocop/cop/style/format_string.rb +9 -9
- data/lib/rubocop/cop/style/hash_each_methods.rb +105 -11
- data/lib/rubocop/cop/style/hash_except.rb +10 -6
- data/lib/rubocop/cop/style/hash_syntax.rb +24 -2
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +12 -1
- 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/map_compact_with_conditional_block.rb +82 -50
- 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 +19 -5
- 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/multiline_method_signature.rb +10 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +5 -3
- 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/operator_method_call.rb +2 -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/quoted_symbols.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +4 -1
- data/lib/rubocop/cop/style/redundant_argument.rb +27 -3
- data/lib/rubocop/cop/style/redundant_assignment.rb +10 -2
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +5 -4
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +17 -10
- data/lib/rubocop/cop/style/redundant_each.rb +7 -4
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +3 -3
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -1
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +5 -4
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +19 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +50 -19
- data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +7 -1
- data/lib/rubocop/cop/style/redundant_self.rb +17 -2
- 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/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 -0
- data/lib/rubocop/cop/style/send.rb +4 -4
- data/lib/rubocop/cop/style/send_with_literal_method_name.rb +104 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +7 -3
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +3 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +76 -10
- 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/strip.rb +7 -4
- data/lib/rubocop/cop/style/super_arguments.rb +174 -0
- data/lib/rubocop/cop/style/super_with_args_parentheses.rb +35 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +75 -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/zero_length_predicate.rb +28 -24
- data/lib/rubocop/cop/team.rb +13 -0
- data/lib/rubocop/cop/util.rb +7 -1
- data/lib/rubocop/cop/utils/regexp_ranges.rb +1 -1
- data/lib/rubocop/cops_documentation_generator.rb +16 -4
- data/lib/rubocop/directive_comment.rb +10 -8
- data/lib/rubocop/ext/regexp_node.rb +9 -4
- data/lib/rubocop/ext/regexp_parser.rb +4 -21
- 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 +37 -14
- data/lib/rubocop/formatter/json_formatter.rb +0 -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 +12 -15
- data/lib/rubocop/lsp/runtime.rb +1 -1
- data/lib/rubocop/lsp/server.rb +7 -2
- data/lib/rubocop/lsp/severity.rb +1 -1
- data/lib/rubocop/lsp.rb +36 -0
- data/lib/rubocop/magic_comment.rb +1 -1
- 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 +0 -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 +73 -16
- data/lib/rubocop/rspec/support.rb +3 -0
- data/lib/rubocop/runner.rb +14 -3
- data/lib/rubocop/server/cache.rb +11 -2
- data/lib/rubocop/server/client_command/exec.rb +2 -3
- data/lib/rubocop/server/client_command/start.rb +1 -1
- data/lib/rubocop/server/core.rb +4 -0
- data/lib/rubocop/server/server_command/exec.rb +0 -1
- data/lib/rubocop/target_finder.rb +84 -78
- data/lib/rubocop/target_ruby.rb +82 -80
- data/lib/rubocop/version.rb +19 -4
- data/lib/rubocop.rb +8 -0
- metadata +27 -29
- /data/lib/rubocop/formatter/{git_hub_actions_formatter.rb → github_actions_formatter.rb} +0 -0
|
@@ -49,19 +49,13 @@ module RuboCop
|
|
|
49
49
|
|
|
50
50
|
private
|
|
51
51
|
|
|
52
|
-
def aligned_locations(locs)
|
|
52
|
+
def aligned_locations(locs)
|
|
53
53
|
return [] if locs.empty?
|
|
54
54
|
|
|
55
|
-
aligned = Set
|
|
56
|
-
locs.each_cons(
|
|
57
|
-
|
|
58
|
-
aligned << loc.line if col == before.column || col == after.column
|
|
55
|
+
aligned = Set.new
|
|
56
|
+
locs.each_cons(2) do |loc1, loc2|
|
|
57
|
+
aligned << loc1.line << loc2.line if loc1.column == loc2.column
|
|
59
58
|
end
|
|
60
|
-
|
|
61
|
-
# if locs.size > 2 and the size of variable `aligned`
|
|
62
|
-
# has not increased from its initial value, there are not aligned lines.
|
|
63
|
-
return [] if locs.size > 2 && aligned.size == 2
|
|
64
|
-
|
|
65
59
|
aligned
|
|
66
60
|
end
|
|
67
61
|
|
|
@@ -118,8 +118,8 @@ module RuboCop
|
|
|
118
118
|
#
|
|
119
119
|
# @example EnforcedStyle: special_for_inner_method_call
|
|
120
120
|
# # The first argument should normally be indented one step more than
|
|
121
|
-
# # the preceding line, but if it's
|
|
122
|
-
# # is itself
|
|
121
|
+
# # the preceding line, but if it's an argument for a method call that
|
|
122
|
+
# # is itself an argument in a method call, then the inner argument
|
|
123
123
|
# # should be indented relative to the inner method.
|
|
124
124
|
#
|
|
125
125
|
# # good
|
|
@@ -5,7 +5,10 @@ module RuboCop
|
|
|
5
5
|
module Layout
|
|
6
6
|
# Checks the indentation of the first element in an array literal
|
|
7
7
|
# where the opening bracket and the first element are on separate lines.
|
|
8
|
-
# The other elements' indentations are handled by
|
|
8
|
+
# The other elements' indentations are handled by `Layout/ArrayAlignment` cop.
|
|
9
|
+
#
|
|
10
|
+
# This cop will respect `Layout/ArrayAlignment` and will not work when
|
|
11
|
+
# `EnforcedStyle: with_fixed_indentation` is specified for `Layout/ArrayAlignment`.
|
|
9
12
|
#
|
|
10
13
|
# By default, array literals that are arguments in a method call with
|
|
11
14
|
# parentheses, and where the opening square bracket of the array is on the
|
|
@@ -25,7 +28,7 @@ module RuboCop
|
|
|
25
28
|
# # element are on separate lines is indented one step (two spaces) more
|
|
26
29
|
# # than the position inside the opening parenthesis.
|
|
27
30
|
#
|
|
28
|
-
# #bad
|
|
31
|
+
# # bad
|
|
29
32
|
# array = [
|
|
30
33
|
# :value
|
|
31
34
|
# ]
|
|
@@ -33,7 +36,7 @@ module RuboCop
|
|
|
33
36
|
# :no_difference
|
|
34
37
|
# ])
|
|
35
38
|
#
|
|
36
|
-
# #good
|
|
39
|
+
# # good
|
|
37
40
|
# array = [
|
|
38
41
|
# :value
|
|
39
42
|
# ]
|
|
@@ -47,7 +50,7 @@ module RuboCop
|
|
|
47
50
|
# # separate lines is indented the same as an array literal which is not
|
|
48
51
|
# # defined inside a method call.
|
|
49
52
|
#
|
|
50
|
-
# #bad
|
|
53
|
+
# # bad
|
|
51
54
|
# # consistent
|
|
52
55
|
# array = [
|
|
53
56
|
# :value
|
|
@@ -56,7 +59,7 @@ module RuboCop
|
|
|
56
59
|
# :its_like_this
|
|
57
60
|
# ])
|
|
58
61
|
#
|
|
59
|
-
# #good
|
|
62
|
+
# # good
|
|
60
63
|
# array = [
|
|
61
64
|
# :value
|
|
62
65
|
# ]
|
|
@@ -68,13 +71,13 @@ module RuboCop
|
|
|
68
71
|
# # The `align_brackets` style enforces that the opening and closing
|
|
69
72
|
# # brackets are indented to the same position.
|
|
70
73
|
#
|
|
71
|
-
# #bad
|
|
74
|
+
# # bad
|
|
72
75
|
# # align_brackets
|
|
73
76
|
# and_now_for_something = [
|
|
74
77
|
# :completely_different
|
|
75
78
|
# ]
|
|
76
79
|
#
|
|
77
|
-
# #good
|
|
80
|
+
# # good
|
|
78
81
|
# # align_brackets
|
|
79
82
|
# and_now_for_something = [
|
|
80
83
|
# :completely_different
|
|
@@ -89,10 +92,14 @@ module RuboCop
|
|
|
89
92
|
'in an array, relative to %<base_description>s.'
|
|
90
93
|
|
|
91
94
|
def on_array(node)
|
|
95
|
+
return if style != :consistent && enforce_first_argument_with_fixed_indentation?
|
|
96
|
+
|
|
92
97
|
check(node, nil) if node.loc.begin
|
|
93
98
|
end
|
|
94
99
|
|
|
95
100
|
def on_send(node)
|
|
101
|
+
return if style != :consistent && enforce_first_argument_with_fixed_indentation?
|
|
102
|
+
|
|
96
103
|
each_argument_node(node, :array) do |array_node, left_parenthesis|
|
|
97
104
|
check(array_node, left_parenthesis)
|
|
98
105
|
end
|
|
@@ -174,6 +181,16 @@ module RuboCop
|
|
|
174
181
|
'where the left bracket is.'
|
|
175
182
|
end
|
|
176
183
|
end
|
|
184
|
+
|
|
185
|
+
def enforce_first_argument_with_fixed_indentation?
|
|
186
|
+
return false unless array_alignment_config['Enabled']
|
|
187
|
+
|
|
188
|
+
array_alignment_config['EnforcedStyle'] == 'with_fixed_indentation'
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def array_alignment_config
|
|
192
|
+
config.for_cop('Layout/ArrayAlignment')
|
|
193
|
+
end
|
|
177
194
|
end
|
|
178
195
|
end
|
|
179
196
|
end
|
|
@@ -72,7 +72,7 @@ module RuboCop
|
|
|
72
72
|
return if ignored_node?(def_node)
|
|
73
73
|
|
|
74
74
|
left_parenthesis = def_node.arguments.loc.begin
|
|
75
|
-
first_elem = def_node.
|
|
75
|
+
first_elem = def_node.first_argument
|
|
76
76
|
return unless first_elem
|
|
77
77
|
return if same_line?(first_elem, left_parenthesis)
|
|
78
78
|
|
|
@@ -182,7 +182,7 @@ module RuboCop
|
|
|
182
182
|
end
|
|
183
183
|
|
|
184
184
|
def add_correct_closing_paren(node, corrector)
|
|
185
|
-
corrector.insert_after(node.
|
|
185
|
+
corrector.insert_after(node.last_argument, ')')
|
|
186
186
|
end
|
|
187
187
|
|
|
188
188
|
def remove_incorrect_closing_paren(node, corrector)
|
|
@@ -271,7 +271,7 @@ module RuboCop
|
|
|
271
271
|
def add_correct_external_trailing_comma(node, corrector)
|
|
272
272
|
return unless external_trailing_comma?(node)
|
|
273
273
|
|
|
274
|
-
corrector.insert_after(node.
|
|
274
|
+
corrector.insert_after(node.last_argument, ',')
|
|
275
275
|
end
|
|
276
276
|
|
|
277
277
|
def remove_incorrect_external_trailing_comma(node, corrector)
|
|
@@ -6,9 +6,9 @@ module RuboCop
|
|
|
6
6
|
# Checks the indentation of the here document bodies. The bodies
|
|
7
7
|
# are indented one step.
|
|
8
8
|
#
|
|
9
|
-
#
|
|
9
|
+
# NOTE: When ``Layout/LineLength``'s `AllowHeredoc` is false (not default),
|
|
10
10
|
# this cop does not add any offenses for long here documents to
|
|
11
|
-
# avoid
|
|
11
|
+
# avoid ``Layout/LineLength``'s offenses.
|
|
12
12
|
#
|
|
13
13
|
# @example
|
|
14
14
|
# # bad
|
|
@@ -107,7 +107,7 @@ module RuboCop
|
|
|
107
107
|
return false unless line.end_with?("\\\n")
|
|
108
108
|
|
|
109
109
|
# Ensure backslash isn't part of a token spanning to the next line.
|
|
110
|
-
node.children.none? { |c| c.first_line
|
|
110
|
+
node.children.none? { |c| (c.first_line...c.last_line).cover?(line_num) && c.multiline? }
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
def autocorrect(corrector, offense_range, insert_pos, spaces)
|
|
@@ -17,29 +17,29 @@ module RuboCop
|
|
|
17
17
|
# split across lines. These include arrays, hashes, and
|
|
18
18
|
# method calls with argument lists.
|
|
19
19
|
#
|
|
20
|
-
# If autocorrection is enabled, the following
|
|
20
|
+
# If autocorrection is enabled, the following cops
|
|
21
21
|
# are recommended to further format the broken lines.
|
|
22
22
|
# (Many of these are enabled by default.)
|
|
23
23
|
#
|
|
24
|
-
# * ArgumentAlignment
|
|
25
|
-
# * ArrayAlignment
|
|
26
|
-
# * BlockAlignment
|
|
27
|
-
# *
|
|
28
|
-
# *
|
|
29
|
-
# *
|
|
30
|
-
# *
|
|
31
|
-
# *
|
|
32
|
-
# *
|
|
33
|
-
# *
|
|
34
|
-
# *
|
|
35
|
-
# *
|
|
36
|
-
# *
|
|
37
|
-
# *
|
|
38
|
-
# *
|
|
39
|
-
# *
|
|
40
|
-
# *
|
|
41
|
-
# *
|
|
42
|
-
# *
|
|
24
|
+
# * `Layout/ArgumentAlignment`
|
|
25
|
+
# * `Layout/ArrayAlignment`
|
|
26
|
+
# * `Layout/BlockAlignment`
|
|
27
|
+
# * `Layout/BlockEndNewline`
|
|
28
|
+
# * `LayoutClosingParenthesisIndentation`
|
|
29
|
+
# * `LayoutFirstArgumentIndentation`
|
|
30
|
+
# * `LayoutFirstArrayElementIndentation`
|
|
31
|
+
# * `LayoutFirstHashElementIndentation`
|
|
32
|
+
# * `LayoutFirstParameterIndentation`
|
|
33
|
+
# * `LayoutHashAlignment`
|
|
34
|
+
# * `LayoutIndentationWidth`
|
|
35
|
+
# * `LayoutMultilineArrayLineBreaks`
|
|
36
|
+
# * `LayoutMultilineBlockLayout`
|
|
37
|
+
# * `LayoutMultilineHashBraceLayout`
|
|
38
|
+
# * `LayoutMultilineHashKeyLineBreaks`
|
|
39
|
+
# * `LayoutMultilineMethodArgumentLineBreaks`
|
|
40
|
+
# * `LayoutMultilineMethodParameterLineBreaks`
|
|
41
|
+
# * `Layout/ParameterAlignment`
|
|
42
|
+
# * `Style/BlockDelimiters`
|
|
43
43
|
#
|
|
44
44
|
# Together, these cops will pretty print hashes, arrays,
|
|
45
45
|
# method calls, etc. For example, let's say the max columns
|
|
@@ -62,6 +62,7 @@ module RuboCop
|
|
|
62
62
|
|
|
63
63
|
register_offense(node)
|
|
64
64
|
end
|
|
65
|
+
alias on_csend on_send
|
|
65
66
|
|
|
66
67
|
private
|
|
67
68
|
|
|
@@ -83,8 +84,20 @@ module RuboCop
|
|
|
83
84
|
end
|
|
84
85
|
|
|
85
86
|
def offense?(node)
|
|
86
|
-
node.multiline?
|
|
87
|
-
|
|
87
|
+
return false if !node.multiline? || too_long?(node) || !suitable_as_single_line?(node)
|
|
88
|
+
return require_backslash?(node) if node.and_type? || node.or_type?
|
|
89
|
+
|
|
90
|
+
!index_access_call_chained?(node) && !configured_to_not_be_inspected?(node)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def require_backslash?(node)
|
|
94
|
+
processed_source.lines[node.loc.operator.line - 1].end_with?('\\')
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def index_access_call_chained?(node)
|
|
98
|
+
return false unless node.send_type? && node.method?(:[])
|
|
99
|
+
|
|
100
|
+
node.children.first.send_type? && node.children.first.method?(:[])
|
|
88
101
|
end
|
|
89
102
|
|
|
90
103
|
def configured_to_not_be_inspected?(node)
|
|
@@ -135,7 +148,7 @@ module RuboCop
|
|
|
135
148
|
.gsub(/" *\\\n\s*'/, %q(" + ')) # Double quote, backslash, and then single quote
|
|
136
149
|
.gsub(/' *\\\n\s*"/, %q(' + ")) # Single quote, backslash, and then double quote
|
|
137
150
|
.gsub(/(["']) *\\\n\s*\1/, '') # Double or single quote, backslash, then same quote
|
|
138
|
-
.gsub(/\n\s*(
|
|
151
|
+
.gsub(/\n\s*(?=(&)?\.\w)/, '') # Extra space within method chaining which includes `&.`
|
|
139
152
|
.gsub(/\s*\\?\n\s*/, ' ') # Any other line break, with or without backslash
|
|
140
153
|
end
|
|
141
154
|
|
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
|
29
29
|
MSG = '`%<kw_loc>s` at %<kw_loc_line>d, %<kw_loc_column>d is not ' \
|
|
30
30
|
'aligned with `%<beginning>s` at ' \
|
|
31
31
|
'%<begin_loc_line>d, %<begin_loc_column>d.'
|
|
32
|
-
ANCESTOR_TYPES = %i[kwbegin def defs class module block].freeze
|
|
32
|
+
ANCESTOR_TYPES = %i[kwbegin def defs class module block numblock].freeze
|
|
33
33
|
ANCESTOR_TYPES_WITH_ACCESS_MODIFIERS = %i[def defs].freeze
|
|
34
34
|
ALTERNATIVE_ACCESS_MODIFIERS = %i[public_class_method private_class_method].freeze
|
|
35
35
|
|
|
@@ -95,7 +95,7 @@ module RuboCop
|
|
|
95
95
|
def alignment_source(node, starting_loc)
|
|
96
96
|
ending_loc =
|
|
97
97
|
case node.type
|
|
98
|
-
when :block, :kwbegin
|
|
98
|
+
when :block, :numblock, :kwbegin
|
|
99
99
|
node.loc.begin
|
|
100
100
|
when :def, :defs, :class, :module,
|
|
101
101
|
:lvasgn, :ivasgn, :cvasgn, :gvasgn, :casgn
|
|
@@ -104,8 +104,8 @@ module RuboCop
|
|
|
104
104
|
mlhs_node, = *node
|
|
105
105
|
mlhs_node.source_range
|
|
106
106
|
else
|
|
107
|
-
# It is a wrapper with access modifier.
|
|
108
|
-
node.child_nodes.first.loc.name
|
|
107
|
+
# It is a wrapper with receiver of object attribute or access modifier.
|
|
108
|
+
node.receiver&.source_range || node.child_nodes.first.loc.name
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
range_between(starting_loc.begin_pos, ending_loc.end_pos).source
|
|
@@ -25,10 +25,15 @@ module RuboCop
|
|
|
25
25
|
|
|
26
26
|
MSG = 'Put method call on a separate line if chained to a single line block.'
|
|
27
27
|
|
|
28
|
+
def self.autocorrect_incompatible_with
|
|
29
|
+
[Style::MapToHash]
|
|
30
|
+
end
|
|
31
|
+
|
|
28
32
|
def on_send(node)
|
|
29
33
|
range = offending_range(node)
|
|
30
34
|
add_offense(range) { |corrector| corrector.insert_before(range, "\n") } if range
|
|
31
35
|
end
|
|
36
|
+
alias on_csend on_send
|
|
32
37
|
|
|
33
38
|
private
|
|
34
39
|
|
|
@@ -50,6 +50,20 @@ module RuboCop
|
|
|
50
50
|
#
|
|
51
51
|
# # good
|
|
52
52
|
# a ** b
|
|
53
|
+
#
|
|
54
|
+
# @example EnforcedStyleForRationalLiterals: no_space (default)
|
|
55
|
+
# # bad
|
|
56
|
+
# 1 / 48r
|
|
57
|
+
#
|
|
58
|
+
# # good
|
|
59
|
+
# 1/48r
|
|
60
|
+
#
|
|
61
|
+
# @example EnforcedStyleForRationalLiterals: space
|
|
62
|
+
# # bad
|
|
63
|
+
# 1/48r
|
|
64
|
+
#
|
|
65
|
+
# # good
|
|
66
|
+
# 1 / 48r
|
|
53
67
|
class SpaceAroundOperators < Base
|
|
54
68
|
include PrecedingFollowingAlignment
|
|
55
69
|
include RangeHelp
|
|
@@ -64,7 +78,7 @@ module RuboCop
|
|
|
64
78
|
end
|
|
65
79
|
|
|
66
80
|
def on_sclass(node)
|
|
67
|
-
check_operator(:sclass, node.loc.operator, node
|
|
81
|
+
check_operator(:sclass, node.loc.operator, node)
|
|
68
82
|
end
|
|
69
83
|
|
|
70
84
|
def on_pair(node)
|
|
@@ -72,14 +86,14 @@ module RuboCop
|
|
|
72
86
|
|
|
73
87
|
return if hash_table_style? && !node.parent.pairs_on_same_line?
|
|
74
88
|
|
|
75
|
-
check_operator(:pair, node.loc.operator, node
|
|
89
|
+
check_operator(:pair, node.loc.operator, node)
|
|
76
90
|
end
|
|
77
91
|
|
|
78
92
|
def on_if(node)
|
|
79
93
|
return unless node.ternary?
|
|
80
94
|
|
|
81
|
-
check_operator(:if, node.loc.question, node.if_branch
|
|
82
|
-
check_operator(:if, node.loc.colon, node.else_branch
|
|
95
|
+
check_operator(:if, node.loc.question, node.if_branch)
|
|
96
|
+
check_operator(:if, node.loc.colon, node.else_branch)
|
|
83
97
|
end
|
|
84
98
|
|
|
85
99
|
def on_resbody(node)
|
|
@@ -87,7 +101,7 @@ module RuboCop
|
|
|
87
101
|
|
|
88
102
|
_, variable, = *node
|
|
89
103
|
|
|
90
|
-
check_operator(:resbody, node.loc.assoc, variable
|
|
104
|
+
check_operator(:resbody, node.loc.assoc, variable)
|
|
91
105
|
end
|
|
92
106
|
|
|
93
107
|
def on_send(node)
|
|
@@ -96,7 +110,7 @@ module RuboCop
|
|
|
96
110
|
if node.setter_method?
|
|
97
111
|
on_special_asgn(node)
|
|
98
112
|
elsif regular_operator?(node)
|
|
99
|
-
check_operator(:send, node.loc.selector, node.first_argument
|
|
113
|
+
check_operator(:send, node.loc.selector, node.first_argument)
|
|
100
114
|
end
|
|
101
115
|
end
|
|
102
116
|
|
|
@@ -105,7 +119,7 @@ module RuboCop
|
|
|
105
119
|
|
|
106
120
|
return unless rhs
|
|
107
121
|
|
|
108
|
-
check_operator(:assignment, node.loc.operator, rhs
|
|
122
|
+
check_operator(:assignment, node.loc.operator, rhs)
|
|
109
123
|
end
|
|
110
124
|
|
|
111
125
|
def on_casgn(node)
|
|
@@ -113,7 +127,7 @@ module RuboCop
|
|
|
113
127
|
|
|
114
128
|
return unless right
|
|
115
129
|
|
|
116
|
-
check_operator(:assignment, node.loc.operator, right
|
|
130
|
+
check_operator(:assignment, node.loc.operator, right)
|
|
117
131
|
end
|
|
118
132
|
|
|
119
133
|
def on_binary(node)
|
|
@@ -121,7 +135,7 @@ module RuboCop
|
|
|
121
135
|
|
|
122
136
|
return unless rhs
|
|
123
137
|
|
|
124
|
-
check_operator(:binary, node.loc.operator, rhs
|
|
138
|
+
check_operator(:binary, node.loc.operator, rhs)
|
|
125
139
|
end
|
|
126
140
|
|
|
127
141
|
def on_special_asgn(node)
|
|
@@ -129,13 +143,13 @@ module RuboCop
|
|
|
129
143
|
|
|
130
144
|
return unless right
|
|
131
145
|
|
|
132
|
-
check_operator(:special_asgn, node.loc.operator, right
|
|
146
|
+
check_operator(:special_asgn, node.loc.operator, right)
|
|
133
147
|
end
|
|
134
148
|
|
|
135
149
|
def on_match_pattern(node)
|
|
136
150
|
return if target_ruby_version < 3.0
|
|
137
151
|
|
|
138
|
-
check_operator(:match_pattern, node.loc.operator, node
|
|
152
|
+
check_operator(:match_pattern, node.loc.operator, node)
|
|
139
153
|
end
|
|
140
154
|
|
|
141
155
|
alias on_or on_binary
|
|
@@ -166,9 +180,12 @@ module RuboCop
|
|
|
166
180
|
with_space = range_with_surrounding_space(operator)
|
|
167
181
|
return if with_space.source.start_with?("\n")
|
|
168
182
|
|
|
183
|
+
comment = processed_source.comment_at_line(operator.line)
|
|
184
|
+
return if comment && with_space.last_column == comment.loc.column
|
|
185
|
+
|
|
169
186
|
offense(type, operator, with_space, right_operand) do |msg|
|
|
170
187
|
add_offense(operator, message: msg) do |corrector|
|
|
171
|
-
autocorrect(corrector, with_space)
|
|
188
|
+
autocorrect(corrector, with_space, right_operand)
|
|
172
189
|
end
|
|
173
190
|
end
|
|
174
191
|
end
|
|
@@ -178,11 +195,15 @@ module RuboCop
|
|
|
178
195
|
yield msg if msg
|
|
179
196
|
end
|
|
180
197
|
|
|
181
|
-
def autocorrect(corrector, range)
|
|
182
|
-
|
|
198
|
+
def autocorrect(corrector, range, right_operand)
|
|
199
|
+
range_source = range.source
|
|
200
|
+
|
|
201
|
+
if range_source.include?('**') && !space_around_exponent_operator?
|
|
183
202
|
corrector.replace(range, '**')
|
|
184
|
-
elsif
|
|
185
|
-
corrector.replace(range,
|
|
203
|
+
elsif range_source.include?('/') && !space_around_slash_operator?(right_operand)
|
|
204
|
+
corrector.replace(range, '/')
|
|
205
|
+
elsif range_source.end_with?("\n")
|
|
206
|
+
corrector.replace(range, " #{range_source.strip}\n")
|
|
186
207
|
else
|
|
187
208
|
enclose_operator_with_space(corrector, range)
|
|
188
209
|
end
|
|
@@ -202,14 +223,14 @@ module RuboCop
|
|
|
202
223
|
end
|
|
203
224
|
|
|
204
225
|
def offense_message(type, operator, with_space, right_operand)
|
|
205
|
-
if should_not_have_surrounding_space?(operator)
|
|
226
|
+
if should_not_have_surrounding_space?(operator, right_operand)
|
|
206
227
|
return if with_space.is?(operator.source)
|
|
207
228
|
|
|
208
229
|
"Space around operator `#{operator.source}` detected."
|
|
209
230
|
elsif !/^\s.*\s$/.match?(with_space.source)
|
|
210
231
|
"Surrounding space missing for operator `#{operator.source}`."
|
|
211
232
|
elsif excess_leading_space?(type, operator, with_space) ||
|
|
212
|
-
excess_trailing_space?(right_operand, with_space)
|
|
233
|
+
excess_trailing_space?(right_operand.source_range, with_space)
|
|
213
234
|
"Operator `#{operator.source}` should be surrounded " \
|
|
214
235
|
'by a single space.'
|
|
215
236
|
end
|
|
@@ -247,12 +268,24 @@ module RuboCop
|
|
|
247
268
|
cop_config['EnforcedStyleForExponentOperator'] == 'space'
|
|
248
269
|
end
|
|
249
270
|
|
|
271
|
+
def space_around_slash_operator?(right_operand)
|
|
272
|
+
return true unless right_operand.rational_type?
|
|
273
|
+
|
|
274
|
+
cop_config['EnforcedStyleForRationalLiterals'] == 'space'
|
|
275
|
+
end
|
|
276
|
+
|
|
250
277
|
def force_equal_sign_alignment?
|
|
251
278
|
config.for_cop('Layout/ExtraSpacing')['ForceEqualSignAlignment']
|
|
252
279
|
end
|
|
253
280
|
|
|
254
|
-
def should_not_have_surrounding_space?(operator)
|
|
255
|
-
operator.is?('**')
|
|
281
|
+
def should_not_have_surrounding_space?(operator, right_operand)
|
|
282
|
+
if operator.is?('**')
|
|
283
|
+
!space_around_exponent_operator?
|
|
284
|
+
elsif operator.is?('/')
|
|
285
|
+
!space_around_slash_operator?(right_operand)
|
|
286
|
+
else
|
|
287
|
+
false
|
|
288
|
+
end
|
|
256
289
|
end
|
|
257
290
|
end
|
|
258
291
|
end
|
|
@@ -81,19 +81,28 @@ module RuboCop
|
|
|
81
81
|
private
|
|
82
82
|
|
|
83
83
|
def check_empty(left_brace, space_plus_brace, used_style)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
if style_for_empty_braces == used_style
|
|
85
|
+
handle_different_styles_for_empty_braces(used_style)
|
|
86
|
+
return
|
|
87
|
+
elsif !config_to_allow_offenses.key?('Enabled')
|
|
88
|
+
config_to_allow_offenses['EnforcedStyleForEmptyBraces'] = used_style.to_s
|
|
89
|
+
end
|
|
87
90
|
|
|
88
91
|
if style_for_empty_braces == :space
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
end
|
|
92
|
+
range = left_brace
|
|
93
|
+
msg = MISSING_MSG
|
|
92
94
|
else
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
range = range_between(space_plus_brace.begin_pos, left_brace.begin_pos)
|
|
96
|
+
msg = DETECTED_MSG
|
|
97
|
+
end
|
|
98
|
+
add_offense(range, message: msg) { |corrector| autocorrect(corrector, range) }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def handle_different_styles_for_empty_braces(used_style)
|
|
102
|
+
if config_to_allow_offenses['EnforcedStyleForEmptyBraces'] &&
|
|
103
|
+
config_to_allow_offenses['EnforcedStyleForEmptyBraces'].to_sym != used_style
|
|
104
|
+
config_to_allow_offenses.clear
|
|
105
|
+
config_to_allow_offenses['Enabled'] = false
|
|
97
106
|
end
|
|
98
107
|
end
|
|
99
108
|
|
|
@@ -116,7 +116,7 @@ module RuboCop
|
|
|
116
116
|
|
|
117
117
|
def incorrect_style_detected(token1, token2,
|
|
118
118
|
expect_space, is_empty_braces)
|
|
119
|
-
brace = (token1.
|
|
119
|
+
brace = (token1.left_brace? ? token1 : token2).pos
|
|
120
120
|
range = expect_space ? brace : space_range(brace)
|
|
121
121
|
detected_style = expect_space ? 'no_space' : 'space'
|
|
122
122
|
|
|
@@ -25,8 +25,7 @@ module RuboCop
|
|
|
25
25
|
include RangeHelp
|
|
26
26
|
extend AutoCorrector
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
SPACE_MSG = 'Missing space inside string interpolation detected.'
|
|
28
|
+
MSG = '%<command>s space inside string interpolation.'
|
|
30
29
|
|
|
31
30
|
def on_interpolation(begin_node)
|
|
32
31
|
return if begin_node.multiline?
|
|
@@ -36,9 +35,9 @@ module RuboCop
|
|
|
36
35
|
return if empty_brackets?(left, right, tokens: tokens)
|
|
37
36
|
|
|
38
37
|
if style == :no_space
|
|
39
|
-
no_space_offenses(begin_node, left, right,
|
|
38
|
+
no_space_offenses(begin_node, left, right, MSG)
|
|
40
39
|
else
|
|
41
|
-
space_offenses(begin_node, left, right,
|
|
40
|
+
space_offenses(begin_node, left, right, MSG)
|
|
42
41
|
end
|
|
43
42
|
end
|
|
44
43
|
|
|
@@ -12,13 +12,23 @@ module RuboCop
|
|
|
12
12
|
if corr.is_a?(CorrectionsProxy)
|
|
13
13
|
merge!(corr.send(:corrector))
|
|
14
14
|
else
|
|
15
|
-
|
|
15
|
+
unless corr.empty?
|
|
16
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
|
17
|
+
`Corrector.new` with corrections is deprecated.
|
|
18
|
+
See https://docs.rubocop.org/rubocop/v1_upgrade_notes.html
|
|
19
|
+
WARNING
|
|
20
|
+
end
|
|
21
|
+
|
|
16
22
|
corr.each { |c| corrections << c }
|
|
17
23
|
end
|
|
18
24
|
end
|
|
19
25
|
|
|
20
26
|
def corrections
|
|
21
|
-
|
|
27
|
+
warn Rainbow(<<~WARNING).yellow, uplevel: 1
|
|
28
|
+
`Corrector#corrections` is deprecated. Open an issue if you have a valid usecase.
|
|
29
|
+
See https://docs.rubocop.org/rubocop/v1_upgrade_notes.html
|
|
30
|
+
WARNING
|
|
31
|
+
|
|
22
32
|
CorrectionsProxy.new(self)
|
|
23
33
|
end
|
|
24
34
|
end
|
|
@@ -17,24 +17,24 @@ module RuboCop
|
|
|
17
17
|
#
|
|
18
18
|
# @example
|
|
19
19
|
# # bad
|
|
20
|
-
# if some_var =
|
|
20
|
+
# if some_var = value
|
|
21
21
|
# do_something
|
|
22
22
|
# end
|
|
23
23
|
#
|
|
24
24
|
# # good
|
|
25
|
-
# if some_var ==
|
|
25
|
+
# if some_var == value
|
|
26
26
|
# do_something
|
|
27
27
|
# end
|
|
28
28
|
#
|
|
29
29
|
# @example AllowSafeAssignment: true (default)
|
|
30
30
|
# # good
|
|
31
|
-
# if (some_var =
|
|
31
|
+
# if (some_var = value)
|
|
32
32
|
# do_something
|
|
33
33
|
# end
|
|
34
34
|
#
|
|
35
35
|
# @example AllowSafeAssignment: false
|
|
36
36
|
# # bad
|
|
37
|
-
# if (some_var =
|
|
37
|
+
# if (some_var = value)
|
|
38
38
|
# do_something
|
|
39
39
|
# end
|
|
40
40
|
#
|
|
@@ -50,7 +50,7 @@ module RuboCop
|
|
|
50
50
|
MSG_WITHOUT_SAFE_ASSIGNMENT_ALLOWED =
|
|
51
51
|
'Use `==` if you meant to do a comparison or move the assignment ' \
|
|
52
52
|
'up out of the condition.'
|
|
53
|
-
ASGN_TYPES = [:begin, *AST::Node::EQUALS_ASSIGNMENTS, :send].freeze
|
|
53
|
+
ASGN_TYPES = [:begin, *AST::Node::EQUALS_ASSIGNMENTS, :send, :csend].freeze
|
|
54
54
|
|
|
55
55
|
def on_if(node)
|
|
56
56
|
return if node.condition.block_type?
|
|
@@ -88,7 +88,7 @@ module RuboCop
|
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
def skip_children?(asgn_node)
|
|
91
|
-
(asgn_node.
|
|
91
|
+
(asgn_node.call_type? && !asgn_node.assignment_method?) ||
|
|
92
92
|
empty_condition?(asgn_node) ||
|
|
93
93
|
(safe_assignment_allowed? && safe_assignment?(asgn_node))
|
|
94
94
|
end
|