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 SurroundingSpace
|
10
11
|
include ConfigurableEnforcedStyle
|
11
12
|
|
12
|
-
MSG = 'Space inside %s.'
|
13
|
+
MSG = 'Space inside %s.'.freeze
|
13
14
|
|
14
15
|
def on_hash(node)
|
15
16
|
b_ix = index_of_first_token(node)
|
@@ -19,6 +20,8 @@ module RuboCop
|
|
19
20
|
return unless tokens[b_ix].type == :tLBRACE
|
20
21
|
|
21
22
|
e_ix = index_of_last_token(node)
|
23
|
+
return unless tokens[e_ix].type == :tRCURLY
|
24
|
+
|
22
25
|
check(tokens[b_ix], tokens[b_ix + 1])
|
23
26
|
check(tokens[e_ix - 1], tokens[e_ix]) unless b_ix == e_ix - 1
|
24
27
|
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
|
@@ -18,7 +19,7 @@ module RuboCop
|
|
18
19
|
# # good
|
19
20
|
# 'a'..'z'
|
20
21
|
class SpaceInsideRangeLiteral < Cop
|
21
|
-
MSG = 'Space inside range literal.'
|
22
|
+
MSG = 'Space inside range literal.'.freeze
|
22
23
|
|
23
24
|
def on_irange(node)
|
24
25
|
check(node)
|
@@ -31,7 +32,7 @@ module RuboCop
|
|
31
32
|
private
|
32
33
|
|
33
34
|
def check(node)
|
34
|
-
expression = node.
|
35
|
+
expression = node.source
|
35
36
|
op = node.loc.operator.source
|
36
37
|
escaped_op = op.gsub(/\./, '\.')
|
37
38
|
|
@@ -44,13 +45,13 @@ module RuboCop
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def autocorrect(node)
|
47
|
-
expression = node.
|
48
|
+
expression = node.source
|
48
49
|
operator = node.loc.operator.source
|
49
50
|
operator_escaped = operator.gsub(/\./, '\.')
|
50
51
|
|
51
52
|
lambda do |corrector|
|
52
53
|
corrector.replace(
|
53
|
-
node.
|
54
|
+
node.source_range,
|
54
55
|
expression
|
55
56
|
.sub(/\s+#{operator_escaped}/, operator)
|
56
57
|
.sub(/#{operator_escaped}\s+/, operator)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -14,15 +15,15 @@ module RuboCop
|
|
14
15
|
class SpaceInsideStringInterpolation < Cop
|
15
16
|
include ConfigurableEnforcedStyle
|
16
17
|
|
17
|
-
NO_SPACE_MSG = 'Space inside string interpolation detected.'
|
18
|
-
SPACE_MSG = 'Missing space around string interpolation detected.'
|
18
|
+
NO_SPACE_MSG = 'Space inside string interpolation detected.'.freeze
|
19
|
+
SPACE_MSG = 'Missing space around string interpolation detected.'.freeze
|
19
20
|
|
20
21
|
def on_dstr(node)
|
21
22
|
node.children.select { |n| n.type == :begin }.each do |begin_node|
|
22
23
|
final_node = begin_node.children.last
|
23
24
|
next unless final_node
|
24
25
|
|
25
|
-
interp = final_node.
|
26
|
+
interp = final_node.source_range
|
26
27
|
interp_with_surrounding_space = range_with_surrounding_space(interp)
|
27
28
|
if style == :no_space
|
28
29
|
if interp_with_surrounding_space != interp
|
@@ -39,20 +40,10 @@ module RuboCop
|
|
39
40
|
private
|
40
41
|
|
41
42
|
def autocorrect(node)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
node.loc.expression.source
|
47
|
-
)
|
48
|
-
end
|
49
|
-
elsif style == :space
|
50
|
-
lambda do |corrector|
|
51
|
-
corrector.replace(
|
52
|
-
range_with_surrounding_space(node.loc.expression),
|
53
|
-
" #{node.loc.expression.source} "
|
54
|
-
)
|
55
|
-
end
|
43
|
+
new_source = (style == :no_space) ? node.source : " #{node.source} "
|
44
|
+
lambda do |corrector|
|
45
|
+
corrector.replace(range_with_surrounding_space(node.source_range),
|
46
|
+
new_source)
|
56
47
|
end
|
57
48
|
end
|
58
49
|
end
|
@@ -1,90 +1,135 @@
|
|
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 Perl-style global variables.
|
7
8
|
class SpecialGlobalVars < Cop
|
9
|
+
include ConfigurableEnforcedStyle
|
10
|
+
|
8
11
|
MSG_BOTH = 'Prefer `%s` from the stdlib \'English\' module, ' \
|
9
|
-
'or `%s` over `%s`.'
|
12
|
+
'or `%s` over `%s`.'.freeze
|
10
13
|
MSG_ENGLISH = 'Prefer `%s` from the stdlib \'English\' module ' \
|
11
|
-
'over `%s`.'
|
12
|
-
MSG_REGULAR = 'Prefer `%s` over `%s`.'
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
'
|
36
|
-
|
37
|
-
}
|
14
|
+
'over `%s`.'.freeze
|
15
|
+
MSG_REGULAR = 'Prefer `%s` over `%s`.'.freeze
|
16
|
+
|
17
|
+
ENGLISH_VARS = { # rubocop:disable Style/MutableConstant
|
18
|
+
:$: => [:$LOAD_PATH],
|
19
|
+
:$" => [:$LOADED_FEATURES],
|
20
|
+
:$0 => [:$PROGRAM_NAME],
|
21
|
+
:$! => [:$ERROR_INFO],
|
22
|
+
:$@ => [:$ERROR_POSITION],
|
23
|
+
:$; => [:$FIELD_SEPARATOR, :$FS],
|
24
|
+
:$, => [:$OUTPUT_FIELD_SEPARATOR, :$OFS],
|
25
|
+
:$/ => [:$INPUT_RECORD_SEPARATOR, :$RS],
|
26
|
+
:$\ => [:$OUTPUT_RECORD_SEPARATOR, :$ORS],
|
27
|
+
:$. => [:$INPUT_LINE_NUMBER, :$NR],
|
28
|
+
:$_ => [:$LAST_READ_LINE],
|
29
|
+
:$> => [:$DEFAULT_OUTPUT],
|
30
|
+
:$< => [:$DEFAULT_INPUT],
|
31
|
+
:$$ => [:$PROCESS_ID, :$PID],
|
32
|
+
:$? => [:$CHILD_STATUS],
|
33
|
+
:$~ => [:$LAST_MATCH_INFO],
|
34
|
+
:$= => [:$IGNORECASE],
|
35
|
+
:$* => [:$ARGV, :ARGV],
|
36
|
+
:$& => [:$MATCH],
|
37
|
+
:$` => [:$PREMATCH],
|
38
|
+
:$' => [:$POSTMATCH],
|
39
|
+
:$+ => [:$LAST_PAREN_MATCH]
|
40
|
+
}
|
41
|
+
|
42
|
+
PERL_VARS =
|
43
|
+
Hash[ENGLISH_VARS.flat_map { |k, vs| vs.map { |v| [v, [k]] } }]
|
44
|
+
|
45
|
+
ENGLISH_VARS.merge!(
|
46
|
+
Hash[ENGLISH_VARS.flat_map { |_, vs| vs.map { |v| [v, [v]] } }])
|
47
|
+
PERL_VARS.merge!(
|
48
|
+
Hash[PERL_VARS.flat_map { |_, vs| vs.map { |v| [v, [v]] } }])
|
49
|
+
ENGLISH_VARS.each { |_, v| v.freeze }.freeze
|
50
|
+
PERL_VARS.each { |_, v| v.freeze }.freeze
|
38
51
|
|
39
52
|
# Anything *not* in this set is provided by the English library.
|
40
53
|
NON_ENGLISH_VARS = Set.new([
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
54
|
+
:$LOAD_PATH,
|
55
|
+
:$LOADED_FEATURES,
|
56
|
+
:$PROGRAM_NAME,
|
57
|
+
:ARGV
|
58
|
+
]).freeze
|
46
59
|
|
47
60
|
def on_gvar(node)
|
48
61
|
global_var, = *node
|
49
62
|
|
50
|
-
|
63
|
+
return unless (preferred = preferred_names(global_var))
|
64
|
+
|
65
|
+
if preferred.include?(global_var)
|
66
|
+
correct_style_detected
|
67
|
+
else
|
68
|
+
opposite_style_detected
|
69
|
+
add_offense(node, :expression)
|
70
|
+
end
|
51
71
|
end
|
52
72
|
|
53
73
|
def message(node)
|
54
74
|
global_var, = *node
|
55
75
|
|
56
|
-
|
57
|
-
|
58
|
-
|
76
|
+
if style == :use_english_names
|
77
|
+
regular, english = ENGLISH_VARS[global_var].partition do |var|
|
78
|
+
NON_ENGLISH_VARS.include? var
|
79
|
+
end
|
59
80
|
|
60
|
-
|
61
|
-
|
62
|
-
|
81
|
+
# For now, we assume that lists are 2 items or less. Easy grammar!
|
82
|
+
regular_msg = regular.join('` or `')
|
83
|
+
english_msg = english.join('` or `')
|
63
84
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
85
|
+
if regular.length > 0 && english.length > 0
|
86
|
+
format(MSG_BOTH, english_msg, regular_msg, global_var)
|
87
|
+
elsif regular.length > 0
|
88
|
+
format(MSG_REGULAR, regular_msg, global_var)
|
89
|
+
elsif english.length > 0
|
90
|
+
format(MSG_ENGLISH, english_msg, global_var)
|
91
|
+
else
|
92
|
+
fail 'Bug in SpecialGlobalVars - global var w/o preferred vars!'
|
93
|
+
end
|
70
94
|
else
|
71
|
-
|
95
|
+
format(MSG_REGULAR, preferred_names(global_var).first, global_var)
|
72
96
|
end
|
73
97
|
end
|
74
98
|
|
75
99
|
def autocorrect(node)
|
76
100
|
lambda do |corrector|
|
77
101
|
global_var, = *node
|
78
|
-
|
102
|
+
|
103
|
+
while node.parent && node.parent.begin_type? &&
|
104
|
+
node.parent.children.one?
|
105
|
+
node = node.parent
|
106
|
+
end
|
107
|
+
parent_type = node.parent && node.parent.type
|
108
|
+
|
79
109
|
if [:dstr, :xstr, :regexp].include?(parent_type)
|
80
|
-
|
81
|
-
|
110
|
+
if style == :use_english_names
|
111
|
+
corrector.replace(node.source_range,
|
112
|
+
"{#{preferred_names(global_var).first}}")
|
113
|
+
else
|
114
|
+
corrector.replace(node.source_range,
|
115
|
+
"##{preferred_names(global_var).first}")
|
116
|
+
end
|
82
117
|
else
|
83
|
-
corrector.replace(node.
|
84
|
-
|
118
|
+
corrector.replace(node.source_range,
|
119
|
+
preferred_names(global_var).first.to_s)
|
85
120
|
end
|
86
121
|
end
|
87
122
|
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def preferred_names(global)
|
127
|
+
if style == :use_english_names
|
128
|
+
ENGLISH_VARS[global]
|
129
|
+
else
|
130
|
+
PERL_VARS[global]
|
131
|
+
end
|
132
|
+
end
|
88
133
|
end
|
89
134
|
end
|
90
135
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
module RuboCop
|
3
4
|
module Cop
|
4
5
|
module Style
|
@@ -18,13 +19,15 @@ module RuboCop
|
|
18
19
|
# # require_parentheses - good
|
19
20
|
# ->a,b,c { a + b + c}
|
20
21
|
class StabbyLambdaParentheses < Cop
|
21
|
-
MSG_REQUIRE = 'Wrap stabby lambda arguments with parentheses.'
|
22
|
-
MSG_NO_REQUIRE = 'Do not wrap stabby lambda arguments with parentheses.'
|
23
|
-
|
24
22
|
include ConfigurableEnforcedStyle
|
25
23
|
|
24
|
+
MSG_REQUIRE = 'Wrap stabby lambda arguments with parentheses.'.freeze
|
25
|
+
MSG_NO_REQUIRE = 'Do not wrap stabby lambda arguments ' \
|
26
|
+
'with parentheses.'.freeze
|
27
|
+
ARROW = '->'.freeze
|
28
|
+
|
26
29
|
def on_send(node)
|
27
|
-
return unless
|
30
|
+
return unless arrow_lambda_with_args?(node)
|
28
31
|
|
29
32
|
if style == :require_parentheses
|
30
33
|
if parentheses?(node)
|
@@ -63,7 +66,7 @@ module RuboCop
|
|
63
66
|
|
64
67
|
def missing_parentheses_corrector(node)
|
65
68
|
lambda do |corrector|
|
66
|
-
args_loc = node_args(node).
|
69
|
+
args_loc = node_args(node).source_range
|
67
70
|
|
68
71
|
corrector.insert_before(args_loc, '(')
|
69
72
|
corrector.insert_after(args_loc, ')')
|
@@ -79,13 +82,17 @@ module RuboCop
|
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
82
|
-
def
|
83
|
-
lambda_node?(node) && args?(node)
|
85
|
+
def arrow_lambda_with_args?(node)
|
86
|
+
lambda_node?(node) && arrow_form?(node) && args?(node)
|
84
87
|
end
|
85
88
|
|
86
89
|
def lambda_node?(node)
|
87
|
-
|
88
|
-
call == :lambda
|
90
|
+
receiver, call = *node
|
91
|
+
receiver.nil? && call == :lambda
|
92
|
+
end
|
93
|
+
|
94
|
+
def arrow_form?(node)
|
95
|
+
node.loc.selector.source == ARROW
|
89
96
|
end
|
90
97
|
|
91
98
|
def node_args(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
|
@@ -8,6 +9,28 @@ module RuboCop
|
|
8
9
|
include ConfigurableEnforcedStyle
|
9
10
|
include StringLiteralsHelp
|
10
11
|
|
12
|
+
MSG_INCONSISTENT = 'Inconsistent quote style.'.freeze
|
13
|
+
|
14
|
+
def on_dstr(node)
|
15
|
+
# Strings which are continued across multiple lines using \
|
16
|
+
# are parsed as a `dstr` node with `str` children
|
17
|
+
# If one part of that continued string contains interpolations,
|
18
|
+
# then it will be parsed as a nested `dstr` node
|
19
|
+
return unless consistent_multiline?
|
20
|
+
|
21
|
+
children = node.children
|
22
|
+
return unless children.all? { |c| c.str_type? || c.dstr_type? }
|
23
|
+
|
24
|
+
quote_styles = children.map { |c| c.loc.begin.source }.uniq
|
25
|
+
if quote_styles.size > 1
|
26
|
+
add_offense(node, :expression, MSG_INCONSISTENT)
|
27
|
+
else
|
28
|
+
check_multiline_quote_style(node, quote_styles[0])
|
29
|
+
end
|
30
|
+
|
31
|
+
ignore_node(node)
|
32
|
+
end
|
33
|
+
|
11
34
|
private
|
12
35
|
|
13
36
|
def message(*)
|
@@ -25,7 +48,24 @@ module RuboCop
|
|
25
48
|
# for this cop.
|
26
49
|
return false if inside_interpolation?(node)
|
27
50
|
|
28
|
-
wrong_quotes?(node
|
51
|
+
wrong_quotes?(node)
|
52
|
+
end
|
53
|
+
|
54
|
+
def consistent_multiline?
|
55
|
+
cop_config['ConsistentQuotesInMultiline']
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_multiline_quote_style(node, quote)
|
59
|
+
range = node.source_range
|
60
|
+
children = node.children
|
61
|
+
if quote == "'" && style == :double_quotes
|
62
|
+
add_offense(node, range) if children.all? { |c| wrong_quotes?(c) }
|
63
|
+
elsif quote == '"' && style == :single_quotes
|
64
|
+
if children.none?(&:dstr_type?) &&
|
65
|
+
children.none? { |c| double_quotes_acceptable?(c.str_content) }
|
66
|
+
add_offense(node, range)
|
67
|
+
end
|
68
|
+
end
|
29
69
|
end
|
30
70
|
end
|
31
71
|
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
|
@@ -22,7 +23,7 @@ module RuboCop
|
|
22
23
|
# offense for this cop.
|
23
24
|
return false unless inside_interpolation?(node)
|
24
25
|
|
25
|
-
wrong_quotes?(node
|
26
|
+
wrong_quotes?(node)
|
26
27
|
end
|
27
28
|
end
|
28
29
|
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
|
@@ -8,7 +9,7 @@ module RuboCop
|
|
8
9
|
class StringMethods < Cop
|
9
10
|
include MethodPreference
|
10
11
|
|
11
|
-
MSG = 'Prefer `%s` over `%s`.'
|
12
|
+
MSG = 'Prefer `%s` over `%s`.'.freeze
|
12
13
|
|
13
14
|
def on_send(node)
|
14
15
|
_receiver, method_name, *_args = *node
|