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
|
@@ -7,10 +8,6 @@ module RuboCop
|
|
7
8
|
# adding offenses for the faulty string nodes, and with filtering out
|
8
9
|
# nodes.
|
9
10
|
module StringHelp
|
10
|
-
# Regex matches IF there is a ' or there is a \\ in the string that is
|
11
|
-
# not preceded/followed by another \\ (e.g. "\\x34") but not "\\\\".
|
12
|
-
ESCAPED_CHAR_REGEXP = /(?<! \\) \\{2}* \\ (?! \\)/x
|
13
|
-
|
14
11
|
def on_str(node)
|
15
12
|
# Constants like __FILE__ are handled as strings,
|
16
13
|
# but don't respond to begin.
|
@@ -30,11 +27,7 @@ module RuboCop
|
|
30
27
|
|
31
28
|
def inside_interpolation?(node)
|
32
29
|
# A :begin node inside a :dstr node is an interpolation.
|
33
|
-
|
34
|
-
node.each_ancestor.any? do |a|
|
35
|
-
begin_found = true if a.type == :begin
|
36
|
-
begin_found && a.type == :dstr
|
37
|
-
end
|
30
|
+
node.ancestors.drop_while { |a| !a.begin_type? }.any?(&:dstr_type?)
|
38
31
|
end
|
39
32
|
end
|
40
33
|
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,21 +7,26 @@ module RuboCop
|
|
6
7
|
module StringLiteralsHelp
|
7
8
|
include StringHelp
|
8
9
|
|
9
|
-
def wrong_quotes?(node
|
10
|
-
src = node.
|
11
|
-
return false if src.start_with?('%'
|
10
|
+
def wrong_quotes?(node)
|
11
|
+
src = node.source
|
12
|
+
return false if src.start_with?('%', '?')
|
12
13
|
if style == :single_quotes
|
13
|
-
src !~ /'/ &&
|
14
|
+
src !~ /'/ && !double_quotes_acceptable?(node.str_content)
|
14
15
|
else
|
15
16
|
src !~ /" | \\ | \#/x
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
20
|
def autocorrect(node)
|
21
|
+
return if node.dstr_type?
|
22
|
+
|
20
23
|
lambda do |corrector|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
str = node.str_content
|
25
|
+
if style == :single_quotes
|
26
|
+
corrector.replace(node.source_range, to_string_literal(str))
|
27
|
+
else
|
28
|
+
corrector.replace(node.source_range, str.inspect)
|
29
|
+
end
|
24
30
|
end
|
25
31
|
end
|
26
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
|
@@ -16,12 +17,12 @@ module RuboCop
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def index_of_first_token(node)
|
19
|
-
b = node.
|
20
|
+
b = node.source_range.begin
|
20
21
|
token_table[b.line][b.column]
|
21
22
|
end
|
22
23
|
|
23
24
|
def index_of_last_token(node)
|
24
|
-
e = node.
|
25
|
+
e = node.source_range.end
|
25
26
|
(0...e.column).to_a.reverse_each do |c|
|
26
27
|
ix = token_table[e.line][c]
|
27
28
|
return ix if ix
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
# Common methods shared by Style/TrailingCommaInArguments and
|
7
|
+
# Style/TrailingCommaInLiteral
|
8
|
+
module TrailingComma
|
9
|
+
include ConfigurableEnforcedStyle
|
10
|
+
|
11
|
+
MSG = '%s comma after the last %s'.freeze
|
12
|
+
|
13
|
+
def parameter_name
|
14
|
+
'EnforcedStyleForMultiline'
|
15
|
+
end
|
16
|
+
|
17
|
+
def check(node, items, kind, begin_pos, end_pos)
|
18
|
+
sb = node.source_range.source_buffer
|
19
|
+
after_last_item = Parser::Source::Range.new(sb, begin_pos, end_pos)
|
20
|
+
|
21
|
+
return if heredoc?(after_last_item.source)
|
22
|
+
|
23
|
+
comma_offset = after_last_item.source =~ /,/
|
24
|
+
|
25
|
+
if comma_offset && !inside_comment?(after_last_item, comma_offset)
|
26
|
+
unless should_have_comma?(style, node)
|
27
|
+
extra_info = case style
|
28
|
+
when :comma
|
29
|
+
', unless each item is on its own line'
|
30
|
+
when :consistent_comma
|
31
|
+
', unless items are split onto multiple lines'
|
32
|
+
else
|
33
|
+
''
|
34
|
+
end
|
35
|
+
avoid_comma(kind, after_last_item.begin_pos + comma_offset, sb,
|
36
|
+
extra_info)
|
37
|
+
end
|
38
|
+
elsif should_have_comma?(style, node)
|
39
|
+
put_comma(items, kind, sb)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def should_have_comma?(style, node)
|
44
|
+
[:comma, :consistent_comma].include?(style) &&
|
45
|
+
multiline?(node)
|
46
|
+
end
|
47
|
+
|
48
|
+
def inside_comment?(range, comma_offset)
|
49
|
+
processed_source.comments.any? do |comment|
|
50
|
+
comment_offset = comment.loc.expression.begin_pos - range.begin_pos
|
51
|
+
comment_offset >= 0 && comment_offset < comma_offset
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def heredoc?(source_after_last_item)
|
56
|
+
source_after_last_item =~ /\w/
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns true if the node has round/square/curly brackets.
|
60
|
+
def brackets?(node)
|
61
|
+
node.loc.end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns true if the round/square/curly brackets of the given node are
|
65
|
+
# on different lines, and each item within is on its own line, and the
|
66
|
+
# closing bracket is on its own line.
|
67
|
+
def multiline?(node)
|
68
|
+
elements = if node.type == :send
|
69
|
+
_receiver, _method_name, *args = *node
|
70
|
+
args.flat_map do |a|
|
71
|
+
# For each argument, if it is a multi-line hash,
|
72
|
+
# then promote the hash elements to method arguments
|
73
|
+
# for the purpose of determining multi-line-ness.
|
74
|
+
if a.hash_type? && a.loc.first_line != a.loc.last_line
|
75
|
+
a.children
|
76
|
+
else
|
77
|
+
a
|
78
|
+
end
|
79
|
+
end
|
80
|
+
else
|
81
|
+
node.children
|
82
|
+
end
|
83
|
+
|
84
|
+
# Without this check, Foo.new({}) is considered multiline, which
|
85
|
+
# it should not be. Essentially, if there are no elements, the
|
86
|
+
# expression can not be multiline.
|
87
|
+
return if elements.empty?
|
88
|
+
|
89
|
+
items = elements.map(&:source_range)
|
90
|
+
if style == :consistent_comma
|
91
|
+
items.one? || items.each_cons(2).any? { |a, b| !on_same_line?(a, b) }
|
92
|
+
else
|
93
|
+
items << node.loc.end
|
94
|
+
items.each_cons(2).all? { |a, b| !on_same_line?(a, b) }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def on_same_line?(a, b)
|
99
|
+
a.last_line == b.line
|
100
|
+
end
|
101
|
+
|
102
|
+
def avoid_comma(kind, comma_begin_pos, sb, extra_info)
|
103
|
+
range = Parser::Source::Range.new(sb, comma_begin_pos,
|
104
|
+
comma_begin_pos + 1)
|
105
|
+
article = kind =~ /array/ ? 'an' : 'a'
|
106
|
+
add_offense(range, range,
|
107
|
+
format(MSG, 'Avoid', format(kind, article)) +
|
108
|
+
"#{extra_info}.")
|
109
|
+
end
|
110
|
+
|
111
|
+
def put_comma(items, kind, sb)
|
112
|
+
last_item = items.last
|
113
|
+
return if last_item.type == :block_pass
|
114
|
+
|
115
|
+
last_expr = last_item.source_range
|
116
|
+
ix = last_expr.source.rindex("\n") || 0
|
117
|
+
ix += last_expr.source[ix..-1] =~ /\S/
|
118
|
+
range = Parser::Source::Range.new(sb, last_expr.begin_pos + ix,
|
119
|
+
last_expr.end_pos)
|
120
|
+
add_offense(range, range,
|
121
|
+
format(MSG, 'Put a', format(kind, 'a multiline') + '.'))
|
122
|
+
end
|
123
|
+
|
124
|
+
def autocorrect(range)
|
125
|
+
lambda do |corrector|
|
126
|
+
case range.source
|
127
|
+
when ',' then corrector.remove(range)
|
128
|
+
else corrector.insert_after(range, ',')
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/lib/rubocop/cop/offense.rb
CHANGED
@@ -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,8 @@ module RuboCop
|
|
7
8
|
include Comparable
|
8
9
|
|
9
10
|
# @api private
|
10
|
-
COMPARISON_ATTRIBUTES = [:line, :column, :cop_name,
|
11
|
+
COMPARISON_ATTRIBUTES = [:line, :column, :cop_name,
|
12
|
+
:message, :severity].freeze
|
11
13
|
|
12
14
|
# @api public
|
13
15
|
#
|
@@ -50,6 +52,20 @@ module RuboCop
|
|
50
52
|
# 'LineLength'
|
51
53
|
attr_reader :cop_name
|
52
54
|
|
55
|
+
# @api private
|
56
|
+
attr_reader :status
|
57
|
+
|
58
|
+
# @api private
|
59
|
+
def initialize(severity, location, message, cop_name,
|
60
|
+
status = :uncorrected)
|
61
|
+
@severity = RuboCop::Cop::Severity.new(severity)
|
62
|
+
@location = location
|
63
|
+
@message = message.freeze
|
64
|
+
@cop_name = cop_name.freeze
|
65
|
+
@status = status
|
66
|
+
freeze
|
67
|
+
end
|
68
|
+
|
53
69
|
# @api public
|
54
70
|
#
|
55
71
|
# @!attribute [r] corrected
|
@@ -59,7 +75,7 @@ module RuboCop
|
|
59
75
|
def corrected
|
60
76
|
@status == :unsupported ? nil : @status == :corrected
|
61
77
|
end
|
62
|
-
|
78
|
+
alias corrected? corrected
|
63
79
|
|
64
80
|
# @api public
|
65
81
|
#
|
@@ -71,17 +87,6 @@ module RuboCop
|
|
71
87
|
@status == :disabled
|
72
88
|
end
|
73
89
|
|
74
|
-
# @api private
|
75
|
-
def initialize(severity, location, message, cop_name,
|
76
|
-
status = :uncorrected)
|
77
|
-
@severity = RuboCop::Cop::Severity.new(severity)
|
78
|
-
@location = location
|
79
|
-
@message = message.freeze
|
80
|
-
@cop_name = cop_name.freeze
|
81
|
-
@status = status
|
82
|
-
freeze
|
83
|
-
end
|
84
|
-
|
85
90
|
# @api private
|
86
91
|
# This is just for debugging purpose.
|
87
92
|
def to_s
|
@@ -118,7 +123,7 @@ module RuboCop
|
|
118
123
|
end
|
119
124
|
end
|
120
125
|
|
121
|
-
|
126
|
+
alias eql? ==
|
122
127
|
|
123
128
|
def hash
|
124
129
|
COMPARISON_ATTRIBUTES.reduce(0) do |hash, attribute|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -71,7 +72,7 @@ module RuboCop
|
|
71
72
|
end
|
72
73
|
|
73
74
|
splat_offenses(when_conditions).reverse_each do |condition|
|
74
|
-
range = condition.parent.loc.keyword.join(condition.
|
75
|
+
range = condition.parent.loc.keyword.join(condition.source_range)
|
75
76
|
variable, = *condition
|
76
77
|
message = variable.array_type? ? ARRAY_MSG : MSG
|
77
78
|
add_offense(condition.parent, range, message)
|
@@ -116,7 +117,7 @@ module RuboCop
|
|
116
117
|
corrector.remove(variable.loc.begin)
|
117
118
|
corrector.remove(variable.loc.end)
|
118
119
|
else
|
119
|
-
corrector.replace(condition.
|
120
|
+
corrector.replace(condition.source_range,
|
120
121
|
expand_percent_array(variable))
|
121
122
|
end
|
122
123
|
end
|
@@ -126,23 +127,22 @@ module RuboCop
|
|
126
127
|
_case_branch, *when_branches, _else_branch = *node.parent
|
127
128
|
current_index = when_branches.index { |branch| branch == node }
|
128
129
|
next_branch = when_branches[current_index + 1]
|
129
|
-
correction = "\n#{offset(node)}#{node.
|
130
|
+
correction = "\n#{offset(node)}#{node.source}"
|
130
131
|
range =
|
131
132
|
Parser::Source::Range.new(node.parent,
|
132
|
-
node.
|
133
|
-
next_branch.
|
133
|
+
node.source_range.begin_pos,
|
134
|
+
next_branch.source_range.begin_pos)
|
134
135
|
|
135
136
|
lambda do |corrector|
|
136
137
|
corrector.remove(range)
|
137
|
-
corrector.insert_after(when_branches.last.
|
138
|
-
correction)
|
138
|
+
corrector.insert_after(when_branches.last.source_range, correction)
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
142
|
def expand_percent_array(array)
|
143
143
|
array_start = array.loc.begin.source
|
144
144
|
elements = *array
|
145
|
-
elements = elements.map
|
145
|
+
elements = elements.map(&:source)
|
146
146
|
|
147
147
|
if array_start.start_with?(PERCENT_W)
|
148
148
|
"'#{elements.join("', '")}'"
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module Performance
|
7
|
+
# This cop identifies places where a case-insensitive string comparison
|
8
|
+
# can better be implemented using `casecmp`.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# @bad
|
12
|
+
# 'abc'.downcase == 'ABC'
|
13
|
+
# 'abc'.upcase.eql? 'ABC'
|
14
|
+
#
|
15
|
+
# @good
|
16
|
+
# 'abc'.casecmp('ABC')
|
17
|
+
class Casecmp < Cop
|
18
|
+
MSG = 'Use `casecmp` instead of `%s %s`.'.freeze
|
19
|
+
|
20
|
+
def_node_matcher :downcase_eq, <<-END
|
21
|
+
(send $(send _ ${:downcase :upcase}) ${:== :eql?} _)
|
22
|
+
END
|
23
|
+
|
24
|
+
def on_send(node)
|
25
|
+
downcase_eq(node) do |send_downcase, case_method, eq_method|
|
26
|
+
range = node.loc.selector.join(send_downcase.loc.selector)
|
27
|
+
add_offense(node, range, format(MSG, case_method, eq_method))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def autocorrect(node)
|
32
|
+
receiver, _method, arg = *node
|
33
|
+
range = Parser::Source::Range.new(node.source_range.source_buffer,
|
34
|
+
receiver.loc.selector.begin_pos,
|
35
|
+
arg.loc.begin.begin_pos)
|
36
|
+
|
37
|
+
lambda do |corrector|
|
38
|
+
# we want resulting call to be parenthesized
|
39
|
+
# if arg already includes one or more sets of parens, don't add more
|
40
|
+
# or if method call already used parens, again, don't add more
|
41
|
+
if arg.loc.begin.source == '('
|
42
|
+
corrector.replace(range, 'casecmp')
|
43
|
+
elsif range.source =~ /\(/
|
44
|
+
corrector.replace(range, 'casecmp(')
|
45
|
+
else
|
46
|
+
corrector.replace(range, 'casecmp(')
|
47
|
+
corrector.insert_after(arg.source_range, ')')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
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
|
@@ -24,10 +25,10 @@ module RuboCop
|
|
24
25
|
# Model.select('field AS field_one').count
|
25
26
|
# Model.select(:value).count
|
26
27
|
class Count < Cop
|
27
|
-
MSG = 'Use `count` instead of `%s...%s`.'
|
28
|
+
MSG = 'Use `count` instead of `%s...%s`.'.freeze
|
28
29
|
|
29
|
-
SELECTORS = [:reject, :select]
|
30
|
-
COUNTERS = [:count, :length, :size]
|
30
|
+
SELECTORS = [:reject, :select].freeze
|
31
|
+
COUNTERS = [:count, :length, :size].freeze
|
31
32
|
|
32
33
|
def on_send(node)
|
33
34
|
selector, selector_loc, params, counter = parse(node)
|
@@ -36,9 +37,9 @@ module RuboCop
|
|
36
37
|
return if params && !params.block_pass_type?
|
37
38
|
return if node.parent && node.parent.block_type?
|
38
39
|
|
39
|
-
range = Parser::Source::Range.new(node.
|
40
|
+
range = Parser::Source::Range.new(node.source_range.source_buffer,
|
40
41
|
selector_loc.begin_pos,
|
41
|
-
node.
|
42
|
+
node.source_range.end_pos)
|
42
43
|
|
43
44
|
add_offense(node, range, format(MSG, selector, counter))
|
44
45
|
end
|
@@ -48,9 +49,9 @@ module RuboCop
|
|
48
49
|
|
49
50
|
return if selector == :reject
|
50
51
|
|
51
|
-
range = Parser::Source::Range.new(node.
|
52
|
+
range = Parser::Source::Range.new(node.source_range.source_buffer,
|
52
53
|
node.loc.dot.begin_pos,
|
53
|
-
node.
|
54
|
+
node.source_range.end_pos)
|
54
55
|
|
55
56
|
lambda do |corrector|
|
56
57
|
corrector.remove(range)
|
@@ -68,8 +69,8 @@ module RuboCop
|
|
68
69
|
if selector.is_a?(Symbol)
|
69
70
|
if expression && expression.parent.loc.respond_to?(:selector)
|
70
71
|
expression.parent.loc.selector
|
71
|
-
|
72
|
-
left.loc.selector
|
72
|
+
elsif left.loc.respond_to?(:selector)
|
73
|
+
left.loc.selector
|
73
74
|
end
|
74
75
|
else
|
75
76
|
_enumerable, selector, params = *expression
|