rubocop 1.27.0 → 1.51.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +8 -6
- data/config/default.yml +462 -69
- data/config/obsoletion.yml +35 -2
- data/exe/rubocop +15 -7
- data/lib/rubocop/arguments_env.rb +17 -0
- data/lib/rubocop/arguments_file.rb +17 -0
- data/lib/rubocop/cache_config.rb +29 -0
- data/lib/rubocop/cli/command/{auto_genenerate_config.rb → auto_generate_config.rb} +27 -5
- data/lib/rubocop/cli/command/execute_runner.rb +15 -10
- data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
- data/lib/rubocop/cli/command/show_cops.rb +1 -1
- data/lib/rubocop/cli/command/suggest_extensions.rb +62 -17
- data/lib/rubocop/cli.rb +57 -9
- data/lib/rubocop/comment_config.rb +60 -1
- data/lib/rubocop/config.rb +52 -20
- data/lib/rubocop/config_finder.rb +68 -0
- data/lib/rubocop/config_loader.rb +49 -69
- data/lib/rubocop/config_loader_resolver.rb +11 -12
- data/lib/rubocop/config_obsoletion/changed_parameter.rb +5 -0
- data/lib/rubocop/config_obsoletion/parameter_rule.rb +4 -0
- data/lib/rubocop/config_obsoletion.rb +9 -4
- data/lib/rubocop/config_validator.rb +22 -5
- data/lib/rubocop/cop/autocorrect_logic.rb +32 -14
- data/lib/rubocop/cop/badge.rb +10 -5
- data/lib/rubocop/cop/base.rb +119 -83
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
- data/lib/rubocop/cop/bundler/gem_comment.rb +2 -2
- data/lib/rubocop/cop/bundler/gem_filename.rb +5 -5
- data/lib/rubocop/cop/bundler/ordered_gems.rb +2 -2
- data/lib/rubocop/cop/commissioner.rb +19 -6
- data/lib/rubocop/cop/cop.rb +54 -34
- data/lib/rubocop/cop/corrector.rb +33 -13
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +4 -4
- data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +4 -4
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -5
- data/lib/rubocop/cop/correctors/if_then_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +8 -2
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +26 -10
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +3 -8
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +59 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/punctuation_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +2 -2
- data/lib/rubocop/cop/gemspec/dependency_version.rb +154 -0
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +92 -0
- data/lib/rubocop/cop/gemspec/development_dependencies.rb +107 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +4 -7
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/require_mfa.rb +21 -21
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/generator/require_file_injector.rb +2 -2
- data/lib/rubocop/cop/generator.rb +6 -3
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +98 -0
- data/lib/rubocop/cop/internal_affairs/create_empty_file.rb +37 -0
- data/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +111 -0
- data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/lambda_or_proc.rb +46 -0
- data/lib/rubocop/cop/internal_affairs/location_expression.rb +37 -0
- data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +80 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +3 -7
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/numblock_handler.rb +69 -0
- data/lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb +42 -0
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +12 -4
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +66 -0
- data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +62 -0
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +60 -0
- data/lib/rubocop/cop/internal_affairs.rb +11 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +22 -1
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/assignment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/begin_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/block_alignment.rb +17 -13
- data/lib/rubocop/cop/layout/block_end_newline.rb +32 -10
- data/lib/rubocop/cop/layout/case_indentation.rb +17 -1
- data/lib/rubocop/cop/layout/class_structure.rb +37 -27
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +3 -7
- data/lib/rubocop/cop/layout/comment_indentation.rb +5 -3
- data/lib/rubocop/cop/layout/condition_position.rb +1 -1
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_comment.rb +4 -4
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -2
- data/lib/rubocop/cop/layout/empty_lines.rb +4 -2
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +7 -2
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +25 -4
- data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +7 -5
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +10 -10
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +10 -10
- data/lib/rubocop/cop/layout/end_alignment.rb +10 -2
- data/lib/rubocop/cop/layout/end_of_line.rb +5 -5
- data/lib/rubocop/cop/layout/extra_spacing.rb +16 -7
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +43 -32
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +21 -14
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +36 -9
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +52 -13
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +37 -2
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +58 -9
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +53 -20
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +2 -0
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +11 -5
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +9 -12
- data/lib/rubocop/cop/layout/indentation_consistency.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_style.rb +8 -3
- data/lib/rubocop/cop/layout/indentation_width.rb +16 -9
- data/lib/rubocop/cop/layout/initial_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/leading_comment_space.rb +2 -2
- data/lib/rubocop/cop/layout/leading_empty_lines.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +136 -0
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +140 -0
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/line_length.rb +13 -6
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +32 -2
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +2 -2
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +5 -3
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +30 -2
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +40 -3
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +22 -5
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +77 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/redundant_line_break.rb +10 -11
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -3
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_not.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -3
- data/lib/rubocop/cop/layout/space_around_keyword.rb +3 -3
- data/lib/rubocop/cop/layout/space_around_operators.rb +2 -2
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +5 -3
- data/lib/rubocop/cop/layout/space_before_brackets.rb +7 -0
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +2 -2
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +3 -3
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +32 -30
- data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +3 -0
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +35 -15
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +30 -3
- data/lib/rubocop/cop/layout/space_inside_parens.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +34 -0
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +11 -7
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +6 -5
- data/lib/rubocop/cop/layout/trailing_empty_lines.rb +10 -10
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +15 -8
- data/lib/rubocop/cop/legacy/corrections_proxy.rb +1 -1
- data/lib/rubocop/cop/legacy/corrector.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_assignment.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +40 -8
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +5 -1
- data/lib/rubocop/cop/lint/ambiguous_operator_precedence.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_range.rb +5 -5
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +1 -1
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +12 -2
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +1 -1
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +1 -1
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +51 -0
- data/lib/rubocop/cop/lint/constant_resolution.rb +5 -1
- data/lib/rubocop/cop/lint/debugger.rb +28 -32
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +67 -111
- data/lib/rubocop/cop/lint/deprecated_constants.rb +9 -2
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
- data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_branch.rb +1 -3
- data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_elsif_condition.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_hash_key.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_magic_comment.rb +73 -0
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +122 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +49 -19
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +27 -10
- data/lib/rubocop/cop/lint/duplicate_require.rb +11 -2
- data/lib/rubocop/cop/lint/duplicate_rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/else_layout.rb +6 -10
- data/lib/rubocop/cop/lint/empty_block.rb +4 -8
- data/lib/rubocop/cop/lint/empty_class.rb +4 -2
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +111 -3
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/empty_expression.rb +1 -1
- data/lib/rubocop/cop/lint/empty_file.rb +1 -1
- data/lib/rubocop/cop/lint/empty_in_pattern.rb +1 -1
- data/lib/rubocop/cop/lint/empty_interpolation.rb +2 -2
- data/lib/rubocop/cop/lint/empty_when.rb +1 -1
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +12 -12
- data/lib/rubocop/cop/lint/flip_flop.rb +1 -1
- data/lib/rubocop/cop/lint/float_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +14 -7
- data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +16 -18
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +2 -2
- data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +6 -3
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +2 -2
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
- data/lib/rubocop/cop/lint/interpolation_check.rb +6 -5
- data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +3 -3
- data/lib/rubocop/cop/lint/literal_as_condition.rb +6 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +49 -3
- data/lib/rubocop/cop/lint/loop.rb +2 -2
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +19 -4
- data/lib/rubocop/cop/lint/missing_super.rb +32 -3
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +54 -10
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +25 -6
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +162 -0
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +17 -5
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +1 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +32 -10
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +3 -3
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +4 -3
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +4 -5
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +17 -2
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +7 -2
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -2
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +2 -2
- data/lib/rubocop/cop/lint/raise_exception.rb +2 -2
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +55 -15
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +8 -8
- data/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb +7 -0
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +48 -7
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +16 -3
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +35 -15
- data/lib/rubocop/cop/lint/redundant_with_index.rb +15 -12
- data/lib/rubocop/cop/lint/redundant_with_object.rb +14 -13
- data/lib/rubocop/cop/lint/refinement_import_methods.rb +3 -2
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +9 -3
- data/lib/rubocop/cop/lint/require_parentheses.rb +4 -2
- data/lib/rubocop/cop/lint/require_range_parentheses.rb +57 -0
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +3 -3
- data/lib/rubocop/cop/lint/return_in_void_context.rb +6 -18
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +44 -8
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
- data/lib/rubocop/cop/lint/script_permission.rb +2 -2
- data/lib/rubocop/cop/lint/self_assignment.rb +1 -1
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +5 -4
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -1
- data/lib/rubocop/cop/lint/shadowed_exception.rb +17 -12
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +29 -4
- data/lib/rubocop/cop/lint/struct_new_override.rb +3 -3
- data/lib/rubocop/cop/lint/suppressed_exception.rb +2 -2
- data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/syntax.rb +5 -1
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +14 -4
- data/lib/rubocop/cop/lint/to_json.rb +1 -1
- data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +24 -10
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +2 -2
- data/lib/rubocop/cop/lint/triple_quotes.rb +1 -1
- data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +1 -1
- data/lib/rubocop/cop/lint/unexpected_block_arity.rb +1 -1
- data/lib/rubocop/cop/lint/unified_integer.rb +3 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_loop.rb +15 -9
- data/lib/rubocop/cop/lint/unused_block_argument.rb +1 -1
- data/lib/rubocop/cop/lint/unused_method_argument.rb +7 -2
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -1
- data/lib/rubocop/cop/lint/uri_regexp.rb +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +18 -13
- data/lib/rubocop/cop/lint/useless_assignment.rb +57 -2
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +2 -3
- data/lib/rubocop/cop/lint/useless_method_definition.rb +13 -5
- data/lib/rubocop/cop/lint/useless_rescue.rb +89 -0
- data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +16 -6
- data/lib/rubocop/cop/lint/useless_setter_call.rb +2 -2
- data/lib/rubocop/cop/lint/useless_times.rb +3 -3
- data/lib/rubocop/cop/lint/void.rb +92 -21
- data/lib/rubocop/cop/metrics/abc_size.rb +5 -3
- data/lib/rubocop/cop/metrics/block_length.rb +17 -12
- data/lib/rubocop/cop/metrics/block_nesting.rb +3 -3
- data/lib/rubocop/cop/metrics/class_length.rb +11 -5
- data/lib/rubocop/cop/metrics/collection_literal_length.rb +76 -0
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +2 -2
- data/lib/rubocop/cop/metrics/method_length.rb +18 -12
- data/lib/rubocop/cop/metrics/module_length.rb +10 -5
- data/lib/rubocop/cop/metrics/parameter_lists.rb +28 -1
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +2 -2
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +4 -7
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +29 -7
- data/lib/rubocop/cop/migration/department_name.rb +1 -1
- data/lib/rubocop/cop/mixin/alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/allowed_identifiers.rb +2 -2
- data/lib/rubocop/cop/mixin/allowed_methods.rb +23 -2
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +56 -0
- data/lib/rubocop/cop/mixin/annotation_comment.rb +14 -7
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +5 -1
- data/lib/rubocop/cop/mixin/code_length.rb +1 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +29 -5
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +21 -9
- data/lib/rubocop/cop/mixin/def_node.rb +2 -7
- data/lib/rubocop/cop/mixin/documentation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/duplication.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -1
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +11 -7
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +4 -0
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +157 -12
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +13 -9
- data/lib/rubocop/cop/mixin/line_length_help.rb +11 -2
- data/lib/rubocop/cop/mixin/method_complexity.rb +13 -16
- data/lib/rubocop/cop/mixin/min_branches_count.rb +40 -0
- data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +34 -12
- data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +5 -6
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
- data/lib/rubocop/cop/mixin/percent_array.rb +58 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/preferred_delimiters.rb +2 -2
- data/lib/rubocop/cop/mixin/range_help.rb +28 -7
- data/lib/rubocop/cop/mixin/require_library.rb +2 -0
- data/lib/rubocop/cop/mixin/rescue_node.rb +5 -3
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +19 -4
- data/lib/rubocop/cop/mixin/string_help.rb +1 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +13 -11
- data/lib/rubocop/cop/mixin/trailing_comma.rb +3 -3
- data/lib/rubocop/cop/mixin/visibility_help.rb +40 -5
- data/lib/rubocop/cop/naming/accessor_method_name.rb +4 -2
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +2 -2
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +8 -4
- data/lib/rubocop/cop/naming/block_parameter_name.rb +2 -2
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +4 -2
- data/lib/rubocop/cop/naming/constant_name.rb +4 -4
- data/lib/rubocop/cop/naming/file_name.rb +2 -2
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +2 -2
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +31 -8
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +23 -8
- data/lib/rubocop/cop/naming/method_name.rb +9 -9
- data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +33 -4
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +13 -5
- data/lib/rubocop/cop/naming/variable_name.rb +10 -1
- data/lib/rubocop/cop/naming/variable_number.rb +28 -18
- data/lib/rubocop/cop/offense.rb +1 -1
- data/lib/rubocop/cop/registry.rb +73 -45
- data/lib/rubocop/cop/security/compound_hash.rb +106 -0
- data/lib/rubocop/cop/security/eval.rb +1 -1
- data/lib/rubocop/cop/security/json_load.rb +1 -1
- data/lib/rubocop/cop/security/marshal_load.rb +1 -1
- data/lib/rubocop/cop/security/open.rb +1 -1
- data/lib/rubocop/cop/security/yaml_load.rb +2 -2
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +92 -3
- data/lib/rubocop/cop/style/accessor_grouping.rb +49 -23
- data/lib/rubocop/cop/style/alias.rb +13 -5
- data/lib/rubocop/cop/style/and_or.rb +12 -12
- data/lib/rubocop/cop/style/arguments_forwarding.rb +7 -6
- data/lib/rubocop/cop/style/array_coercion.rb +1 -1
- data/lib/rubocop/cop/style/array_intersect.rb +111 -0
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/ascii_comments.rb +2 -2
- data/lib/rubocop/cop/style/attr.rb +12 -2
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +1 -1
- data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
- data/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb +1 -1
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +2 -2
- data/lib/rubocop/cop/style/block_comments.rb +3 -3
- data/lib/rubocop/cop/style/block_delimiters.rb +52 -11
- data/lib/rubocop/cop/style/case_equality.rb +41 -11
- data/lib/rubocop/cop/style/case_like_if.rb +22 -5
- data/lib/rubocop/cop/style/character_literal.rb +2 -2
- data/lib/rubocop/cop/style/class_and_module_children.rb +9 -16
- data/lib/rubocop/cop/style/class_check.rb +1 -1
- data/lib/rubocop/cop/style/class_equality_comparison.rb +95 -13
- data/lib/rubocop/cop/style/class_methods.rb +1 -1
- data/lib/rubocop/cop/style/class_methods_definitions.rb +3 -2
- data/lib/rubocop/cop/style/class_vars.rb +1 -1
- data/lib/rubocop/cop/style/collection_compact.rb +25 -9
- data/lib/rubocop/cop/style/collection_methods.rb +3 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
- data/lib/rubocop/cop/style/colon_method_definition.rb +1 -1
- data/lib/rubocop/cop/style/combinable_loops.rb +30 -8
- data/lib/rubocop/cop/style/command_literal.rb +2 -2
- data/lib/rubocop/cop/style/comment_annotation.rb +2 -2
- data/lib/rubocop/cop/style/commented_keyword.rb +5 -5
- data/lib/rubocop/cop/style/comparable_clamp.rb +125 -0
- data/lib/rubocop/cop/style/concat_array_literals.rb +94 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +10 -15
- data/lib/rubocop/cop/style/constant_visibility.rb +1 -1
- data/lib/rubocop/cop/style/copyright.rb +6 -3
- data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
- data/lib/rubocop/cop/style/date_time.rb +2 -2
- data/lib/rubocop/cop/style/def_with_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/dir.rb +4 -1
- data/lib/rubocop/cop/style/dir_empty.rb +60 -0
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +2 -2
- data/lib/rubocop/cop/style/documentation.rb +23 -11
- data/lib/rubocop/cop/style/documentation_method.rb +11 -5
- data/lib/rubocop/cop/style/double_negation.rb +31 -3
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +42 -7
- data/lib/rubocop/cop/style/each_with_object.rb +41 -10
- data/lib/rubocop/cop/style/empty_block_parameter.rb +3 -3
- data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
- data/lib/rubocop/cop/style/empty_else.rb +40 -3
- data/lib/rubocop/cop/style/empty_heredoc.rb +73 -0
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +3 -3
- data/lib/rubocop/cop/style/empty_literal.rb +2 -2
- data/lib/rubocop/cop/style/empty_method.rb +18 -3
- data/lib/rubocop/cop/style/encoding.rb +2 -2
- data/lib/rubocop/cop/style/end_block.rb +1 -1
- data/lib/rubocop/cop/style/endless_method.rb +2 -2
- data/lib/rubocop/cop/style/env_home.rb +56 -0
- data/lib/rubocop/cop/style/eval_with_location.rb +5 -5
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/exact_regexp_match.rb +62 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +1 -1
- data/lib/rubocop/cop/style/explicit_block_argument.rb +7 -3
- data/lib/rubocop/cop/style/exponential_notation.rb +1 -1
- data/lib/rubocop/cop/style/fetch_env_var.rb +132 -0
- data/lib/rubocop/cop/style/file_empty.rb +71 -0
- data/lib/rubocop/cop/style/file_read.rb +1 -1
- data/lib/rubocop/cop/style/file_write.rb +1 -1
- data/lib/rubocop/cop/style/float_division.rb +1 -1
- data/lib/rubocop/cop/style/for.rb +3 -1
- data/lib/rubocop/cop/style/format_string.rb +1 -1
- data/lib/rubocop/cop/style/format_string_token.rb +73 -23
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +7 -4
- data/lib/rubocop/cop/style/global_std_stream.rb +1 -1
- data/lib/rubocop/cop/style/global_vars.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +161 -25
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +2 -1
- data/lib/rubocop/cop/style/hash_conversion.rb +1 -1
- data/lib/rubocop/cop/style/hash_each_methods.rb +49 -13
- data/lib/rubocop/cop/style/hash_except.rb +101 -10
- data/lib/rubocop/cop/style/hash_like_case.rb +4 -10
- data/lib/rubocop/cop/style/hash_syntax.rb +29 -5
- data/lib/rubocop/cop/style/hash_transform_keys.rb +6 -1
- data/lib/rubocop/cop/style/hash_transform_values.rb +4 -1
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +19 -4
- data/lib/rubocop/cop/style/if_inside_else.rb +6 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +117 -20
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +31 -4
- data/lib/rubocop/cop/style/if_with_semicolon.rb +4 -4
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +3 -3
- data/lib/rubocop/cop/style/in_pattern_then.rb +1 -1
- data/lib/rubocop/cop/style/infinite_loop.rb +2 -5
- data/lib/rubocop/cop/style/inline_comment.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +17 -13
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +118 -0
- data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +2 -2
- data/lib/rubocop/cop/style/lambda.rb +1 -1
- data/lib/rubocop/cop/style/lambda_call.rb +1 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +6 -3
- data/lib/rubocop/cop/style/magic_comment_format.rb +307 -0
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +136 -0
- data/lib/rubocop/cop/style/map_to_hash.rb +7 -4
- data/lib/rubocop/cop/style/map_to_set.rb +64 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +42 -26
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +6 -2
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +52 -45
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +22 -3
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +5 -2
- data/lib/rubocop/cop/style/method_def_parentheses.rb +12 -5
- data/lib/rubocop/cop/style/min_max.rb +4 -4
- data/lib/rubocop/cop/style/min_max_comparison.rb +83 -0
- data/lib/rubocop/cop/style/missing_else.rb +37 -25
- data/lib/rubocop/cop/style/missing_respond_to_missing.rb +1 -1
- data/lib/rubocop/cop/style/mixin_grouping.rb +6 -6
- data/lib/rubocop/cop/style/mixin_usage.rb +1 -1
- data/lib/rubocop/cop/style/module_function.rb +30 -8
- data/lib/rubocop/cop/style/multiline_block_chain.rb +4 -2
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -6
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +3 -5
- data/lib/rubocop/cop/style/multiline_memoization.rb +3 -3
- data/lib/rubocop/cop/style/multiline_method_signature.rb +9 -6
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +52 -11
- data/lib/rubocop/cop/style/multiline_when_then.rb +2 -4
- data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +1 -1
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +18 -11
- data/lib/rubocop/cop/style/nested_file_dirname.rb +1 -1
- data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +11 -2
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +20 -8
- data/lib/rubocop/cop/style/next.rb +4 -6
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
- data/lib/rubocop/cop/style/nil_lambda.rb +5 -5
- data/lib/rubocop/cop/style/non_nil_check.rb +1 -1
- data/lib/rubocop/cop/style/not.rb +2 -2
- data/lib/rubocop/cop/style/numbered_parameters.rb +1 -1
- data/lib/rubocop/cop/style/numbered_parameters_limit.rb +12 -4
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +16 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +53 -11
- data/lib/rubocop/cop/style/object_then.rb +74 -0
- data/lib/rubocop/cop/style/one_line_conditional.rb +4 -7
- data/lib/rubocop/cop/style/open_struct_use.rb +1 -1
- data/lib/rubocop/cop/style/operator_method_call.rb +67 -0
- data/lib/rubocop/cop/style/option_hash.rb +1 -1
- data/lib/rubocop/cop/style/optional_arguments.rb +2 -2
- data/lib/rubocop/cop/style/optional_boolean_parameter.rb +2 -2
- data/lib/rubocop/cop/style/or_assignment.rb +1 -1
- data/lib/rubocop/cop/style/parallel_assignment.rb +29 -19
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -4
- data/lib/rubocop/cop/style/percent_q_literals.rb +2 -2
- data/lib/rubocop/cop/style/perl_backrefs.rb +23 -2
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +5 -2
- data/lib/rubocop/cop/style/quoted_symbols.rb +2 -2
- data/lib/rubocop/cop/style/raise_args.rb +5 -2
- data/lib/rubocop/cop/style/random_with_offset.rb +1 -1
- data/lib/rubocop/cop/style/redundant_argument.rb +5 -2
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +20 -6
- data/lib/rubocop/cop/style/redundant_capital_w.rb +1 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +148 -14
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -5
- data/lib/rubocop/cop/style/redundant_constant_base.rb +85 -0
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +45 -0
- data/lib/rubocop/cop/style/redundant_each.rb +116 -0
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +7 -5
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -1
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_heredoc_delimiter_quotes.rb +58 -0
- data/lib/rubocop/cop/style/redundant_initialize.rb +41 -4
- data/lib/rubocop/cop/style/redundant_interpolation.rb +24 -3
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +183 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +23 -25
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +15 -4
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +23 -6
- data/lib/rubocop/cop/style/redundant_return.rb +9 -2
- data/lib/rubocop/cop/style/redundant_self.rb +3 -1
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +3 -4
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +1 -1
- data/lib/rubocop/cop/style/redundant_sort.rb +25 -10
- data/lib/rubocop/cop/style/redundant_sort_by.rb +25 -9
- data/lib/rubocop/cop/style/redundant_string_escape.rb +183 -0
- data/lib/rubocop/cop/style/regexp_literal.rb +11 -2
- data/lib/rubocop/cop/style/require_order.rb +138 -0
- data/lib/rubocop/cop/style/rescue_modifier.rb +2 -2
- data/lib/rubocop/cop/style/rescue_standard_error.rb +15 -15
- data/lib/rubocop/cop/style/return_nil.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +46 -12
- data/lib/rubocop/cop/style/sample.rb +1 -1
- data/lib/rubocop/cop/style/select_by_regexp.rb +14 -6
- data/lib/rubocop/cop/style/self_assignment.rb +3 -3
- data/lib/rubocop/cop/style/semicolon.rb +64 -6
- data/lib/rubocop/cop/style/send.rb +1 -1
- data/lib/rubocop/cop/style/signal_exception.rb +9 -7
- data/lib/rubocop/cop/style/single_argument_dig.rb +5 -0
- data/lib/rubocop/cop/style/single_line_block_params.rb +2 -2
- data/lib/rubocop/cop/style/single_line_methods.rb +2 -2
- data/lib/rubocop/cop/style/slicing_with_range.rb +2 -2
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +52 -24
- data/lib/rubocop/cop/style/special_global_vars.rb +66 -8
- data/lib/rubocop/cop/style/static_class.rb +33 -2
- data/lib/rubocop/cop/style/stderr_puts.rb +2 -2
- data/lib/rubocop/cop/style/string_chars.rb +1 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +6 -7
- data/lib/rubocop/cop/style/string_hash_keys.rb +5 -2
- data/lib/rubocop/cop/style/string_literals.rb +1 -5
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/string_methods.rb +1 -1
- data/lib/rubocop/cop/style/strip.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +5 -5
- data/lib/rubocop/cop/style/swap_values.rb +2 -2
- data/lib/rubocop/cop/style/symbol_array.rb +12 -7
- data/lib/rubocop/cop/style/symbol_literal.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +68 -12
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -14
- data/lib/rubocop/cop/style/top_level_method_definition.rb +3 -1
- data/lib/rubocop/cop/style/trailing_body_on_class.rb +2 -1
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -1
- data/lib/rubocop/cop/style/trailing_body_on_module.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +5 -5
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +2 -2
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +1 -1
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +2 -2
- data/lib/rubocop/cop/style/trivial_accessors.rb +12 -10
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/unless_logical_operators.rb +2 -1
- data/lib/rubocop/cop/style/unpack_first.rb +8 -5
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +60 -6
- data/lib/rubocop/cop/style/yoda_condition.rb +14 -7
- data/lib/rubocop/cop/style/yoda_expression.rb +90 -0
- data/lib/rubocop/cop/style/zero_length_predicate.rb +41 -20
- data/lib/rubocop/cop/team.rb +65 -58
- data/lib/rubocop/cop/util.rb +44 -8
- data/lib/rubocop/cop/variable_force/assignment.rb +5 -1
- data/lib/rubocop/cop/variable_force/branch.rb +1 -1
- data/lib/rubocop/cop/variable_force/scope.rb +3 -3
- data/lib/rubocop/cop/variable_force/variable.rb +5 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +6 -4
- data/lib/rubocop/cop/variable_force.rb +18 -30
- data/lib/rubocop/cops_documentation_generator.rb +64 -17
- data/lib/rubocop/directive_comment.rb +4 -4
- data/lib/rubocop/ext/comment.rb +18 -0
- data/lib/rubocop/ext/processed_source.rb +2 -0
- data/lib/rubocop/ext/range.rb +15 -0
- data/lib/rubocop/ext/regexp_node.rb +1 -1
- data/lib/rubocop/ext/regexp_parser.rb +1 -1
- data/lib/rubocop/feature_loader.rb +94 -0
- data/lib/rubocop/file_patterns.rb +43 -0
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +36 -16
- data/lib/rubocop/formatter/formatter_set.rb +20 -18
- data/lib/rubocop/formatter/git_hub_actions_formatter.rb +15 -2
- data/lib/rubocop/formatter/html_formatter.rb +6 -14
- data/lib/rubocop/formatter/junit_formatter.rb +4 -1
- data/lib/rubocop/formatter/markdown_formatter.rb +78 -0
- data/lib/rubocop/formatter/offense_count_formatter.rb +10 -5
- data/lib/rubocop/formatter/simple_text_formatter.rb +9 -8
- data/lib/rubocop/formatter/tap_formatter.rb +1 -1
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +6 -3
- data/lib/rubocop/formatter.rb +34 -0
- data/lib/rubocop/magic_comment.rb +31 -5
- data/lib/rubocop/options.rb +154 -49
- data/lib/rubocop/path_util.rb +50 -22
- data/lib/rubocop/rake_task.rb +34 -9
- data/lib/rubocop/result_cache.rb +28 -25
- data/lib/rubocop/rspec/cop_helper.rb +27 -4
- data/lib/rubocop/rspec/expect_offense.rb +9 -7
- data/lib/rubocop/rspec/parallel_formatter.rb +1 -1
- data/lib/rubocop/rspec/shared_contexts.rb +48 -11
- data/lib/rubocop/rspec/support.rb +17 -2
- data/lib/rubocop/runner.rb +106 -25
- data/lib/rubocop/server/cache.rb +155 -0
- data/lib/rubocop/server/cli.rb +147 -0
- data/lib/rubocop/server/client_command/base.rb +44 -0
- data/lib/rubocop/server/client_command/exec.rb +64 -0
- data/lib/rubocop/server/client_command/restart.rb +25 -0
- data/lib/rubocop/server/client_command/start.rb +48 -0
- data/lib/rubocop/server/client_command/status.rb +28 -0
- data/lib/rubocop/server/client_command/stop.rb +31 -0
- data/lib/rubocop/server/client_command.rb +26 -0
- data/lib/rubocop/server/core.rb +111 -0
- data/lib/rubocop/server/errors.rb +23 -0
- data/lib/rubocop/server/helper.rb +34 -0
- data/lib/rubocop/server/server_command/base.rb +50 -0
- data/lib/rubocop/server/server_command/exec.rb +34 -0
- data/lib/rubocop/server/server_command/stop.rb +24 -0
- data/lib/rubocop/server/server_command.rb +21 -0
- data/lib/rubocop/server/socket_reader.rb +69 -0
- data/lib/rubocop/server.rb +53 -0
- data/lib/rubocop/string_interpreter.rb +4 -4
- data/lib/rubocop/target_finder.rb +1 -1
- data/lib/rubocop/target_ruby.rb +16 -8
- data/lib/rubocop/version.rb +24 -11
- data/lib/rubocop.rb +59 -35
- metadata +114 -37
- data/lib/rubocop/cop/gemspec/date_assignment.rb +0 -49
- data/lib/rubocop/cop/mixin/ignored_methods.rb +0 -52
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +0 -29
@@ -11,6 +11,32 @@ module RuboCop
|
|
11
11
|
# cop. The tab size is configured in the `IndentationWidth` of the
|
12
12
|
# `Layout/IndentationStyle` cop.
|
13
13
|
#
|
14
|
+
# One-line pattern matching is always allowed. To ensure that there are few cases
|
15
|
+
# where the match variable is not used, and to prevent oversights. The variable `x`
|
16
|
+
# becomes undefined and raises `NameError` when the following example is changed to
|
17
|
+
# the modifier form:
|
18
|
+
#
|
19
|
+
# [source,ruby]
|
20
|
+
# ----
|
21
|
+
# if [42] in [x]
|
22
|
+
# x # `x` is undefined when using modifier form.
|
23
|
+
# end
|
24
|
+
# ----
|
25
|
+
#
|
26
|
+
# NOTE: It is allowed when `defined?` argument has an undefined value,
|
27
|
+
# because using the modifier form causes the following incompatibility:
|
28
|
+
#
|
29
|
+
# [source,ruby]
|
30
|
+
# ----
|
31
|
+
# unless defined?(undefined_foo)
|
32
|
+
# undefined_foo = 'default_value'
|
33
|
+
# end
|
34
|
+
# undefined_foo # => 'default_value'
|
35
|
+
#
|
36
|
+
# undefined_bar = 'default_value' unless defined?(undefined_bar)
|
37
|
+
# undefined_bar # => nil
|
38
|
+
# ----
|
39
|
+
#
|
14
40
|
# @example
|
15
41
|
# # bad
|
16
42
|
# if condition
|
@@ -37,8 +63,9 @@ module RuboCop
|
|
37
63
|
class IfUnlessModifier < Base
|
38
64
|
include StatementModifier
|
39
65
|
include LineLengthHelp
|
40
|
-
include
|
66
|
+
include AllowedPattern
|
41
67
|
include RangeHelp
|
68
|
+
include CommentsHelp
|
42
69
|
extend AutoCorrector
|
43
70
|
|
44
71
|
MSG_USE_MODIFIER = 'Favor modifier `%<keyword>s` usage when having a ' \
|
@@ -51,51 +78,106 @@ module RuboCop
|
|
51
78
|
end
|
52
79
|
|
53
80
|
def on_if(node)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
return unless msg
|
81
|
+
condition = node.condition
|
82
|
+
return if defined_nodes(condition).any? { |n| defined_argument_is_undefined?(node, n) } ||
|
83
|
+
pattern_matching_nodes(condition).any?
|
84
|
+
return unless (msg = message(node))
|
60
85
|
|
61
86
|
add_offense(node.loc.keyword, message: format(msg, keyword: node.keyword)) do |corrector|
|
87
|
+
next if part_of_ignored_node?(node)
|
88
|
+
|
62
89
|
autocorrect(corrector, node)
|
90
|
+
ignore_node(node)
|
63
91
|
end
|
64
92
|
end
|
65
93
|
|
66
94
|
private
|
67
95
|
|
96
|
+
def defined_nodes(condition)
|
97
|
+
if condition.defined_type?
|
98
|
+
[condition]
|
99
|
+
else
|
100
|
+
condition.each_descendant.select(&:defined_type?)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def defined_argument_is_undefined?(if_node, defined_node)
|
105
|
+
defined_argument = defined_node.first_argument
|
106
|
+
return false unless defined_argument.lvar_type? || defined_argument.send_type?
|
107
|
+
|
108
|
+
if_node.left_siblings.none? do |sibling|
|
109
|
+
sibling.respond_to?(:lvasgn_type?) && sibling.lvasgn_type? &&
|
110
|
+
sibling.name == defined_argument.node_parts[0]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def pattern_matching_nodes(condition)
|
115
|
+
if condition.match_pattern_type? || condition.match_pattern_p_type?
|
116
|
+
[condition]
|
117
|
+
else
|
118
|
+
condition.each_descendant.select do |node|
|
119
|
+
node.match_pattern_type? || node.match_pattern_p_type?
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def message(node)
|
125
|
+
if single_line_as_modifier?(node) && !named_capture_in_condition?(node)
|
126
|
+
MSG_USE_MODIFIER
|
127
|
+
elsif too_long_due_to_modifier?(node)
|
128
|
+
MSG_USE_NORMAL
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
68
132
|
def autocorrect(corrector, node)
|
69
133
|
replacement = if node.modifier_form?
|
70
|
-
|
71
|
-
|
72
|
-
if last_argument.respond_to?(:heredoc?) && last_argument.heredoc?
|
73
|
-
heredoc = extract_heredoc_from(last_argument)
|
74
|
-
remove_heredoc(corrector, heredoc)
|
75
|
-
to_normal_form_with_heredoc(node, indent(node), heredoc)
|
76
|
-
else
|
77
|
-
to_normal_form(node, indent(node))
|
78
|
-
end
|
134
|
+
replacement_for_modifier_form(corrector, node)
|
79
135
|
else
|
80
136
|
to_modifier_form(node)
|
81
137
|
end
|
82
138
|
corrector.replace(node, replacement)
|
83
139
|
end
|
84
140
|
|
141
|
+
def replacement_for_modifier_form(corrector, node) # rubocop:disable Metrics/AbcSize
|
142
|
+
comment = comment_on_node_line(node)
|
143
|
+
if comment && too_long_due_to_comment_after_modifier?(node, comment)
|
144
|
+
remove_comment(corrector, node, comment)
|
145
|
+
|
146
|
+
return to_modifier_form_with_move_comment(node, indent(node), comment)
|
147
|
+
end
|
148
|
+
|
149
|
+
last_argument = node.if_branch.last_argument if node.if_branch.send_type?
|
150
|
+
if last_argument.respond_to?(:heredoc?) && last_argument.heredoc?
|
151
|
+
heredoc = extract_heredoc_from(last_argument)
|
152
|
+
remove_heredoc(corrector, heredoc)
|
153
|
+
|
154
|
+
return to_normal_form_with_heredoc(node, indent(node), heredoc)
|
155
|
+
end
|
156
|
+
|
157
|
+
to_normal_form(node, indent(node))
|
158
|
+
end
|
159
|
+
|
85
160
|
def too_long_due_to_modifier?(node)
|
86
161
|
node.modifier_form? && too_long_single_line?(node) &&
|
87
162
|
!another_statement_on_same_line?(node)
|
88
163
|
end
|
89
164
|
|
90
|
-
def
|
91
|
-
|
165
|
+
def too_long_due_to_comment_after_modifier?(node, comment)
|
166
|
+
source_length = processed_source.lines[node.first_line - 1].length
|
167
|
+
source_length >= max_line_length &&
|
168
|
+
source_length - comment.source_range.length <= max_line_length
|
169
|
+
end
|
170
|
+
|
171
|
+
def allowed_patterns
|
172
|
+
line_length_config = config.for_cop('Layout/LineLength')
|
173
|
+
line_length_config['AllowedPatterns'] || line_length_config['IgnoredPatterns'] || []
|
92
174
|
end
|
93
175
|
|
94
176
|
def too_long_single_line?(node)
|
95
177
|
return false unless max_line_length
|
96
178
|
|
97
179
|
range = node.source_range
|
98
|
-
return false unless range.
|
180
|
+
return false unless range.single_line?
|
99
181
|
return false unless line_length_enabled_at_line?(range.first_line)
|
100
182
|
|
101
183
|
line = range.source_line
|
@@ -105,7 +187,7 @@ module RuboCop
|
|
105
187
|
end
|
106
188
|
|
107
189
|
def too_long_line_based_on_config?(range, line)
|
108
|
-
return false if
|
190
|
+
return false if matches_allowed_pattern?(line)
|
109
191
|
|
110
192
|
too_long = too_long_line_based_on_ignore_cop_directives?(range, line)
|
111
193
|
return too_long unless too_long == :undetermined
|
@@ -180,6 +262,13 @@ module RuboCop
|
|
180
262
|
RUBY
|
181
263
|
end
|
182
264
|
|
265
|
+
def to_modifier_form_with_move_comment(node, indentation, comment)
|
266
|
+
<<~RUBY.chomp
|
267
|
+
#{comment.source}
|
268
|
+
#{indentation}#{node.body.source} #{node.keyword} #{node.condition.source}
|
269
|
+
RUBY
|
270
|
+
end
|
271
|
+
|
183
272
|
def extract_heredoc_from(last_argument)
|
184
273
|
heredoc_body = last_argument.loc.heredoc_body
|
185
274
|
heredoc_end = last_argument.loc.heredoc_end
|
@@ -192,6 +281,14 @@ module RuboCop
|
|
192
281
|
corrector.remove(range_by_whole_lines(range, include_final_newline: true))
|
193
282
|
end
|
194
283
|
end
|
284
|
+
|
285
|
+
def comment_on_node_line(node)
|
286
|
+
processed_source.comments.find { |c| same_line?(c, node) }
|
287
|
+
end
|
288
|
+
|
289
|
+
def remove_comment(corrector, _node, comment)
|
290
|
+
corrector.remove(range_with_surrounding_space(range: comment.source_range, side: :left))
|
291
|
+
end
|
195
292
|
end
|
196
293
|
end
|
197
294
|
end
|
@@ -3,12 +3,31 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
#
|
6
|
+
# Checks for redundant `if` with boolean literal branches.
|
7
7
|
# It checks only conditions to return boolean value (`true` or `false`) for safe detection.
|
8
|
-
# The conditions to be checked are comparison methods, predicate methods, and
|
8
|
+
# The conditions to be checked are comparison methods, predicate methods, and
|
9
|
+
# double negation (!!).
|
10
|
+
# `nonzero?` method is allowed by default.
|
11
|
+
# These are customizable with `AllowedMethods` option.
|
12
|
+
#
|
13
|
+
# This cop targets only `if`s with a single `elsif` or `else` branch. The following
|
14
|
+
# code will be allowed, because it has two `elsif` branches:
|
15
|
+
#
|
16
|
+
# [source,ruby]
|
17
|
+
# ----
|
18
|
+
# if foo
|
19
|
+
# true
|
20
|
+
# elsif bar > baz
|
21
|
+
# true
|
22
|
+
# elsif qux > quux # Single `elsif` is warned, but two or more `elsif`s are not.
|
23
|
+
# true
|
24
|
+
# else
|
25
|
+
# false
|
26
|
+
# end
|
27
|
+
# ----
|
9
28
|
#
|
10
29
|
# @safety
|
11
|
-
#
|
30
|
+
# Autocorrection is unsafe because there is no guarantee that all predicate methods
|
12
31
|
# will return a boolean value. Those methods can be allowed with `AllowedMethods` config.
|
13
32
|
#
|
14
33
|
# @example
|
@@ -55,7 +74,7 @@ module RuboCop
|
|
55
74
|
def_node_matcher :double_negative?, '(send (send _ :!) :!)'
|
56
75
|
|
57
76
|
def on_if(node)
|
58
|
-
return
|
77
|
+
return if !if_with_boolean_literal_branches?(node) || multiple_elsif?(node)
|
59
78
|
|
60
79
|
condition = node.condition
|
61
80
|
range, keyword = offense_range_with_keyword(node, condition)
|
@@ -74,6 +93,12 @@ module RuboCop
|
|
74
93
|
|
75
94
|
private
|
76
95
|
|
96
|
+
def multiple_elsif?(node)
|
97
|
+
return false unless (parent = node.parent)
|
98
|
+
|
99
|
+
parent.if_type? && parent.elsif?
|
100
|
+
end
|
101
|
+
|
77
102
|
def offense_range_with_keyword(node, condition)
|
78
103
|
if node.ternary?
|
79
104
|
range = condition.source_range.end.join(node.source_range.end)
|
@@ -93,6 +118,8 @@ module RuboCop
|
|
93
118
|
end
|
94
119
|
|
95
120
|
def return_boolean_value?(condition)
|
121
|
+
return false unless condition
|
122
|
+
|
96
123
|
if condition.begin_type?
|
97
124
|
return_boolean_value?(condition.children.first)
|
98
125
|
elsif condition.or_type?
|
@@ -21,13 +21,12 @@ module RuboCop
|
|
21
21
|
MSG_TERNARY = 'Do not use `if %<expr>s;` - use a ternary operator instead.'
|
22
22
|
|
23
23
|
def on_normal_if_unless(node)
|
24
|
-
return unless node.else_branch
|
25
24
|
return if node.parent&.if_type?
|
26
25
|
|
27
26
|
beginning = node.loc.begin
|
28
27
|
return unless beginning&.is?(';')
|
29
28
|
|
30
|
-
message = node.else_branch
|
29
|
+
message = node.else_branch&.if_type? ? MSG_IF_ELSE : MSG_TERNARY
|
31
30
|
|
32
31
|
add_offense(node, message: format(message, expr: node.condition.source)) do |corrector|
|
33
32
|
corrector.replace(node, autocorrect(node))
|
@@ -37,11 +36,12 @@ module RuboCop
|
|
37
36
|
private
|
38
37
|
|
39
38
|
def autocorrect(node)
|
40
|
-
return correct_elsif(node) if node.else_branch
|
39
|
+
return correct_elsif(node) if node.else_branch&.if_type?
|
41
40
|
|
41
|
+
then_code = node.if_branch ? node.if_branch.source : 'nil'
|
42
42
|
else_code = node.else_branch ? node.else_branch.source : 'nil'
|
43
43
|
|
44
|
-
"#{node.condition.source} ? #{
|
44
|
+
"#{node.condition.source} ? #{then_code} : #{else_code}"
|
45
45
|
end
|
46
46
|
|
47
47
|
def correct_elsif(node)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
#
|
6
|
+
# Checks for `raise` or `fail` statements which do not specify an
|
7
7
|
# explicit exception class. (This raises a `RuntimeError`. Some projects
|
8
8
|
# might prefer to use exception classes which more precisely identify the
|
9
9
|
# nature of the error.)
|
@@ -15,8 +15,8 @@ module RuboCop
|
|
15
15
|
# # good
|
16
16
|
# raise ArgumentError, 'Error message here'
|
17
17
|
class ImplicitRuntimeError < Base
|
18
|
-
MSG = 'Use `%<method>s` with an explicit exception class and message,' \
|
19
|
-
'
|
18
|
+
MSG = 'Use `%<method>s` with an explicit exception class and message, ' \
|
19
|
+
'rather than just a message.'
|
20
20
|
RESTRICT_ON_SEND = %i[raise fail].freeze
|
21
21
|
|
22
22
|
# @!method implicit_runtime_error_raise_or_fail(node)
|
@@ -21,6 +21,7 @@ module RuboCop
|
|
21
21
|
# work
|
22
22
|
# end
|
23
23
|
class InfiniteLoop < Base
|
24
|
+
include Alignment
|
24
25
|
extend AutoCorrector
|
25
26
|
|
26
27
|
LEADING_SPACE = /\A(\s*)/.freeze
|
@@ -106,7 +107,7 @@ module RuboCop
|
|
106
107
|
else
|
107
108
|
indentation = body.source_range.source_line[LEADING_SPACE]
|
108
109
|
|
109
|
-
['loop do', body.source.gsub(/^/,
|
110
|
+
['loop do', body.source.gsub(/^/, indentation(node)), 'end'].join("\n#{indentation}")
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
@@ -120,10 +121,6 @@ module RuboCop
|
|
120
121
|
|
121
122
|
start_range.join(end_range)
|
122
123
|
end
|
123
|
-
|
124
|
-
def configured_indent
|
125
|
-
' ' * config.for_cop('Layout/IndentationWidth')['Width']
|
126
|
-
end
|
127
124
|
end
|
128
125
|
end
|
129
126
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
#
|
6
|
+
# Check for usages of not (`not` or `!`) called on a method
|
7
7
|
# when an inverse of that method can be used instead.
|
8
8
|
#
|
9
9
|
# Methods that can be inverted by a not (`not` or `!`) should be defined
|
@@ -51,6 +51,8 @@ module RuboCop
|
|
51
51
|
NEGATED_EQUALITY_METHODS = %i[!= !~].freeze
|
52
52
|
CAMEL_CASE = /[A-Z]+[a-z]+/.freeze
|
53
53
|
|
54
|
+
RESTRICT_ON_SEND = [:!].freeze
|
55
|
+
|
54
56
|
def self.autocorrect_incompatible_with
|
55
57
|
[Style::Not, Style::SymbolProc]
|
56
58
|
end
|
@@ -59,18 +61,18 @@ module RuboCop
|
|
59
61
|
def_node_matcher :inverse_candidate?, <<~PATTERN
|
60
62
|
{
|
61
63
|
(send $(send $(...) $_ $...) :!)
|
62
|
-
(send (block $(send $(...) $_) $...) :!)
|
64
|
+
(send ({block numblock} $(send $(...) $_) $...) :!)
|
63
65
|
(send (begin $(send $(...) $_ $...)) :!)
|
64
66
|
}
|
65
67
|
PATTERN
|
66
68
|
|
67
69
|
# @!method inverse_block?(node)
|
68
70
|
def_node_matcher :inverse_block?, <<~PATTERN
|
69
|
-
(block $(send (...) $_) ... { $(send ... :!)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
({block numblock} $(send (...) $_) ... { $(send ... :!)
|
72
|
+
$(send (...) {:!= :!~} ...)
|
73
|
+
(begin ... $(send ... :!))
|
74
|
+
(begin ... $(send (...) {:!= :!~} ...))
|
75
|
+
})
|
74
76
|
PATTERN
|
75
77
|
|
76
78
|
def on_send(node)
|
@@ -94,7 +96,7 @@ module RuboCop
|
|
94
96
|
|
95
97
|
# Inverse method offenses inside of the block of an inverse method
|
96
98
|
# offense, such as `y.reject { |key, _value| !(key =~ /c\d/) }`,
|
97
|
-
# can cause
|
99
|
+
# can cause autocorrection to apply improper corrections.
|
98
100
|
ignore_node(block)
|
99
101
|
add_offense(node, message: message(method, inverse_blocks[method])) do |corrector|
|
100
102
|
correct_inverse_block(corrector, node)
|
@@ -102,6 +104,8 @@ module RuboCop
|
|
102
104
|
end
|
103
105
|
end
|
104
106
|
|
107
|
+
alias on_numblock on_block
|
108
|
+
|
105
109
|
private
|
106
110
|
|
107
111
|
def correct_inverse_method(corrector, node)
|
@@ -151,15 +155,15 @@ module RuboCop
|
|
151
155
|
end
|
152
156
|
|
153
157
|
def not_to_receiver(node, method_call)
|
154
|
-
Parser::Source::Range.new(node.
|
158
|
+
Parser::Source::Range.new(node.source_range.source_buffer,
|
155
159
|
node.loc.selector.begin_pos,
|
156
|
-
method_call.
|
160
|
+
method_call.source_range.begin_pos)
|
157
161
|
end
|
158
162
|
|
159
163
|
def end_parentheses(node, method_call)
|
160
|
-
Parser::Source::Range.new(node.
|
161
|
-
method_call.
|
162
|
-
node.
|
164
|
+
Parser::Source::Range.new(node.source_range.source_buffer,
|
165
|
+
method_call.source_range.end_pos,
|
166
|
+
node.source_range.end_pos)
|
163
167
|
end
|
164
168
|
|
165
169
|
# When comparing classes, `!(Integer < Numeric)` is not the same as
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# Checks for usages of `unless` which can be replaced by `if` with inverted condition.
|
7
|
+
# Code without `unless` is easier to read, but that is subjective, so this cop
|
8
|
+
# is disabled by default.
|
9
|
+
#
|
10
|
+
# Methods that can be inverted should be defined in `InverseMethods`. Note that
|
11
|
+
# the relationship of inverse methods needs to be defined in both directions.
|
12
|
+
# For example,
|
13
|
+
#
|
14
|
+
# [source,yaml]
|
15
|
+
# ----
|
16
|
+
# InverseMethods:
|
17
|
+
# :!=: :==
|
18
|
+
# :even?: :odd?
|
19
|
+
# :odd?: :even?
|
20
|
+
# ----
|
21
|
+
#
|
22
|
+
# will suggest both `even?` and `odd?` to be inverted, but only `!=` (and not `==`).
|
23
|
+
#
|
24
|
+
# @safety
|
25
|
+
# This cop is unsafe because it cannot be guaranteed that the method
|
26
|
+
# and its inverse method are both defined on receiver, and also are
|
27
|
+
# actually inverse of each other.
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# # bad (simple condition)
|
31
|
+
# foo unless !bar
|
32
|
+
# foo unless x != y
|
33
|
+
# foo unless x >= 10
|
34
|
+
# foo unless x.even?
|
35
|
+
#
|
36
|
+
# # good
|
37
|
+
# foo if bar
|
38
|
+
# foo if x == y
|
39
|
+
# foo if x < 10
|
40
|
+
# foo if x.odd?
|
41
|
+
#
|
42
|
+
# # bad (complex condition)
|
43
|
+
# foo unless x != y || x.even?
|
44
|
+
#
|
45
|
+
# # good
|
46
|
+
# foo if x == y && x.odd?
|
47
|
+
#
|
48
|
+
# # good (if)
|
49
|
+
# foo if !condition
|
50
|
+
#
|
51
|
+
class InvertibleUnlessCondition < Base
|
52
|
+
extend AutoCorrector
|
53
|
+
|
54
|
+
MSG = 'Favor `if` with inverted condition over `unless`.'
|
55
|
+
|
56
|
+
def on_if(node)
|
57
|
+
return unless node.unless?
|
58
|
+
|
59
|
+
condition = node.condition
|
60
|
+
return unless invertible?(condition)
|
61
|
+
|
62
|
+
add_offense(node) do |corrector|
|
63
|
+
corrector.replace(node.loc.keyword, node.inverse_keyword)
|
64
|
+
autocorrect(corrector, condition)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def invertible?(node)
|
71
|
+
case node.type
|
72
|
+
when :begin
|
73
|
+
invertible?(node.children.first)
|
74
|
+
when :send
|
75
|
+
return if inheritance_check?(node)
|
76
|
+
|
77
|
+
node.method?(:!) || inverse_methods.key?(node.method_name)
|
78
|
+
when :or, :and
|
79
|
+
invertible?(node.lhs) && invertible?(node.rhs)
|
80
|
+
else
|
81
|
+
false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def inheritance_check?(node)
|
86
|
+
argument = node.first_argument
|
87
|
+
node.method?(:<) &&
|
88
|
+
(argument.const_type? && argument.short_name.to_s.upcase != argument.short_name.to_s)
|
89
|
+
end
|
90
|
+
|
91
|
+
def autocorrect(corrector, node)
|
92
|
+
case node.type
|
93
|
+
when :begin
|
94
|
+
autocorrect(corrector, node.children.first)
|
95
|
+
when :send
|
96
|
+
autocorrect_send_node(corrector, node)
|
97
|
+
when :or, :and
|
98
|
+
corrector.replace(node.loc.operator, node.inverse_operator)
|
99
|
+
autocorrect(corrector, node.lhs)
|
100
|
+
autocorrect(corrector, node.rhs)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def autocorrect_send_node(corrector, node)
|
105
|
+
if node.method?(:!)
|
106
|
+
corrector.remove(node.loc.selector)
|
107
|
+
else
|
108
|
+
corrector.replace(node.loc.selector, inverse_methods[node.method_name])
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def inverse_methods
|
113
|
+
@inverse_methods ||= cop_config['InverseMethods']
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -5,7 +5,7 @@ require 'resolv'
|
|
5
5
|
module RuboCop
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
|
-
#
|
8
|
+
# Checks for hardcoded IP addresses, which can make code
|
9
9
|
# brittle. IP addresses are likely to need to be changed when code
|
10
10
|
# is deployed to a different server or environment, which may break
|
11
11
|
# a deployment if forgotten. Prefer setting IP addresses in ENV or
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
#
|
6
|
+
# Enforces that optional keyword parameters are placed at the
|
7
7
|
# end of the parameters list.
|
8
8
|
#
|
9
9
|
# This improves readability, because when looking through the source,
|
@@ -65,7 +65,7 @@ module RuboCop
|
|
65
65
|
|
66
66
|
def remove_kwargs(kwarg_nodes, corrector)
|
67
67
|
kwarg_nodes.each do |kwarg|
|
68
|
-
with_space = range_with_surrounding_space(
|
68
|
+
with_space = range_with_surrounding_space(kwarg.source_range)
|
69
69
|
corrector.remove(range_with_surrounding_comma(with_space, :left))
|
70
70
|
end
|
71
71
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
#
|
6
|
+
# (by default) checks for uses of the lambda literal syntax for
|
7
7
|
# single line lambdas, and the method call syntax for multiline lambdas.
|
8
8
|
# It is configurable to enforce one of the styles for both single line
|
9
9
|
# and multiline lambdas as well.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
#
|
6
|
+
# Checks for string literal concatenation at
|
7
7
|
# the end of a line.
|
8
8
|
#
|
9
9
|
# @safety
|
@@ -55,7 +55,10 @@ module RuboCop
|
|
55
55
|
private
|
56
56
|
|
57
57
|
def check_token_set(index)
|
58
|
-
|
58
|
+
tokens = processed_source.tokens
|
59
|
+
predecessor = tokens[index]
|
60
|
+
operator = tokens[index + 1]
|
61
|
+
successor = tokens[index + 2]
|
59
62
|
|
60
63
|
return unless eligible_token_set?(predecessor, operator, successor)
|
61
64
|
|
@@ -70,7 +73,7 @@ module RuboCop
|
|
70
73
|
|
71
74
|
def autocorrect(corrector, operator_range)
|
72
75
|
# Include any trailing whitespace so we don't create a syntax error.
|
73
|
-
operator_range = range_with_surrounding_space(
|
76
|
+
operator_range = range_with_surrounding_space(operator_range,
|
74
77
|
side: :right,
|
75
78
|
newlines: false)
|
76
79
|
one_more_char = operator_range.resize(operator_range.size + 1)
|