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
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module Style
|
7
|
+
# If the `else` branch of a conditional consists solely of an `if` node,
|
8
|
+
# it can be combined with the `else` to become an `elsif`.
|
9
|
+
# This helps to keep the nesting level from getting too deep.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# @good
|
13
|
+
# if condition_a
|
14
|
+
# action_a
|
15
|
+
# elsif condition_b
|
16
|
+
# action_b
|
17
|
+
# else
|
18
|
+
# action_c
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# @bad
|
22
|
+
# if condition_a
|
23
|
+
# action_a
|
24
|
+
# else
|
25
|
+
# if condition_b
|
26
|
+
# action_b
|
27
|
+
# else
|
28
|
+
# action_c
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
class IfInsideElse < Cop
|
32
|
+
include IfNode
|
33
|
+
|
34
|
+
MSG = 'Convert `if` nested inside `else` to `elsif`.'.freeze
|
35
|
+
|
36
|
+
def on_if(node)
|
37
|
+
_cond, _if_branch, else_branch = *node
|
38
|
+
return unless else_branch
|
39
|
+
return unless else_branch.if_type?
|
40
|
+
return if ternary_op?(node) || ternary_op?(else_branch)
|
41
|
+
return unless else_branch.loc.keyword.is?('if')
|
42
|
+
return if node.loc.keyword.is?('unless')
|
43
|
+
|
44
|
+
add_offense(else_branch, :keyword, MSG)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
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
|
@@ -9,7 +10,8 @@ module RuboCop
|
|
9
10
|
class IfUnlessModifier < Cop
|
10
11
|
include StatementModifier
|
11
12
|
|
12
|
-
ASSIGNMENT_TYPES = [:lvasgn, :casgn, :cvasgn,
|
13
|
+
ASSIGNMENT_TYPES = [:lvasgn, :casgn, :cvasgn,
|
14
|
+
:gvasgn, :ivasgn, :masgn].freeze
|
13
15
|
|
14
16
|
def message(keyword)
|
15
17
|
"Favor modifier `#{keyword}` usage when having a single-line body." \
|
@@ -50,7 +52,7 @@ module RuboCop
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def method_uses_parens?(node, limit)
|
53
|
-
source = node.
|
55
|
+
source = node.source_range.source_line[0...limit.loc.column]
|
54
56
|
source =~ /\s*\(\s*$/
|
55
57
|
end
|
56
58
|
|
@@ -58,8 +60,7 @@ module RuboCop
|
|
58
60
|
cond, body, _else = if_node_parts(node)
|
59
61
|
|
60
62
|
oneline =
|
61
|
-
"#{body.
|
62
|
-
cond.loc.expression.source
|
63
|
+
"#{body.source} #{node.loc.keyword.source} " + cond.source
|
63
64
|
first_line_comment = processed_source.comments.find do |c|
|
64
65
|
c.loc.line == node.loc.line
|
65
66
|
end
|
@@ -68,7 +69,7 @@ module RuboCop
|
|
68
69
|
end
|
69
70
|
oneline = "(#{oneline})" if parenthesize?(node)
|
70
71
|
|
71
|
-
->(corrector) { corrector.replace(node.
|
72
|
+
->(corrector) { corrector.replace(node.source_range, oneline) }
|
72
73
|
end
|
73
74
|
end
|
74
75
|
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
|
@@ -7,7 +8,7 @@ module RuboCop
|
|
7
8
|
class IfWithSemicolon < Cop
|
8
9
|
include OnNormalIfUnless
|
9
10
|
|
10
|
-
MSG = 'Do not use if x; Use the ternary operator instead.'
|
11
|
+
MSG = 'Do not use if x; Use the ternary operator instead.'.freeze
|
11
12
|
|
12
13
|
def on_normal_if_unless(node)
|
13
14
|
beginning = node.loc.begin
|
@@ -1,62 +1,113 @@
|
|
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
|
-
# This
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
7
|
+
# This cop checks the indentation of the first element in an array literal
|
8
|
+
# where the opening bracket and the first element are on separate lines.
|
9
|
+
# The other elements' indentations are handled by the AlignArray cop.
|
10
|
+
#
|
11
|
+
# By default, array literals that are arguments in a method call with
|
12
|
+
# parentheses, and where the opening square bracket of the array is on the
|
13
|
+
# same line as the opening parenthesis of the method call, shall have
|
14
|
+
# their first element indented one step (two spaces) more than the
|
15
|
+
# position inside the opening parenthesis.
|
16
|
+
#
|
17
|
+
# Other array literals shall have their first element indented one step
|
18
|
+
# more than the start of the line where the opening square bracket is.
|
19
|
+
#
|
20
|
+
# This default style is called 'special_inside_parentheses'. Alternative
|
21
|
+
# styles are 'consistent' and 'align_brackets'. Here are examples:
|
22
|
+
#
|
23
|
+
# # special_inside_parentheses
|
24
|
+
# array = [
|
25
|
+
# :value
|
26
|
+
# ]
|
27
|
+
# but_in_a_method_call([
|
28
|
+
# :its_like_this
|
29
|
+
# ])
|
30
|
+
# # consistent
|
31
|
+
# array = [
|
32
|
+
# :value
|
33
|
+
# ]
|
34
|
+
# and_in_a_method_call([
|
35
|
+
# :no_difference
|
36
|
+
# ])
|
37
|
+
# # align_brackets
|
38
|
+
# and_now_for_something = [
|
39
|
+
# :completely_different
|
40
|
+
# ]
|
10
41
|
#
|
11
|
-
# Array literals shall have their first element indented one step (2
|
12
|
-
# spaces) more than the start of the line where the opening bracket is.
|
13
42
|
class IndentArray < Cop
|
14
43
|
include AutocorrectAlignment
|
44
|
+
include ConfigurableEnforcedStyle
|
45
|
+
include ArrayHashIndentation
|
15
46
|
|
16
47
|
def on_array(node)
|
17
|
-
|
18
|
-
|
48
|
+
check(node, nil) if node.loc.begin
|
49
|
+
end
|
19
50
|
|
20
|
-
|
21
|
-
|
22
|
-
|
51
|
+
def on_send(node)
|
52
|
+
each_argument_node(node, :array) do |array_node, left_parenthesis|
|
53
|
+
check(array_node, left_parenthesis)
|
54
|
+
end
|
23
55
|
end
|
24
56
|
|
25
|
-
|
26
|
-
return if first_pair.nil?
|
27
|
-
expr = first_pair.loc.expression
|
28
|
-
return if expr.line == left_bracket.line
|
57
|
+
private
|
29
58
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
59
|
+
def brace_alignment_style
|
60
|
+
:align_brackets
|
61
|
+
end
|
62
|
+
|
63
|
+
def check(array_node, left_parenthesis)
|
64
|
+
return if ignored_node?(array_node)
|
34
65
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
66
|
+
left_bracket = array_node.loc.begin
|
67
|
+
first_elem = array_node.children.first
|
68
|
+
if first_elem
|
69
|
+
return if first_elem.source_range.line == left_bracket.line
|
70
|
+
check_first(first_elem, left_bracket, left_parenthesis, 0)
|
71
|
+
end
|
72
|
+
|
73
|
+
check_right_bracket(array_node.loc.end, left_bracket,
|
74
|
+
left_parenthesis)
|
39
75
|
end
|
40
76
|
|
41
|
-
def check_right_bracket(
|
42
|
-
|
43
|
-
|
44
|
-
|
77
|
+
def check_right_bracket(right_bracket, left_bracket, left_parenthesis)
|
78
|
+
# if the right bracket is on the same line as the last value, accept
|
79
|
+
return if right_bracket.source_line[0...right_bracket.column] =~ /\S/
|
80
|
+
|
81
|
+
expected_column = base_column(left_bracket, left_parenthesis)
|
82
|
+
@column_delta = expected_column - right_bracket.column
|
83
|
+
return if @column_delta == 0
|
84
|
+
|
85
|
+
msg = if style == :align_brackets
|
86
|
+
'Indent the right bracket the same as the left bracket.'
|
87
|
+
elsif style == :special_inside_parentheses && left_parenthesis
|
88
|
+
'Indent the right bracket the same as the first position ' \
|
89
|
+
'after the preceding left parenthesis.'
|
90
|
+
else
|
91
|
+
'Indent the right bracket the same as the start of the line' \
|
92
|
+
' where the left bracket is.'
|
93
|
+
end
|
94
|
+
add_offense(right_bracket, right_bracket, msg)
|
95
|
+
end
|
45
96
|
|
46
|
-
|
47
|
-
|
48
|
-
|
97
|
+
# Returns the description of what the correct indentation is based on.
|
98
|
+
def base_description(left_parenthesis)
|
99
|
+
if style == :align_brackets
|
100
|
+
'the position of the opening bracket'
|
101
|
+
elsif left_parenthesis && style == :special_inside_parentheses
|
102
|
+
'the first position after the preceding left parenthesis'
|
49
103
|
else
|
50
|
-
|
51
|
-
expected_indentation =
|
52
|
-
'the start of the line where the left bracket is'
|
104
|
+
'the start of the line where the left square bracket is'
|
53
105
|
end
|
54
|
-
|
55
|
-
return if @column_delta == 0
|
106
|
+
end
|
56
107
|
|
57
|
-
|
58
|
-
|
59
|
-
|
108
|
+
def message(base_description)
|
109
|
+
format('Use %d spaces for indentation in an array, relative to %s.',
|
110
|
+
configured_indentation_width, base_description)
|
60
111
|
end
|
61
112
|
end
|
62
113
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module Style
|
7
|
+
# This cop checks the indentation of the first line of the
|
8
|
+
# right-hand-side of a multi-line assignment.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# value =
|
13
|
+
# if foo
|
14
|
+
# 'bar'
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# value =
|
19
|
+
# if foo
|
20
|
+
# 'bar'
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# The indentation of the remaining lines can be corrected with
|
24
|
+
# other cops such as `IndentationConsistency` and `EndAlignment`.
|
25
|
+
class IndentAssignment < Cop
|
26
|
+
include CheckAssignment
|
27
|
+
include AutocorrectAlignment
|
28
|
+
|
29
|
+
MSG = 'Indent the first line of the right-hand-side of a ' \
|
30
|
+
'multi-line assignment.'.freeze
|
31
|
+
|
32
|
+
def check_assignment(node, rhs)
|
33
|
+
return unless rhs
|
34
|
+
return unless node.loc.operator
|
35
|
+
return if node.loc.operator.line == rhs.loc.line
|
36
|
+
|
37
|
+
base = node.source_range.column
|
38
|
+
check_alignment([rhs], base + configured_indentation_width)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
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
|
@@ -41,43 +42,37 @@ module RuboCop
|
|
41
42
|
class IndentHash < Cop
|
42
43
|
include AutocorrectAlignment
|
43
44
|
include ConfigurableEnforcedStyle
|
45
|
+
include ArrayHashIndentation
|
44
46
|
|
45
47
|
def on_hash(node)
|
46
|
-
|
47
|
-
check(node, left_brace, nil) if left_brace
|
48
|
+
check(node, nil) if node.loc.begin
|
48
49
|
end
|
49
50
|
|
50
51
|
def on_send(node)
|
51
|
-
|
52
|
-
|
53
|
-
return unless left_parenthesis
|
54
|
-
|
55
|
-
args.each do |arg|
|
56
|
-
on_node(:hash, arg, :send) do |hash_node|
|
57
|
-
left_brace = hash_node.loc.begin
|
58
|
-
if left_brace && left_brace.line == left_parenthesis.line
|
59
|
-
check(hash_node, left_brace, left_parenthesis)
|
60
|
-
ignore_node(hash_node)
|
61
|
-
end
|
62
|
-
end
|
52
|
+
each_argument_node(node, :hash) do |hash_node, left_parenthesis|
|
53
|
+
check(hash_node, left_parenthesis)
|
63
54
|
end
|
64
55
|
end
|
65
56
|
|
66
57
|
private
|
67
58
|
|
68
|
-
def
|
59
|
+
def brace_alignment_style
|
60
|
+
:align_braces
|
61
|
+
end
|
62
|
+
|
63
|
+
def check(hash_node, left_parenthesis)
|
69
64
|
return if ignored_node?(hash_node)
|
70
65
|
|
66
|
+
left_brace = hash_node.loc.begin
|
71
67
|
first_pair = hash_node.children.first
|
72
68
|
if first_pair
|
73
|
-
|
74
|
-
return if first_pair.loc.expression.line == left_brace.line
|
69
|
+
return if first_pair.source_range.line == left_brace.line
|
75
70
|
|
76
71
|
if separator_style?(first_pair)
|
77
72
|
check_based_on_longest_key(hash_node.children, left_brace,
|
78
73
|
left_parenthesis)
|
79
74
|
else
|
80
|
-
|
75
|
+
check_first(first_pair, left_brace, left_parenthesis, 0)
|
81
76
|
end
|
82
77
|
end
|
83
78
|
|
@@ -112,66 +107,10 @@ module RuboCop
|
|
112
107
|
|
113
108
|
def check_based_on_longest_key(pairs, left_brace, left_parenthesis)
|
114
109
|
key_lengths = pairs.map do |pair|
|
115
|
-
pair.children.first.
|
116
|
-
end
|
117
|
-
check_first_pair(pairs.first, left_brace, left_parenthesis,
|
118
|
-
key_lengths.max - key_lengths.first)
|
119
|
-
end
|
120
|
-
|
121
|
-
def check_first_pair(first_pair, left_brace, left_parenthesis, offset)
|
122
|
-
actual_column = first_pair.loc.expression.column
|
123
|
-
expected_column = base_column(left_brace, left_parenthesis) +
|
124
|
-
configured_indentation_width + offset
|
125
|
-
@column_delta = expected_column - actual_column
|
126
|
-
|
127
|
-
if @column_delta == 0
|
128
|
-
# which column was actually used as 'base column' for indentation?
|
129
|
-
# (not the column which we think should be the 'base column',
|
130
|
-
# but the one which has actually been used for that purpose)
|
131
|
-
base_column = actual_column - configured_indentation_width - offset
|
132
|
-
styles = detected_styles(base_column, left_parenthesis, left_brace)
|
133
|
-
if styles.size > 1
|
134
|
-
ambiguous_style_detected(*styles)
|
135
|
-
else
|
136
|
-
correct_style_detected
|
137
|
-
end
|
138
|
-
else
|
139
|
-
incorrect_style_detected(actual_column, offset, first_pair,
|
140
|
-
left_parenthesis, left_brace)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def incorrect_style_detected(column, offset, first_pair,
|
145
|
-
left_parenthesis, left_brace)
|
146
|
-
add_offense(first_pair, :expression,
|
147
|
-
message(base_description(left_parenthesis))) do
|
148
|
-
base_column = column - configured_indentation_width - offset
|
149
|
-
styles = detected_styles(base_column, left_parenthesis, left_brace)
|
150
|
-
ambiguous_style_detected(*styles)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def detected_styles(column, left_parenthesis, left_brace)
|
155
|
-
styles = []
|
156
|
-
if column == (left_brace.source_line =~ /\S/)
|
157
|
-
styles << :consistent
|
158
|
-
styles << :special_inside_parentheses unless left_parenthesis
|
159
|
-
end
|
160
|
-
if left_parenthesis && column == left_parenthesis.column + 1
|
161
|
-
styles << :special_inside_parentheses
|
162
|
-
end
|
163
|
-
styles << :align_braces if column == left_brace.column
|
164
|
-
styles
|
165
|
-
end
|
166
|
-
|
167
|
-
def base_column(left_brace, left_parenthesis)
|
168
|
-
if style == :align_braces
|
169
|
-
left_brace.column
|
170
|
-
elsif left_parenthesis && style == :special_inside_parentheses
|
171
|
-
left_parenthesis.column + 1
|
172
|
-
else
|
173
|
-
left_brace.source_line =~ /\S/
|
110
|
+
pair.children.first.source_range.length
|
174
111
|
end
|
112
|
+
check_first(pairs.first, left_brace, left_parenthesis,
|
113
|
+
key_lengths.max - key_lengths.first)
|
175
114
|
end
|
176
115
|
|
177
116
|
# Returns the description of what the correct indentation is based on.
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -18,7 +19,7 @@ module RuboCop
|
|
18
19
|
include AccessModifierNode
|
19
20
|
include ConfigurableEnforcedStyle
|
20
21
|
|
21
|
-
MSG = 'Inconsistent indentation detected.'
|
22
|
+
MSG = 'Inconsistent indentation detected.'.freeze
|
22
23
|
|
23
24
|
def on_begin(node)
|
24
25
|
check(node)
|