rubocop 0.35.1 → 0.36.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +164 -0
- data/LICENSE.txt +1 -1
- data/README.md +72 -21
- data/bin/rubocop +1 -0
- data/config/default.yml +167 -18
- data/config/disabled.yml +19 -6
- data/config/enabled.yml +159 -14
- data/lib/rubocop.rb +67 -26
- data/lib/rubocop/ast_node.rb +488 -14
- data/lib/rubocop/ast_node/builder.rb +24 -0
- data/lib/rubocop/ast_node/sexp.rb +13 -0
- data/lib/rubocop/cached_data.rb +58 -0
- data/lib/rubocop/cli.rb +47 -10
- data/lib/rubocop/comment_config.rb +9 -2
- data/lib/rubocop/config.rb +99 -31
- data/lib/rubocop/config_loader.rb +23 -14
- data/lib/rubocop/config_store.rb +1 -0
- data/lib/rubocop/cop/autocorrect_logic.rb +2 -1
- data/lib/rubocop/cop/commissioner.rb +3 -5
- data/lib/rubocop/cop/cop.rb +23 -17
- data/lib/rubocop/cop/corrector.rb +25 -0
- data/lib/rubocop/cop/force.rb +1 -0
- data/lib/rubocop/cop/ignored_node.rb +3 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +2 -1
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +2 -1
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +4 -3
- data/lib/rubocop/cop/lint/block_alignment.rb +29 -91
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -1
- data/lib/rubocop/cop/lint/condition_position.rb +2 -1
- data/lib/rubocop/cop/lint/debugger.rb +29 -12
- data/lib/rubocop/cop/lint/def_end_alignment.rb +16 -18
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +6 -6
- data/lib/rubocop/cop/lint/duplicate_methods.rb +98 -74
- data/lib/rubocop/cop/lint/duplicated_key.rb +3 -2
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +3 -2
- data/lib/rubocop/cop/lint/else_layout.rb +2 -1
- data/lib/rubocop/cop/lint/empty_ensure.rb +2 -1
- data/lib/rubocop/cop/lint/empty_interpolation.rb +2 -1
- data/lib/rubocop/cop/lint/end_alignment.rb +77 -39
- data/lib/rubocop/cop/lint/end_in_method.rb +2 -1
- data/lib/rubocop/cop/lint/ensure_return.rb +2 -1
- data/lib/rubocop/cop/lint/eval.rb +2 -1
- data/lib/rubocop/cop/lint/float_out_of_range.rb +31 -0
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +14 -30
- data/lib/rubocop/cop/lint/handle_exceptions.rb +2 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +85 -0
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +120 -0
- data/lib/rubocop/cop/lint/invalid_character_literal.rb +3 -1
- data/lib/rubocop/cop/lint/literal_in_condition.rb +6 -9
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +6 -9
- data/lib/rubocop/cop/lint/loop.rb +2 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +19 -3
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +38 -0
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +5 -8
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +8 -6
- data/lib/rubocop/cop/lint/rand_one.rb +36 -0
- data/lib/rubocop/cop/lint/require_parentheses.rb +6 -5
- data/lib/rubocop/cop/lint/rescue_exception.rb +3 -2
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +2 -1
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +6 -4
- data/lib/rubocop/cop/lint/syntax.rb +9 -5
- data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +3 -2
- data/lib/rubocop/cop/lint/unneeded_disable.rb +121 -18
- data/lib/rubocop/cop/lint/unreachable_code.rb +5 -4
- data/lib/rubocop/cop/lint/unused_block_argument.rb +9 -7
- data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +56 -29
- data/lib/rubocop/cop/lint/useless_assignment.rb +4 -16
- data/lib/rubocop/cop/lint/useless_comparison.rb +3 -2
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +2 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +14 -20
- data/lib/rubocop/cop/lint/void.rb +10 -11
- data/lib/rubocop/cop/metrics/abc_size.rb +3 -1
- data/lib/rubocop/cop/metrics/block_nesting.rb +2 -1
- data/lib/rubocop/cop/metrics/class_length.rb +1 -0
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +4 -2
- data/lib/rubocop/cop/metrics/line_length.rb +35 -13
- data/lib/rubocop/cop/metrics/method_length.rb +2 -1
- data/lib/rubocop/cop/metrics/module_length.rb +1 -0
- data/lib/rubocop/cop/metrics/parameter_lists.rb +2 -1
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +4 -2
- data/lib/rubocop/cop/mixin/access_modifier_node.rb +3 -10
- data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -0
- data/lib/rubocop/cop/mixin/array_hash_indentation.rb +80 -0
- data/lib/rubocop/cop/mixin/array_syntax.rb +2 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +14 -20
- data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +5 -4
- data/lib/rubocop/cop/mixin/check_assignment.rb +20 -15
- data/lib/rubocop/cop/mixin/classish_length.rb +1 -0
- data/lib/rubocop/cop/mixin/code_length.rb +1 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +17 -15
- data/lib/rubocop/cop/mixin/configurable_max.rb +1 -0
- data/lib/rubocop/cop/mixin/configurable_naming.rb +4 -0
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +9 -4
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +24 -16
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +3 -2
- data/lib/rubocop/cop/mixin/hash_node.rb +15 -0
- data/lib/rubocop/cop/mixin/if_node.rb +1 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +1 -0
- data/lib/rubocop/cop/mixin/method_preference.rb +1 -0
- data/lib/rubocop/cop/mixin/min_body_length.rb +1 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +177 -0
- data/lib/rubocop/cop/mixin/negative_conditional.rb +1 -0
- data/lib/rubocop/cop/mixin/on_method_def.rb +6 -5
- data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +1 -0
- data/lib/rubocop/cop/mixin/parentheses.rb +22 -0
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -0
- data/lib/rubocop/cop/mixin/percent_literal.rb +1 -0
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +79 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +1 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -1
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +2 -1
- data/lib/rubocop/cop/mixin/space_inside.rb +2 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +6 -5
- data/lib/rubocop/cop/mixin/string_help.rb +2 -9
- data/lib/rubocop/cop/mixin/string_literals_help.rb +13 -7
- data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +134 -0
- data/lib/rubocop/cop/mixin/unused_argument.rb +1 -0
- data/lib/rubocop/cop/offense.rb +19 -14
- data/lib/rubocop/cop/performance/case_when_splat.rb +8 -8
- data/lib/rubocop/cop/performance/casecmp.rb +54 -0
- data/lib/rubocop/cop/performance/count.rb +10 -9
- data/lib/rubocop/cop/performance/detect.rb +6 -5
- data/lib/rubocop/cop/performance/double_start_end_with.rb +65 -0
- data/lib/rubocop/cop/performance/end_with.rb +55 -0
- data/lib/rubocop/cop/performance/fixed_size.rb +1 -0
- data/lib/rubocop/cop/performance/flat_map.rb +9 -8
- data/lib/rubocop/cop/performance/hash_each.rb +86 -0
- data/lib/rubocop/cop/performance/lstrip_rstrip.rb +44 -0
- data/lib/rubocop/cop/performance/range_include.rb +40 -0
- data/lib/rubocop/cop/performance/redundant_block_call.rb +57 -0
- data/lib/rubocop/cop/performance/redundant_match.rb +51 -0
- data/lib/rubocop/cop/performance/redundant_merge.rb +85 -0
- data/lib/rubocop/cop/performance/redundant_sort_by.rb +45 -0
- data/lib/rubocop/cop/performance/reverse_each.rb +3 -2
- data/lib/rubocop/cop/performance/sample.rb +6 -5
- data/lib/rubocop/cop/performance/size.rb +2 -1
- data/lib/rubocop/cop/performance/start_with.rb +58 -0
- data/lib/rubocop/cop/performance/string_replacement.rb +18 -23
- data/lib/rubocop/cop/performance/times_map.rb +49 -0
- data/lib/rubocop/cop/rails/action_filter.rb +4 -3
- data/lib/rubocop/cop/rails/date.rb +5 -4
- data/lib/rubocop/cop/rails/delegate.rb +3 -2
- data/lib/rubocop/cop/rails/find_by.rb +20 -14
- data/lib/rubocop/cop/rails/find_each.rb +23 -2
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +3 -2
- data/lib/rubocop/cop/rails/output.rb +4 -2
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +3 -2
- data/lib/rubocop/cop/rails/read_write_attribute.rb +5 -7
- data/lib/rubocop/cop/rails/scope_args.rb +3 -2
- data/lib/rubocop/cop/rails/time_zone.rb +14 -10
- data/lib/rubocop/cop/rails/validation.rb +4 -3
- data/lib/rubocop/cop/severity.rb +8 -7
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +5 -4
- data/lib/rubocop/cop/style/accessor_method_name.rb +1 -0
- data/lib/rubocop/cop/style/alias.rb +84 -24
- data/lib/rubocop/cop/style/align_array.rb +2 -1
- data/lib/rubocop/cop/style/align_hash.rb +13 -14
- data/lib/rubocop/cop/style/align_parameters.rb +3 -2
- data/lib/rubocop/cop/style/and_or.rb +9 -7
- data/lib/rubocop/cop/style/array_join.rb +5 -5
- data/lib/rubocop/cop/style/ascii_comments.rb +2 -1
- data/lib/rubocop/cop/style/ascii_identifiers.rb +2 -1
- data/lib/rubocop/cop/style/attr.rb +30 -5
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +3 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +2 -1
- data/lib/rubocop/cop/style/begin_block.rb +2 -1
- data/lib/rubocop/cop/style/block_comments.rb +2 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +10 -9
- data/lib/rubocop/cop/style/block_end_newline.rb +3 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +9 -8
- data/lib/rubocop/cop/style/case_equality.rb +2 -1
- data/lib/rubocop/cop/style/case_indentation.rb +2 -1
- data/lib/rubocop/cop/style/character_literal.rb +11 -7
- data/lib/rubocop/cop/style/class_and_module_camel_case.rb +2 -1
- data/lib/rubocop/cop/style/class_and_module_children.rb +3 -2
- data/lib/rubocop/cop/style/class_check.rb +2 -1
- data/lib/rubocop/cop/style/class_methods.rb +2 -1
- data/lib/rubocop/cop/style/class_vars.rb +2 -1
- data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +3 -2
- data/lib/rubocop/cop/style/collection_methods.rb +2 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +3 -2
- data/lib/rubocop/cop/style/command_literal.rb +8 -7
- data/lib/rubocop/cop/style/comment_annotation.rb +3 -2
- data/lib/rubocop/cop/style/comment_indentation.rb +4 -6
- data/lib/rubocop/cop/style/conditional_assignment.rb +362 -0
- data/lib/rubocop/cop/style/constant_name.rb +2 -1
- data/lib/rubocop/cop/style/copyright.rb +7 -6
- data/lib/rubocop/cop/style/def_with_parentheses.rb +2 -1
- data/lib/rubocop/cop/style/deprecated_hash_methods.rb +3 -2
- data/lib/rubocop/cop/style/documentation.rb +7 -11
- data/lib/rubocop/cop/style/dot_position.rb +3 -2
- data/lib/rubocop/cop/style/double_negation.rb +2 -1
- data/lib/rubocop/cop/style/each_with_object.rb +4 -3
- data/lib/rubocop/cop/style/else_alignment.rb +3 -2
- data/lib/rubocop/cop/style/empty_else.rb +4 -3
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +2 -1
- data/lib/rubocop/cop/style/empty_lines.rb +10 -4
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +13 -5
- data/lib/rubocop/cop/style/empty_lines_around_block_body.rb +7 -3
- data/lib/rubocop/cop/style/empty_lines_around_class_body.rb +6 -3
- data/lib/rubocop/cop/style/empty_lines_around_method_body.rb +4 -3
- data/lib/rubocop/cop/style/empty_lines_around_module_body.rb +4 -2
- data/lib/rubocop/cop/style/empty_literal.rb +20 -5
- data/lib/rubocop/cop/style/encoding.rb +8 -11
- data/lib/rubocop/cop/style/end_block.rb +3 -1
- data/lib/rubocop/cop/style/end_of_line.rb +2 -1
- data/lib/rubocop/cop/style/even_odd.rb +4 -3
- data/lib/rubocop/cop/style/extra_spacing.rb +110 -74
- data/lib/rubocop/cop/style/file_name.rb +103 -6
- data/lib/rubocop/cop/style/first_array_element_line_break.rb +3 -2
- data/lib/rubocop/cop/style/first_hash_element_line_break.rb +5 -6
- data/lib/rubocop/cop/style/first_method_argument_line_break.rb +14 -1
- data/lib/rubocop/cop/style/first_method_parameter_line_break.rb +2 -1
- data/lib/rubocop/cop/style/first_parameter_indentation.rb +6 -4
- data/lib/rubocop/cop/style/flip_flop.rb +2 -1
- data/lib/rubocop/cop/style/for.rb +2 -1
- data/lib/rubocop/cop/style/format_string.rb +1 -0
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +89 -0
- data/lib/rubocop/cop/style/global_vars.rb +2 -1
- data/lib/rubocop/cop/style/guard_clause.rb +63 -11
- data/lib/rubocop/cop/style/hash_syntax.rb +10 -10
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +93 -0
- data/lib/rubocop/cop/style/if_inside_else.rb +49 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +6 -5
- data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -1
- data/lib/rubocop/cop/style/indent_array.rb +89 -38
- data/lib/rubocop/cop/style/indent_assignment.rb +43 -0
- data/lib/rubocop/cop/style/indent_hash.rb +16 -77
- data/lib/rubocop/cop/style/indentation_consistency.rb +2 -1
- data/lib/rubocop/cop/style/indentation_width.rb +11 -11
- data/lib/rubocop/cop/style/infinite_loop.rb +5 -9
- data/lib/rubocop/cop/style/initial_indentation.rb +2 -1
- data/lib/rubocop/cop/style/inline_comment.rb +2 -1
- data/lib/rubocop/cop/style/lambda.rb +14 -11
- data/lib/rubocop/cop/style/lambda_call.rb +4 -4
- data/lib/rubocop/cop/style/leading_comment_space.rb +2 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +3 -1
- data/lib/rubocop/cop/style/method_call_parentheses.rb +9 -1
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +3 -2
- data/lib/rubocop/cop/style/method_def_parentheses.rb +4 -4
- data/lib/rubocop/cop/style/method_name.rb +1 -0
- data/lib/rubocop/cop/style/missing_else.rb +5 -3
- data/lib/rubocop/cop/style/module_function.rb +2 -1
- data/lib/rubocop/cop/style/multiline_array_brace_layout.rb +95 -0
- data/lib/rubocop/cop/style/multiline_assignment_layout.rb +91 -0
- data/lib/rubocop/cop/style/multiline_block_chain.rb +3 -2
- data/lib/rubocop/cop/style/multiline_block_layout.rb +11 -9
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -0
- data/lib/rubocop/cop/style/multiline_method_call_indentation.rb +137 -0
- data/lib/rubocop/cop/style/multiline_operation_indentation.rb +25 -135
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +2 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +4 -5
- data/lib/rubocop/cop/style/negated_if.rb +3 -3
- data/lib/rubocop/cop/style/negated_while.rb +3 -3
- data/lib/rubocop/cop/style/nested_modifier.rb +6 -5
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +48 -0
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +2 -1
- data/lib/rubocop/cop/style/next.rb +79 -15
- data/lib/rubocop/cop/style/nil_comparison.rb +5 -5
- data/lib/rubocop/cop/style/non_nil_check.rb +5 -5
- data/lib/rubocop/cop/style/not.rb +5 -9
- data/lib/rubocop/cop/style/numeric_literals.rb +5 -4
- data/lib/rubocop/cop/style/one_line_conditional.rb +3 -2
- data/lib/rubocop/cop/style/op_method.rb +7 -4
- data/lib/rubocop/cop/style/option_hash.rb +13 -7
- data/lib/rubocop/cop/style/optional_arguments.rb +3 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +40 -16
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +3 -16
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -2
- data/lib/rubocop/cop/style/percent_q_literals.rb +3 -6
- data/lib/rubocop/cop/style/perl_backrefs.rb +4 -3
- data/lib/rubocop/cop/style/predicate_name.rb +1 -0
- data/lib/rubocop/cop/style/proc.rb +3 -2
- data/lib/rubocop/cop/style/raise_args.rb +2 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +2 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +5 -5
- data/lib/rubocop/cop/style/redundant_freeze.rb +5 -4
- data/lib/rubocop/cop/style/redundant_parentheses.rb +80 -0
- data/lib/rubocop/cop/style/redundant_return.rb +5 -4
- data/lib/rubocop/cop/style/redundant_self.rb +7 -8
- data/lib/rubocop/cop/style/regexp_literal.rb +9 -8
- data/lib/rubocop/cop/style/rescue_ensure_alignment.rb +3 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +11 -9
- data/lib/rubocop/cop/style/self_assignment.rb +4 -5
- data/lib/rubocop/cop/style/semicolon.rb +3 -2
- data/lib/rubocop/cop/style/send.rb +3 -1
- data/lib/rubocop/cop/style/signal_exception.rb +5 -3
- data/lib/rubocop/cop/style/single_line_block_params.rb +2 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +7 -7
- data/lib/rubocop/cop/style/space_after_colon.rb +2 -1
- data/lib/rubocop/cop/style/space_after_comma.rb +1 -0
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +5 -5
- data/lib/rubocop/cop/style/space_after_method_name.rb +3 -2
- data/lib/rubocop/cop/style/space_after_not.rb +4 -3
- data/lib/rubocop/cop/style/space_after_semicolon.rb +1 -0
- data/lib/rubocop/cop/style/space_around_block_parameters.rb +8 -7
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +1 -0
- data/lib/rubocop/cop/style/space_around_operators.rb +72 -32
- data/lib/rubocop/cop/style/space_before_block_braces.rb +2 -1
- data/lib/rubocop/cop/style/space_before_comma.rb +1 -0
- data/lib/rubocop/cop/style/space_before_comment.rb +2 -1
- data/lib/rubocop/cop/style/{single_space_before_first_arg.rb → space_before_first_arg.rb} +13 -4
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +4 -3
- data/lib/rubocop/cop/style/space_before_semicolon.rb +1 -0
- data/lib/rubocop/cop/style/space_inside_block_braces.rb +3 -2
- data/lib/rubocop/cop/style/space_inside_brackets.rb +1 -0
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +4 -1
- data/lib/rubocop/cop/style/space_inside_parens.rb +1 -0
- data/lib/rubocop/cop/style/space_inside_range_literal.rb +5 -4
- data/lib/rubocop/cop/style/space_inside_string_interpolation.rb +8 -17
- data/lib/rubocop/cop/style/special_global_vars.rb +97 -52
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +16 -9
- data/lib/rubocop/cop/style/string_literals.rb +41 -1
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +2 -1
- data/lib/rubocop/cop/style/string_methods.rb +2 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +3 -2
- data/lib/rubocop/cop/style/symbol_array.rb +74 -7
- data/lib/rubocop/cop/style/symbol_literal.rb +4 -7
- data/lib/rubocop/cop/style/symbol_proc.rb +11 -7
- data/lib/rubocop/cop/style/tab.rb +25 -2
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +1 -2
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +45 -0
- data/lib/rubocop/cop/style/trailing_comma_in_literal.rb +56 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +8 -7
- data/lib/rubocop/cop/style/trailing_whitespace.rb +2 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +18 -9
- data/lib/rubocop/cop/style/unless_else.rb +2 -1
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +4 -3
- data/lib/rubocop/cop/style/unneeded_interpolation.rb +87 -0
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +23 -7
- data/lib/rubocop/cop/style/variable_interpolation.rb +8 -6
- data/lib/rubocop/cop/style/variable_name.rb +1 -0
- data/lib/rubocop/cop/style/when_then.rb +2 -1
- data/lib/rubocop/cop/style/while_until_do.rb +3 -2
- data/lib/rubocop/cop/style/while_until_modifier.rb +3 -4
- data/lib/rubocop/cop/style/word_array.rb +74 -51
- data/lib/rubocop/cop/team.rb +21 -15
- data/lib/rubocop/cop/util.rb +102 -69
- data/lib/rubocop/cop/variable_force.rb +2 -1
- data/lib/rubocop/cop/variable_force/assignment.rb +2 -1
- data/lib/rubocop/cop/variable_force/locatable.rb +1 -0
- data/lib/rubocop/cop/variable_force/reference.rb +1 -0
- data/lib/rubocop/cop/variable_force/scope.rb +2 -1
- data/lib/rubocop/cop/variable_force/variable.rb +2 -1
- data/lib/rubocop/cop/variable_force/variable_table.rb +2 -1
- data/lib/rubocop/error.rb +12 -0
- data/lib/rubocop/formatter/base_formatter.rb +10 -1
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -0
- data/lib/rubocop/formatter/colorizable.rb +6 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +29 -15
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +3 -1
- data/lib/rubocop/formatter/emacs_style_formatter.rb +7 -3
- data/lib/rubocop/formatter/file_list_formatter.rb +1 -0
- data/lib/rubocop/formatter/formatter_set.rb +10 -19
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +2 -1
- data/lib/rubocop/formatter/html_formatter.rb +15 -14
- data/lib/rubocop/formatter/json_formatter.rb +2 -1
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -0
- data/lib/rubocop/formatter/progress_formatter.rb +3 -3
- data/lib/rubocop/formatter/simple_text_formatter.rb +50 -17
- data/lib/rubocop/formatter/text_util.rb +8 -10
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +61 -0
- data/lib/rubocop/name_similarity.rb +22 -0
- data/lib/rubocop/node_pattern.rb +126 -35
- data/lib/rubocop/options.rb +28 -19
- data/lib/rubocop/path_util.rb +1 -0
- data/lib/rubocop/processed_source.rb +41 -16
- data/lib/rubocop/rake_task.rb +6 -9
- data/lib/rubocop/remote_config.rb +1 -0
- data/lib/rubocop/result_cache.rb +60 -43
- data/lib/rubocop/runner.rb +48 -45
- data/lib/rubocop/string_util.rb +1 -0
- data/lib/rubocop/target_finder.rb +2 -1
- data/lib/rubocop/token.rb +1 -0
- data/lib/rubocop/version.rb +3 -2
- data/lib/rubocop/warning.rb +1 -0
- data/relnotes/v0.36.0.md +306 -0
- data/rubocop.gemspec +3 -9
- metadata +48 -92
- data/lib/rubocop/cop/lint/space_before_first_arg.rb +0 -44
- data/lib/rubocop/cop/rails/default_scope.rb +0 -33
- data/lib/rubocop/cop/style/trailing_comma.rb +0 -182
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -9,7 +10,7 @@ module RuboCop
|
|
9
10
|
include AutocorrectAlignment
|
10
11
|
|
11
12
|
MSG = 'Align the elements of an array literal if they span more ' \
|
12
|
-
'than one line.'
|
13
|
+
'than one line.'.freeze
|
13
14
|
|
14
15
|
def on_array(node)
|
15
16
|
check_alignment(node.children)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -20,7 +21,7 @@ module RuboCop
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def deltas(first_pair, current_pair)
|
23
|
-
if Util.begins_its_line?(current_pair.
|
24
|
+
if Util.begins_its_line?(current_pair.source_range)
|
24
25
|
{ key: first_pair.loc.column - current_pair.loc.column }
|
25
26
|
else
|
26
27
|
{}
|
@@ -31,6 +32,8 @@ module RuboCop
|
|
31
32
|
# Common functionality for the styles where not only keys, but also
|
32
33
|
# values are aligned.
|
33
34
|
class AlignmentOfValues
|
35
|
+
include HashNode # any_pairs_on_the_same_line?
|
36
|
+
|
34
37
|
def checkable_layout(node)
|
35
38
|
!any_pairs_on_the_same_line?(node) && all_have_same_separator?(node)
|
36
39
|
end
|
@@ -56,15 +59,9 @@ module RuboCop
|
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
59
|
-
def any_pairs_on_the_same_line?(node)
|
60
|
-
node.children[1..-1].any? do |pair|
|
61
|
-
!Util.begins_its_line?(pair.loc.expression)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
62
|
def all_have_same_separator?(node)
|
66
63
|
first_separator = node.children.first.loc.operator.source
|
67
|
-
node.children
|
64
|
+
node.children.butfirst.all? do |pair|
|
68
65
|
pair.loc.operator.is?(first_separator)
|
69
66
|
end
|
70
67
|
end
|
@@ -77,7 +74,7 @@ module RuboCop
|
|
77
74
|
def deltas_for_first_pair(first_pair, node)
|
78
75
|
key_widths = node.children.map do |pair|
|
79
76
|
key, _value = *pair
|
80
|
-
key.
|
77
|
+
key.source.length
|
81
78
|
end
|
82
79
|
@max_key_width = key_widths.max
|
83
80
|
|
@@ -128,7 +125,7 @@ module RuboCop
|
|
128
125
|
|
129
126
|
def key_end_column(pair)
|
130
127
|
key, _value = *pair
|
131
|
-
key.loc.column + key.
|
128
|
+
key.loc.column + key.source.length
|
132
129
|
end
|
133
130
|
|
134
131
|
def hash_rocket_delta(first_pair, current_separator)
|
@@ -143,7 +140,7 @@ module RuboCop
|
|
143
140
|
end
|
144
141
|
|
145
142
|
MSG = 'Align the elements of a hash literal if they span more than ' \
|
146
|
-
'one line.'
|
143
|
+
'one line.'.freeze
|
147
144
|
|
148
145
|
def on_send(node)
|
149
146
|
return unless (last_child = node.children.last) &&
|
@@ -218,14 +215,16 @@ module RuboCop
|
|
218
215
|
value_delta = @column_deltas[:value] || 0
|
219
216
|
|
220
217
|
key, value = *node
|
218
|
+
key_column = key.source_range.column
|
219
|
+
key_delta = -key_column if key_delta < -key_column
|
221
220
|
|
222
221
|
lambda do |corrector|
|
223
222
|
if value.nil?
|
224
|
-
adjust(corrector, key_delta, node.
|
223
|
+
adjust(corrector, key_delta, node.source_range)
|
225
224
|
else
|
226
|
-
adjust(corrector, key_delta, key.
|
225
|
+
adjust(corrector, key_delta, key.source_range)
|
227
226
|
adjust(corrector, separator_delta, node.loc.operator)
|
228
|
-
adjust(corrector, value_delta, value.
|
227
|
+
adjust(corrector, value_delta, value.source_range)
|
229
228
|
end
|
230
229
|
end
|
231
230
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -25,7 +26,7 @@ module RuboCop
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def message(node)
|
28
|
-
type = node.parent.send_type? ? 'call' : 'definition'
|
29
|
+
type = node && node.parent.send_type? ? 'call' : 'definition'
|
29
30
|
"Align the parameters of a method #{type} if they span " \
|
30
31
|
'more than one line.'
|
31
32
|
end
|
@@ -39,7 +40,7 @@ module RuboCop
|
|
39
40
|
def base_column(node, args)
|
40
41
|
if fixed_indentation?
|
41
42
|
lineno = target_method_lineno(node)
|
42
|
-
line = node.
|
43
|
+
line = node.source_range.source_buffer.source_line(lineno)
|
43
44
|
indentation_of_line = /\S.*/.match(line).begin(0)
|
44
45
|
indentation_of_line + configured_indentation_width
|
45
46
|
else
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -8,9 +9,9 @@ module RuboCop
|
|
8
9
|
include AutocorrectUnlessChangingAST
|
9
10
|
include ConfigurableEnforcedStyle
|
10
11
|
|
11
|
-
MSG = 'Use `%s` instead of `%s`.'
|
12
|
+
MSG = 'Use `%s` instead of `%s`.'.freeze
|
12
13
|
|
13
|
-
OPS = { 'and' => '&&', 'or' => '||' }
|
14
|
+
OPS = { 'and' => '&&', 'or' => '||' }.freeze
|
14
15
|
|
15
16
|
def on_and(node)
|
16
17
|
process_logical_op(node) if style == :always
|
@@ -85,6 +86,7 @@ module RuboCop
|
|
85
86
|
|
86
87
|
if node.loc.selector.source == '!'
|
87
88
|
node = receiver
|
89
|
+
return unless node.send_type?
|
88
90
|
_receiver, _method_name, *args = *node
|
89
91
|
elsif node.loc.selector.source == 'not'
|
90
92
|
return correct_other(node, corrector)
|
@@ -94,17 +96,17 @@ module RuboCop
|
|
94
96
|
end
|
95
97
|
return unless correctable_send?(node)
|
96
98
|
|
97
|
-
sb = node.
|
99
|
+
sb = node.source_range.source_buffer
|
98
100
|
begin_paren = node.loc.selector.end_pos
|
99
101
|
range = Parser::Source::Range.new(sb, begin_paren, begin_paren + 1)
|
100
102
|
corrector.replace(range, '(')
|
101
|
-
corrector.insert_after(args.last.
|
103
|
+
corrector.insert_after(args.last.source_range, ')')
|
102
104
|
end
|
103
105
|
|
104
106
|
def correct_other(node, corrector)
|
105
|
-
return unless node.
|
106
|
-
corrector.insert_before(node.
|
107
|
-
corrector.insert_after(node.
|
107
|
+
return unless node.source_range.begin.source != '('
|
108
|
+
corrector.insert_before(node.source_range, '(')
|
109
|
+
corrector.insert_after(node.source_range, ')')
|
108
110
|
end
|
109
111
|
|
110
112
|
def correctable_send?(node)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -9,7 +10,7 @@ module RuboCop
|
|
9
10
|
# types, so we consider only cases when the first argument is an
|
10
11
|
# array literal or the second is a string literal.
|
11
12
|
class ArrayJoin < Cop
|
12
|
-
MSG = 'Favor `Array#join` over `Array#*`.'
|
13
|
+
MSG = 'Favor `Array#join` over `Array#*`.'.freeze
|
13
14
|
|
14
15
|
def on_send(node)
|
15
16
|
receiver_node, method_name, *arg_nodes = *node
|
@@ -21,12 +22,11 @@ module RuboCop
|
|
21
22
|
|
22
23
|
def autocorrect(node)
|
23
24
|
receiver_node, _method_name, *arg_nodes = *node
|
24
|
-
|
25
|
-
|
26
|
-
join_arg = arg_nodes[0].loc.expression.source
|
25
|
+
array = receiver_node.source
|
26
|
+
join_arg = arg_nodes[0].source
|
27
27
|
|
28
28
|
lambda do |corrector|
|
29
|
-
corrector.replace(
|
29
|
+
corrector.replace(node.source_range, "#{array}.join(#{join_arg})")
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -6,7 +7,7 @@ module RuboCop
|
|
6
7
|
# This cop checks for non-ascii (non-English) characters
|
7
8
|
# in comments.
|
8
9
|
class AsciiComments < Cop
|
9
|
-
MSG = 'Use only ascii symbols in comments.'
|
10
|
+
MSG = 'Use only ascii symbols in comments.'.freeze
|
10
11
|
|
11
12
|
def investigate(processed_source)
|
12
13
|
processed_source.comments.each do |comment|
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
5
6
|
module Style
|
6
7
|
# This cop checks for non-ascii characters in identifier names.
|
7
8
|
class AsciiIdentifiers < Cop
|
8
|
-
MSG = 'Use only ascii symbols in identifiers.'
|
9
|
+
MSG = 'Use only ascii symbols in identifiers.'.freeze
|
9
10
|
|
10
11
|
def investigate(processed_source)
|
11
12
|
processed_source.tokens.each do |t|
|
@@ -1,20 +1,45 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
5
6
|
module Style
|
6
7
|
# This cop checks for uses of Module#attr.
|
7
8
|
class Attr < Cop
|
8
|
-
MSG = 'Do not use `attr`. Use `attr_reader` instead.'
|
9
|
-
|
10
9
|
def on_send(node)
|
11
|
-
return unless command?(:attr
|
10
|
+
return unless node.command?(:attr)
|
12
11
|
_receiver, _method_name, *args = *node
|
13
|
-
|
12
|
+
msg = "Do not use `attr`. Use `#{replacement_method(node)}` instead."
|
13
|
+
|
14
|
+
add_offense(node, :selector, msg) if args.any?
|
14
15
|
end
|
15
16
|
|
16
17
|
def autocorrect(node)
|
17
|
-
|
18
|
+
_receiver, _method_name, attr_name, setter = *node
|
19
|
+
node_expr = node.source_range
|
20
|
+
attr_expr = attr_name.source_range
|
21
|
+
|
22
|
+
if setter && (setter.true_type? || setter.false_type?)
|
23
|
+
remove = Parser::Source::Range.new(node_expr.source_buffer,
|
24
|
+
attr_expr.end_pos,
|
25
|
+
node_expr.end_pos)
|
26
|
+
end
|
27
|
+
|
28
|
+
lambda do |corrector|
|
29
|
+
corrector.replace(node.loc.selector, replacement_method(node))
|
30
|
+
corrector.replace(remove, '') if remove
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def replacement_method(node)
|
37
|
+
_receiver, _method_name, _attr_name, setter = *node
|
38
|
+
if setter && (setter.true_type? || setter.false_type?)
|
39
|
+
setter.true_type? ? 'attr_accessor' : 'attr_reader'
|
40
|
+
else
|
41
|
+
'attr_reader'
|
42
|
+
end
|
18
43
|
end
|
19
44
|
end
|
20
45
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -17,12 +18,11 @@ module RuboCop
|
|
17
18
|
# ...
|
18
19
|
# end
|
19
20
|
class AutoResourceCleanup < Cop
|
20
|
-
|
21
|
-
MSG = 'Use the block version of `%s.%s`.'
|
21
|
+
MSG = 'Use the block version of `%s.%s`.'.freeze
|
22
22
|
|
23
23
|
TARGET_METHODS = [
|
24
24
|
[:File, :open]
|
25
|
-
]
|
25
|
+
].freeze
|
26
26
|
|
27
27
|
def on_send(node)
|
28
28
|
receiver_node, method_name, *arg_nodes = *node
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -7,7 +8,7 @@ module RuboCop
|
|
7
8
|
class BarePercentLiterals < Cop
|
8
9
|
include ConfigurableEnforcedStyle
|
9
10
|
|
10
|
-
MSG = 'Use `%%%s` instead of `%%%s`.'
|
11
|
+
MSG = 'Use `%%%s` instead of `%%%s`.'.freeze
|
11
12
|
|
12
13
|
def on_dstr(node)
|
13
14
|
check(node)
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
5
6
|
module Style
|
6
7
|
# This cop checks for BEGIN blocks.
|
7
8
|
class BeginBlock < Cop
|
8
|
-
MSG = 'Avoid the use of `BEGIN` blocks.'
|
9
|
+
MSG = 'Avoid the use of `BEGIN` blocks.'.freeze
|
9
10
|
|
10
11
|
def on_preexe(node)
|
11
12
|
add_offense(node, :keyword)
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
5
6
|
module Style
|
6
7
|
# This cop looks for uses of block comments (=begin...=end).
|
7
8
|
class BlockComments < Cop
|
8
|
-
MSG = 'Do not use block comments.'
|
9
|
+
MSG = 'Do not use block comments.'.freeze
|
9
10
|
BEGIN_LENGTH = "=begin\n".length
|
10
11
|
END_LENGTH = "\n=end".length
|
11
12
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -33,7 +34,7 @@ module RuboCop
|
|
33
34
|
private
|
34
35
|
|
35
36
|
def line_count_based_message(node)
|
36
|
-
block_length =
|
37
|
+
block_length = block_length(node)
|
37
38
|
|
38
39
|
if block_length > 0
|
39
40
|
'Avoid using `{...}` for multi-line blocks.'
|
@@ -53,7 +54,7 @@ module RuboCop
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def braces_for_chaining_message(node)
|
56
|
-
block_length =
|
57
|
+
block_length = block_length(node)
|
57
58
|
|
58
59
|
if block_length > 0
|
59
60
|
if return_value_chaining?(node)
|
@@ -119,7 +120,7 @@ module RuboCop
|
|
119
120
|
end
|
120
121
|
|
121
122
|
def line_count_based_block_style?(node)
|
122
|
-
block_length =
|
123
|
+
block_length = block_length(node)
|
123
124
|
block_begin = node.loc.begin.source
|
124
125
|
|
125
126
|
if block_length > 0
|
@@ -143,14 +144,14 @@ module RuboCop
|
|
143
144
|
end
|
144
145
|
|
145
146
|
def braces_for_chaining_style?(node)
|
146
|
-
block_length =
|
147
|
+
block_length = block_length(node)
|
147
148
|
block_begin = node.loc.begin.source
|
148
149
|
|
149
|
-
if block_length > 0
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
150
|
+
block_begin == if block_length > 0
|
151
|
+
(return_value_chaining?(node) ? '{' : 'do')
|
152
|
+
else
|
153
|
+
'{'
|
154
|
+
end
|
154
155
|
end
|
155
156
|
|
156
157
|
def return_value_chaining?(node)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -25,7 +26,7 @@ module RuboCop
|
|
25
26
|
# foo(i)
|
26
27
|
# }
|
27
28
|
class BlockEndNewline < Cop
|
28
|
-
MSG = 'Expression at %d, %d should be on its own line.'
|
29
|
+
MSG = 'Expression at %d, %d should be on its own line.'.freeze
|
29
30
|
|
30
31
|
def on_block(node)
|
31
32
|
end_loc = node.loc.end
|
@@ -33,7 +34,7 @@ module RuboCop
|
|
33
34
|
return if do_loc.line == end_loc.line # Ignore one-liners.
|
34
35
|
|
35
36
|
# If the end is on its own line, there is no offense
|
36
|
-
return if /^\s*#{end_loc.source}
|
37
|
+
return if end_loc.source_line =~ /^\s*#{end_loc.source}/
|
37
38
|
|
38
39
|
msg = format(MSG, end_loc.line, end_loc.column + 1)
|
39
40
|
add_offense(node, end_loc, msg)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -9,7 +10,7 @@ module RuboCop
|
|
9
10
|
include ConfigurableEnforcedStyle
|
10
11
|
include AutocorrectUnlessChangingAST
|
11
12
|
|
12
|
-
MSG = '%s curly braces around a hash parameter.'
|
13
|
+
MSG = '%s curly braces around a hash parameter.'.freeze
|
13
14
|
|
14
15
|
def on_send(node)
|
15
16
|
_receiver, method_name, *args = *node
|
@@ -29,9 +30,9 @@ module RuboCop
|
|
29
30
|
|
30
31
|
def check(arg, args)
|
31
32
|
if style == :braces && !braces?(arg)
|
32
|
-
add_offense(arg.parent, arg.
|
33
|
+
add_offense(arg.parent, arg.source_range, format(MSG, 'Missing'))
|
33
34
|
elsif style == :no_braces && braces?(arg)
|
34
|
-
add_offense(arg.parent, arg.
|
35
|
+
add_offense(arg.parent, arg.source_range,
|
35
36
|
format(MSG, 'Redundant'))
|
36
37
|
elsif style == :context_dependent
|
37
38
|
check_context_dependent(arg, args)
|
@@ -42,16 +43,16 @@ module RuboCop
|
|
42
43
|
braces_around_2nd_from_end = args.length > 1 && args[-2].type == :hash
|
43
44
|
if braces?(arg)
|
44
45
|
unless braces_around_2nd_from_end
|
45
|
-
add_offense(arg.parent, arg.
|
46
|
+
add_offense(arg.parent, arg.source_range,
|
46
47
|
format(MSG, 'Redundant'))
|
47
48
|
end
|
48
49
|
elsif braces_around_2nd_from_end
|
49
|
-
add_offense(arg.parent, arg.
|
50
|
+
add_offense(arg.parent, arg.source_range, format(MSG, 'Missing'))
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
54
|
# We let AutocorrectUnlessChangingAST#autocorrect work with the send
|
54
|
-
# node,
|
55
|
+
# node, because that context is needed. When parsing the code to see if
|
55
56
|
# the AST has changed, a braceless hash would not be parsed as a hash
|
56
57
|
# otherwise.
|
57
58
|
def correction(send_node)
|
@@ -85,8 +86,8 @@ module RuboCop
|
|
85
86
|
end
|
86
87
|
|
87
88
|
def add_braces(corrector, node)
|
88
|
-
corrector.insert_before(node.
|
89
|
-
corrector.insert_after(node.
|
89
|
+
corrector.insert_before(node.source_range, '{')
|
90
|
+
corrector.insert_after(node.source_range, '}')
|
90
91
|
end
|
91
92
|
|
92
93
|
def non_empty_hash?(arg)
|