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,120 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module Lint
|
7
|
+
# This cop checks for `private` or `protected` access modifiers which are
|
8
|
+
# applied to a singleton method. These access modifiers do not make
|
9
|
+
# singleton methods private/protected. `private_class_method` can be
|
10
|
+
# used for that.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# @bad
|
14
|
+
# class C
|
15
|
+
# private
|
16
|
+
#
|
17
|
+
# def self.method
|
18
|
+
# puts 'hi'
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# @good
|
23
|
+
# class C
|
24
|
+
# def self.method
|
25
|
+
# puts 'hi'
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# private_class_method :method
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# class C
|
32
|
+
# class << self
|
33
|
+
# private
|
34
|
+
#
|
35
|
+
# def method
|
36
|
+
# puts 'hi'
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
class IneffectiveAccessModifier < Cop
|
41
|
+
MSG = '`%s` (on line %d) does not make singleton methods %s. ' \
|
42
|
+
'Use %s instead.'.freeze
|
43
|
+
ALTERNATIVE_PRIVATE = '`private_class_method` or `private` inside a ' \
|
44
|
+
'`class << self` block'.freeze
|
45
|
+
ALTERNATIVE_PROTECTED = '`protected` inside a `class << self` ' \
|
46
|
+
'block'.freeze
|
47
|
+
|
48
|
+
def_node_matcher :access_modifier, <<-PATTERN
|
49
|
+
(send nil ${:public :protected :private})
|
50
|
+
PATTERN
|
51
|
+
|
52
|
+
def_node_matcher :private_class_method, <<-PATTERN
|
53
|
+
(send nil :private_class_method $...)
|
54
|
+
PATTERN
|
55
|
+
|
56
|
+
def on_class(node)
|
57
|
+
check_node(node.children[2]) # class body
|
58
|
+
end
|
59
|
+
|
60
|
+
def on_module(node)
|
61
|
+
check_node(node.children[1]) # module body
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def clear
|
67
|
+
@useless = {}
|
68
|
+
@last_access_modifier = nil
|
69
|
+
end
|
70
|
+
|
71
|
+
def check_node(node)
|
72
|
+
if node && node.begin_type?
|
73
|
+
clear
|
74
|
+
check_scope(node)
|
75
|
+
|
76
|
+
@useless.each do |_name, (defs_node, visibility, modifier)|
|
77
|
+
add_offense(defs_node, :keyword,
|
78
|
+
format_message(visibility, modifier))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def format_message(visibility, modifier)
|
84
|
+
alternative = if visibility == :private
|
85
|
+
ALTERNATIVE_PRIVATE
|
86
|
+
else
|
87
|
+
ALTERNATIVE_PROTECTED
|
88
|
+
end
|
89
|
+
format(MSG, visibility, modifier.location.expression.line, visibility,
|
90
|
+
alternative)
|
91
|
+
end
|
92
|
+
|
93
|
+
def check_scope(node, cur_vis = :public)
|
94
|
+
node.children.each do |child|
|
95
|
+
if (new_vis = access_modifier(child))
|
96
|
+
@last_access_modifier = child
|
97
|
+
cur_vis = new_vis
|
98
|
+
elsif child.defs_type?
|
99
|
+
if cur_vis != :public
|
100
|
+
_, method_name, = *child
|
101
|
+
@useless[method_name] = [child, cur_vis, @last_access_modifier]
|
102
|
+
end
|
103
|
+
elsif (methods = private_class_method(child))
|
104
|
+
# don't warn about defs nodes which are followed by a call to
|
105
|
+
# `private_class_method :name`
|
106
|
+
# obviously the programmer knows what they are doing
|
107
|
+
methods.select(&:sym_type?).each do |sym|
|
108
|
+
@useless.delete(sym.children[0])
|
109
|
+
end
|
110
|
+
elsif child.kwbegin_type?
|
111
|
+
cur_vis = check_scope(child, cur_vis)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
cur_vis
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
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
|
@@ -27,7 +28,8 @@ module RuboCop
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def alternative_message(diagnostic)
|
30
|
-
diagnostic
|
31
|
+
diagnostic
|
32
|
+
.message
|
31
33
|
.capitalize
|
32
34
|
.gsub('character syntax', 'character literal')
|
33
35
|
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
|
# end
|
19
20
|
#
|
20
21
|
class LiteralInCondition < Cop
|
21
|
-
MSG = 'Literal `%s` appeared in a condition.'
|
22
|
+
MSG = 'Literal `%s` appeared in a condition.'.freeze
|
22
23
|
|
23
24
|
def on_if(node)
|
24
25
|
check_for_literal(node)
|
@@ -53,7 +54,7 @@ module RuboCop
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def message(node)
|
56
|
-
format(MSG, node.
|
57
|
+
format(MSG, node.source)
|
57
58
|
end
|
58
59
|
|
59
60
|
private
|
@@ -62,7 +63,7 @@ module RuboCop
|
|
62
63
|
cond, = *node
|
63
64
|
|
64
65
|
# if the cond node is literal we obviously have a problem
|
65
|
-
if literal?
|
66
|
+
if cond.literal?
|
66
67
|
add_offense(cond, :expression)
|
67
68
|
else
|
68
69
|
# alternatively we have to consider a logical node with a
|
@@ -79,15 +80,11 @@ module RuboCop
|
|
79
80
|
method_name == :!
|
80
81
|
end
|
81
82
|
|
82
|
-
def literal?(node)
|
83
|
-
LITERALS.include?(node.type)
|
84
|
-
end
|
85
|
-
|
86
83
|
def basic_literal?(node)
|
87
84
|
if node && node.type == :array
|
88
85
|
primitive_array?(node)
|
89
86
|
else
|
90
|
-
|
87
|
+
node.basic_literal?
|
91
88
|
end
|
92
89
|
end
|
93
90
|
|
@@ -114,7 +111,7 @@ module RuboCop
|
|
114
111
|
end
|
115
112
|
|
116
113
|
def handle_node(node)
|
117
|
-
if literal?
|
114
|
+
if node.literal?
|
118
115
|
add_offense(node, :expression)
|
119
116
|
elsif [:send, :and, :or, :begin].include?(node.type)
|
120
117
|
check_node(node)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -9,26 +10,22 @@ module RuboCop
|
|
9
10
|
#
|
10
11
|
# "result is #{10}"
|
11
12
|
class LiteralInInterpolation < Cop
|
12
|
-
|
13
|
-
:hash, :regexp, :nil, :true, :false]
|
14
|
-
|
15
|
-
MSG = 'Literal interpolation detected.'
|
13
|
+
MSG = 'Literal interpolation detected.'.freeze
|
16
14
|
|
17
15
|
def on_dstr(node)
|
18
16
|
node.children.select { |n| n.type == :begin }.each do |begin_node|
|
19
17
|
final_node = begin_node.children.last
|
20
18
|
next unless final_node
|
21
19
|
next if special_keyword?(final_node)
|
22
|
-
next unless
|
20
|
+
next unless final_node.literal?
|
23
21
|
|
24
22
|
add_offense(final_node, :expression)
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
26
|
def autocorrect(node)
|
29
|
-
expr = node.parent.loc.expression
|
30
27
|
value = autocorrected_value(node)
|
31
|
-
->(corrector) { corrector.replace(
|
28
|
+
->(corrector) { corrector.replace(node.parent.source_range, value) }
|
32
29
|
end
|
33
30
|
|
34
31
|
private
|
@@ -36,11 +33,11 @@ module RuboCop
|
|
36
33
|
def special_keyword?(node)
|
37
34
|
# handle strings like __FILE__
|
38
35
|
(node.type == :str && !node.loc.respond_to?(:begin)) ||
|
39
|
-
node.
|
36
|
+
node.source_range.is?('__LINE__')
|
40
37
|
end
|
41
38
|
|
42
39
|
def autocorrected_value(node)
|
43
|
-
node.str_type? ? node.children.last : node.
|
40
|
+
node.str_type? ? node.children.last : node.source
|
44
41
|
end
|
45
42
|
end
|
46
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
|
@@ -6,7 +7,7 @@ module RuboCop
|
|
6
7
|
# This cop checks for uses of *begin...end while/until something*.
|
7
8
|
class Loop < Cop
|
8
9
|
MSG = 'Use `Kernel#loop` with `break` rather than ' \
|
9
|
-
'`begin/end/until`(or `while`).'
|
10
|
+
'`begin/end/until`(or `while`).'.freeze
|
10
11
|
|
11
12
|
def on_while_post(node)
|
12
13
|
register_offense(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,7 +9,7 @@ module RuboCop
|
|
8
9
|
# @example
|
9
10
|
# # `bar` definition actually produces methods in the same scope
|
10
11
|
# # as the outer `foo` method. Furthermore, the `bar` method
|
11
|
-
# # will be redefined every time
|
12
|
+
# # will be redefined every time `foo` is invoked.
|
12
13
|
# def foo
|
13
14
|
# def bar
|
14
15
|
# end
|
@@ -16,15 +17,30 @@ module RuboCop
|
|
16
17
|
#
|
17
18
|
class NestedMethodDefinition < Cop
|
18
19
|
include OnMethodDef
|
20
|
+
extend RuboCop::NodePattern::Macros
|
19
21
|
|
20
22
|
MSG = 'Method definitions must not be nested. ' \
|
21
|
-
'Use `lambda` instead.'
|
23
|
+
'Use `lambda` instead.'.freeze
|
24
|
+
|
25
|
+
def_node_matcher :eval_call?, <<-PATTERN
|
26
|
+
(block (send _ {:instance_eval :class_eval :module_eval} ...) ...)
|
27
|
+
PATTERN
|
22
28
|
|
23
29
|
def on_method_def(node, _method_name, _args, _body)
|
24
|
-
node
|
30
|
+
find_nested_defs(node) do |nested_def_node|
|
25
31
|
add_offense(nested_def_node, :expression)
|
26
32
|
end
|
27
33
|
end
|
34
|
+
|
35
|
+
def find_nested_defs(node, &block)
|
36
|
+
node.each_child_node do |child|
|
37
|
+
if child.def_type? || child.defs_type?
|
38
|
+
yield child
|
39
|
+
elsif !eval_call?(child)
|
40
|
+
find_nested_defs(child, &block)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
28
44
|
end
|
29
45
|
end
|
30
46
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module Lint
|
7
|
+
# Don't omit the accumulator when calling `next` in a `reduce` block.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# result = (1..4).reduce(0) do |acc, i|
|
12
|
+
# next if i.odd?
|
13
|
+
# acc + i
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# result = (1..4).reduce(0) do |acc, i|
|
18
|
+
# next acc if i.odd?
|
19
|
+
# acc + i
|
20
|
+
# end
|
21
|
+
class NextWithoutAccumulator < Cop
|
22
|
+
MSG = 'Use `next` with an accumulator argument in a `reduce`.'.freeze
|
23
|
+
|
24
|
+
def_node_matcher :on_body_of_reduce, <<-PATTERN
|
25
|
+
(block (send _recv {:reduce :inject} !sym) _blockargs $(begin ...))
|
26
|
+
PATTERN
|
27
|
+
|
28
|
+
def on_block(node)
|
29
|
+
on_body_of_reduce(node) do |body|
|
30
|
+
void_next = body.each_node(:next).find { |n| n.children.empty? }
|
31
|
+
|
32
|
+
add_offense(void_next, :expression) if void_next
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
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
|
@@ -12,7 +13,7 @@ module RuboCop
|
|
12
13
|
#
|
13
14
|
# class ItemApi
|
14
15
|
# rescue_from ValidationError do |e| # non-iteration block with arg
|
15
|
-
# return message: 'validation error' unless e.errors #
|
16
|
+
# return message: 'validation error' unless e.errors # allowed
|
16
17
|
# error_array = e.errors.map do |error| # block with method chain
|
17
18
|
# return if error.suppress? # warned
|
18
19
|
# return "#{error.param}: invalid" unless error.message # allowed
|
@@ -34,7 +35,8 @@ module RuboCop
|
|
34
35
|
#
|
35
36
|
class NonLocalExitFromIterator < Cop
|
36
37
|
MSG = 'Non-local exit from iterator, without return value. ' \
|
37
|
-
|
38
|
+
'`next`, `break`, `Array#find`, `Array#any?`, etc. ' \
|
39
|
+
'is preferred.'.freeze
|
38
40
|
|
39
41
|
def on_return(return_node)
|
40
42
|
return if return_value?(return_node)
|
@@ -42,7 +44,7 @@ module RuboCop
|
|
42
44
|
send_node, args_node, _body_node = *block_node
|
43
45
|
|
44
46
|
# `return` does not exit to outside of lambda block, this is safe.
|
45
|
-
break if lambda?
|
47
|
+
break if block_node.lambda?
|
46
48
|
# if a proc is passed to `Module#define_method`, `return` will not
|
47
49
|
# cause a non-local exit error
|
48
50
|
break if define_method?(send_node)
|
@@ -64,11 +66,6 @@ module RuboCop
|
|
64
66
|
!receiver_node.nil?
|
65
67
|
end
|
66
68
|
|
67
|
-
def lambda?(send_node)
|
68
|
-
receiver_node, selector_node = *send_node
|
69
|
-
receiver_node.nil? && selector_node == :lambda
|
70
|
-
end
|
71
|
-
|
72
69
|
def define_method?(send_node)
|
73
70
|
_receiver, selector = *send_node
|
74
71
|
selector == :define_method
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -10,16 +11,17 @@ module RuboCop
|
|
10
11
|
#
|
11
12
|
# puts (x + y)
|
12
13
|
class ParenthesesAsGroupedExpression < Cop
|
13
|
-
MSG = '`(...)` interpreted as grouped expression.'
|
14
|
+
MSG = '`(...)` interpreted as grouped expression.'.freeze
|
14
15
|
|
15
16
|
def on_send(node)
|
16
|
-
_receiver, method_name, args = *node
|
17
|
+
_receiver, method_name, *args = *node
|
17
18
|
return if operator?(method_name) || node.asgn_method_call?
|
18
|
-
return unless args && args.
|
19
|
+
return unless args.first && args.first.source.start_with?('(')
|
20
|
+
return if args.size > 1
|
19
21
|
|
20
22
|
space_length = spaces_before_left_parenthesis(node)
|
21
23
|
return unless space_length > 0
|
22
|
-
expr = args.
|
24
|
+
expr = args.first.source_range
|
23
25
|
space_range =
|
24
26
|
Parser::Source::Range.new(expr.source_buffer,
|
25
27
|
expr.begin_pos - space_length,
|
@@ -33,11 +35,11 @@ module RuboCop
|
|
33
35
|
def spaces_before_left_parenthesis(node)
|
34
36
|
receiver, method_name, _args = *node
|
35
37
|
receiver_length = if receiver
|
36
|
-
receiver.
|
38
|
+
receiver.source.length
|
37
39
|
else
|
38
40
|
0
|
39
41
|
end
|
40
|
-
without_receiver = node.
|
42
|
+
without_receiver = node.source[receiver_length..-1]
|
41
43
|
|
42
44
|
# Escape question mark if any.
|
43
45
|
method_regexp = Regexp.escape(method_name)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module Lint
|
7
|
+
# This cop checks for `rand(1)` calls.
|
8
|
+
# Such calls always return `0`.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
# @bad
|
13
|
+
# rand 1
|
14
|
+
# Kernel.rand(-1)
|
15
|
+
# rand 1.0
|
16
|
+
# rand(-1.0)
|
17
|
+
#
|
18
|
+
# @good
|
19
|
+
# 0
|
20
|
+
class RandOne < Cop
|
21
|
+
MSG = '`%s` always returns `0`. ' \
|
22
|
+
'Perhaps you meant `rand(2)` or `rand`?'.freeze
|
23
|
+
|
24
|
+
def_node_matcher :rand_one?, <<-PATTERN
|
25
|
+
(send {(const nil :Kernel) nil} :rand {(int {-1 1}) (float {-1.0 1.0})})
|
26
|
+
PATTERN
|
27
|
+
|
28
|
+
def on_send(node)
|
29
|
+
if rand_one?(node)
|
30
|
+
add_offense(node, :expression, format(MSG, node.source))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|