rubocop 0.80.1 → 0.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/config/default.yml +202 -49
- data/lib/rubocop.rb +20 -61
- data/lib/rubocop/ast_aliases.rb +8 -0
- data/lib/rubocop/cli.rb +13 -7
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +2 -2
- data/lib/rubocop/cli/command/show_cops.rb +2 -6
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +14 -2
- data/lib/rubocop/config_loader.rb +37 -33
- data/lib/rubocop/config_loader_resolver.rb +45 -6
- data/lib/rubocop/config_obsoletion.rb +2 -0
- data/lib/rubocop/config_store.rb +12 -2
- data/lib/rubocop/config_validator.rb +18 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -2
- data/lib/rubocop/cop/badge.rb +5 -5
- data/lib/rubocop/cop/bundler/gem_comment.rb +70 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +0 -21
- data/lib/rubocop/cop/cop.rb +14 -6
- data/lib/rubocop/cop/corrector.rb +48 -24
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +4 -8
- data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -2
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +4 -4
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
- data/lib/rubocop/cop/generator.rb +4 -3
- data/lib/rubocop/cop/ignored_node.rb +1 -3
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/array_alignment.rb +53 -10
- data/lib/rubocop/cop/layout/block_end_newline.rb +5 -3
- data/lib/rubocop/cop/layout/case_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/class_structure.rb +19 -16
- data/lib/rubocop/cop/layout/condition_position.rb +12 -2
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +8 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +126 -0
- data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -3
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +14 -10
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +6 -6
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +5 -9
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +20 -103
- data/lib/rubocop/cop/layout/{tab.rb → indentation_style.rb} +48 -6
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +23 -20
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +13 -4
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -3
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +131 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +19 -2
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -3
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_range_literal.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -3
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +41 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +14 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +12 -0
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +137 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -5
- data/lib/rubocop/cop/lint/empty_when.rb +29 -6
- data/lib/rubocop/cop/lint/ensure_return.rb +19 -2
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +2 -4
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
- data/lib/rubocop/cop/lint/interpolation_check.rb +1 -1
- data/lib/rubocop/cop/lint/literal_as_condition.rb +10 -13
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/loop.rb +7 -5
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +62 -0
- data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +7 -7
- data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +33 -11
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
- data/lib/rubocop/cop/lint/raise_exception.rb +75 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -6
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
- data/lib/rubocop/cop/lint/struct_new_override.rb +58 -0
- data/lib/rubocop/cop/lint/suppressed_exception.rb +23 -26
- data/lib/rubocop/cop/lint/syntax.rb +1 -3
- data/lib/rubocop/cop/lint/unified_integer.rb +0 -2
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/unused_method_argument.rb +32 -6
- data/lib/rubocop/cop/lint/uri_regexp.rb +4 -4
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +13 -3
- data/lib/rubocop/cop/lint/useless_assignment.rb +3 -2
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +6 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/migration/department_name.rb +22 -9
- data/lib/rubocop/cop/mixin/alignment.rb +1 -3
- data/lib/rubocop/cop/mixin/array_min_size.rb +1 -3
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -9
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +2 -4
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +10 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +9 -2
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +3 -2
- data/lib/rubocop/cop/mixin/method_complexity.rb +5 -0
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -1
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +16 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -22
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +1 -1
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
- data/lib/rubocop/cop/naming/constant_name.rb +2 -1
- data/lib/rubocop/cop/naming/file_name.rb +27 -14
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +26 -0
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
- data/lib/rubocop/cop/registry.rb +12 -7
- data/lib/rubocop/cop/severity.rb +1 -3
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -6
- data/lib/rubocop/cop/style/alias.rb +4 -4
- data/lib/rubocop/cop/style/and_or.rb +7 -8
- data/lib/rubocop/cop/style/array_join.rb +2 -2
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -8
- data/lib/rubocop/cop/style/case_equality.rb +24 -1
- data/lib/rubocop/cop/style/character_literal.rb +2 -2
- data/lib/rubocop/cop/style/collection_methods.rb +2 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +9 -11
- data/lib/rubocop/cop/style/copyright.rb +3 -3
- data/lib/rubocop/cop/style/dir.rb +1 -1
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +49 -0
- data/lib/rubocop/cop/style/documentation.rb +43 -5
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +41 -4
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +3 -3
- data/lib/rubocop/cop/style/empty_literal.rb +1 -3
- data/lib/rubocop/cop/style/empty_method.rb +2 -6
- data/lib/rubocop/cop/style/end_block.rb +6 -0
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -3
- data/lib/rubocop/cop/style/exponential_notation.rb +119 -0
- data/lib/rubocop/cop/style/format_string.rb +2 -2
- data/lib/rubocop/cop/style/format_string_token.rb +2 -3
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -6
- data/lib/rubocop/cop/style/guard_clause.rb +25 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +6 -4
- data/lib/rubocop/cop/style/hash_syntax.rb +19 -12
- data/lib/rubocop/cop/style/hash_transform_keys.rb +6 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +6 -5
- data/lib/rubocop/cop/style/if_unless_modifier.rb +23 -3
- data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -0
- data/lib/rubocop/cop/style/inline_comment.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/lambda.rb +3 -2
- data/lib/rubocop/cop/style/lambda_call.rb +1 -21
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/module_function.rb +58 -12
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +16 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +2 -4
- data/lib/rubocop/cop/style/negated_if.rb +3 -3
- data/lib/rubocop/cop/style/negated_unless.rb +3 -3
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -2
- data/lib/rubocop/cop/style/next.rb +2 -2
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
- data/lib/rubocop/cop/style/non_nil_check.rb +5 -5
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
- data/lib/rubocop/cop/style/one_line_conditional.rb +6 -9
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
- data/lib/rubocop/cop/style/or_assignment.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
- data/lib/rubocop/cop/style/redundant_condition.rb +3 -4
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +3 -3
- data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -6
- data/lib/rubocop/cop/style/redundant_percent_q.rb +3 -3
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +89 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +130 -0
- data/lib/rubocop/cop/style/redundant_return.rb +5 -7
- data/lib/rubocop/cop/style/redundant_self.rb +1 -1
- data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/return_nil.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +3 -7
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +39 -0
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -7
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -4
- data/lib/rubocop/cop/style/string_hash_keys.rb +1 -1
- data/lib/rubocop/cop/style/symbol_array.rb +2 -2
- data/lib/rubocop/cop/style/symbol_literal.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -5
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +35 -0
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +41 -0
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +88 -0
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +44 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -3
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +0 -4
- 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/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -1
- data/lib/rubocop/cop/team.rb +61 -25
- data/lib/rubocop/cop/util.rb +25 -1
- data/lib/rubocop/cop/variable_force.rb +3 -9
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -0
- data/lib/rubocop/cop/variable_force/branch.rb +1 -3
- data/lib/rubocop/cop/variable_force/scope.rb +1 -0
- data/lib/rubocop/cop/variable_force/variable.rb +3 -6
- data/lib/rubocop/ext/processed_source.rb +18 -0
- data/lib/rubocop/formatter/base_formatter.rb +0 -4
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -12
- data/lib/rubocop/formatter/formatter_set.rb +1 -4
- data/lib/rubocop/formatter/junit_formatter.rb +27 -6
- data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
- data/lib/rubocop/formatter/tap_formatter.rb +1 -1
- data/lib/rubocop/magic_comment.rb +1 -1
- data/lib/rubocop/name_similarity.rb +12 -9
- data/lib/rubocop/options.rb +33 -12
- data/lib/rubocop/remote_config.rb +1 -3
- data/lib/rubocop/result_cache.rb +5 -7
- data/lib/rubocop/rspec/cop_helper.rb +3 -26
- data/lib/rubocop/rspec/expect_offense.rb +46 -16
- data/lib/rubocop/rspec/shared_contexts.rb +54 -20
- data/lib/rubocop/runner.rb +21 -14
- data/lib/rubocop/target_finder.rb +7 -7
- data/lib/rubocop/target_ruby.rb +5 -2
- data/lib/rubocop/version.rb +5 -3
- metadata +50 -77
- data/lib/rubocop/ast/builder.rb +0 -83
- data/lib/rubocop/ast/node.rb +0 -632
- data/lib/rubocop/ast/node/alias_node.rb +0 -24
- data/lib/rubocop/ast/node/and_node.rb +0 -29
- data/lib/rubocop/ast/node/args_node.rb +0 -29
- data/lib/rubocop/ast/node/array_node.rb +0 -57
- data/lib/rubocop/ast/node/block_node.rb +0 -117
- data/lib/rubocop/ast/node/break_node.rb +0 -17
- data/lib/rubocop/ast/node/case_node.rb +0 -56
- data/lib/rubocop/ast/node/class_node.rb +0 -31
- data/lib/rubocop/ast/node/def_node.rb +0 -82
- data/lib/rubocop/ast/node/defined_node.rb +0 -17
- data/lib/rubocop/ast/node/ensure_node.rb +0 -17
- data/lib/rubocop/ast/node/float_node.rb +0 -12
- data/lib/rubocop/ast/node/for_node.rb +0 -53
- data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
- data/lib/rubocop/ast/node/hash_node.rb +0 -109
- data/lib/rubocop/ast/node/if_node.rb +0 -175
- data/lib/rubocop/ast/node/int_node.rb +0 -12
- data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
- data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
- data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
- data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -261
- data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
- data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
- data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
- data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
- data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
- data/lib/rubocop/ast/node/module_node.rb +0 -24
- data/lib/rubocop/ast/node/or_node.rb +0 -29
- data/lib/rubocop/ast/node/pair_node.rb +0 -63
- data/lib/rubocop/ast/node/range_node.rb +0 -18
- data/lib/rubocop/ast/node/regexp_node.rb +0 -33
- data/lib/rubocop/ast/node/resbody_node.rb +0 -24
- data/lib/rubocop/ast/node/retry_node.rb +0 -17
- data/lib/rubocop/ast/node/return_node.rb +0 -24
- data/lib/rubocop/ast/node/self_class_node.rb +0 -24
- data/lib/rubocop/ast/node/send_node.rb +0 -13
- data/lib/rubocop/ast/node/str_node.rb +0 -16
- data/lib/rubocop/ast/node/super_node.rb +0 -21
- data/lib/rubocop/ast/node/symbol_node.rb +0 -12
- data/lib/rubocop/ast/node/until_node.rb +0 -35
- data/lib/rubocop/ast/node/when_node.rb +0 -53
- data/lib/rubocop/ast/node/while_node.rb +0 -35
- data/lib/rubocop/ast/node/yield_node.rb +0 -21
- data/lib/rubocop/ast/sexp.rb +0 -16
- data/lib/rubocop/ast/traversal.rb +0 -200
- data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
- data/lib/rubocop/node_pattern.rb +0 -887
- data/lib/rubocop/processed_source.rb +0 -216
- data/lib/rubocop/string_util.rb +0 -14
- data/lib/rubocop/token.rb +0 -114
@@ -5,9 +5,10 @@ require 'set'
|
|
5
5
|
module RuboCop
|
6
6
|
module Cop
|
7
7
|
module Layout
|
8
|
-
# This cop checks
|
8
|
+
# This cop checks that the indentation method is consistent.
|
9
|
+
# Either tabs only or spaces only are used for indentation.
|
9
10
|
#
|
10
|
-
# @example
|
11
|
+
# @example EnforcedStyle: spaces (default)
|
11
12
|
# # bad
|
12
13
|
# # This example uses a tab to indent bar.
|
13
14
|
# def foo
|
@@ -20,17 +21,30 @@ module RuboCop
|
|
20
21
|
# bar
|
21
22
|
# end
|
22
23
|
#
|
23
|
-
|
24
|
+
# @example EnforcedStyle: tabs
|
25
|
+
# # bad
|
26
|
+
# # This example uses spaces to indent bar.
|
27
|
+
# def foo
|
28
|
+
# bar
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# # This example uses a tab to indent bar.
|
33
|
+
# def foo
|
34
|
+
# bar
|
35
|
+
# end
|
36
|
+
class IndentationStyle < Cop
|
24
37
|
include Alignment
|
38
|
+
include ConfigurableEnforcedStyle
|
25
39
|
include RangeHelp
|
26
40
|
|
27
|
-
MSG = '
|
41
|
+
MSG = '%<type>s detected in indentation.'
|
28
42
|
|
29
43
|
def investigate(processed_source)
|
30
44
|
str_ranges = string_literal_ranges(processed_source.ast)
|
31
45
|
|
32
46
|
processed_source.lines.each.with_index(1) do |line, lineno|
|
33
|
-
match = line
|
47
|
+
match = find_offence(line)
|
34
48
|
next unless match
|
35
49
|
|
36
50
|
range = source_range(processed_source.buffer,
|
@@ -43,13 +57,37 @@ module RuboCop
|
|
43
57
|
end
|
44
58
|
|
45
59
|
def autocorrect(range)
|
60
|
+
if range.source.include?("\t")
|
61
|
+
autocorrect_lambda_for_tabs(range)
|
62
|
+
else
|
63
|
+
autocorrect_lambda_for_spaces(range)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def find_offence(line)
|
70
|
+
if style == :spaces
|
71
|
+
line.match(/\A\s*\t+/)
|
72
|
+
else
|
73
|
+
line.match(/\A\s* +/)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def autocorrect_lambda_for_tabs(range)
|
46
78
|
lambda do |corrector|
|
47
79
|
spaces = ' ' * configured_indentation_width
|
48
80
|
corrector.replace(range, range.source.gsub(/\t/, spaces))
|
49
81
|
end
|
50
82
|
end
|
51
83
|
|
52
|
-
|
84
|
+
def autocorrect_lambda_for_spaces(range)
|
85
|
+
lambda do |corrector|
|
86
|
+
corrector.replace(range, range.source.gsub(/\A\s+/) do |match|
|
87
|
+
"\t" * (match.size / configured_indentation_width)
|
88
|
+
end)
|
89
|
+
end
|
90
|
+
end
|
53
91
|
|
54
92
|
def in_string_literal?(ranges, tabs_range)
|
55
93
|
ranges.any? { |range| range.contains?(tabs_range) }
|
@@ -69,6 +107,10 @@ module RuboCop
|
|
69
107
|
end
|
70
108
|
end
|
71
109
|
end
|
110
|
+
|
111
|
+
def message(_node)
|
112
|
+
format(MSG, type: style == :spaces ? 'Tab' : 'Space')
|
113
|
+
end
|
72
114
|
end
|
73
115
|
end
|
74
116
|
end
|
@@ -263,9 +263,7 @@ module RuboCop
|
|
263
263
|
def offense(body_node, indentation, style)
|
264
264
|
# This cop only auto-corrects the first statement in a def body, for
|
265
265
|
# example.
|
266
|
-
if body_node.begin_type? && !parentheses?(body_node)
|
267
|
-
body_node = body_node.children.first
|
268
|
-
end
|
266
|
+
body_node = body_node.children.first if body_node.begin_type? && !parentheses?(body_node)
|
269
267
|
|
270
268
|
# Since autocorrect changes a number of lines, and not only the line
|
271
269
|
# where the reported offending range is, we avoid auto-correction if
|
@@ -56,7 +56,7 @@ module RuboCop
|
|
56
56
|
|
57
57
|
def investigate(processed_source)
|
58
58
|
processed_source.each_comment do |comment|
|
59
|
-
next unless
|
59
|
+
next unless /\A#+[^#\s=:+-]/.match?(comment.text)
|
60
60
|
next if comment.loc.line == 1 && allowed_on_first_line?(comment)
|
61
61
|
next if doxygen_comment_style?(comment)
|
62
62
|
next if gemfile_ruby_comment?(comment)
|
@@ -8,7 +8,7 @@ module RuboCop
|
|
8
8
|
# This cop checks the length of lines in the source code.
|
9
9
|
# The maximum length is configurable.
|
10
10
|
# The tab size is configured in the `IndentationWidth`
|
11
|
-
# of the `Layout/
|
11
|
+
# of the `Layout/IndentationStyle` cop.
|
12
12
|
# It also ignores a shebang line by default.
|
13
13
|
#
|
14
14
|
# This cop has some autocorrection capabilities.
|
@@ -21,23 +21,23 @@ module RuboCop
|
|
21
21
|
# are recommended to further format the broken lines.
|
22
22
|
# (Many of these are enabled by default.)
|
23
23
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
24
|
+
# * ArgumentAlignment
|
25
|
+
# * BlockAlignment
|
26
|
+
# * BlockDelimiters
|
27
|
+
# * BlockEndNewline
|
28
|
+
# * ClosingParenthesisIndentation
|
29
|
+
# * FirstArgumentIndentation
|
30
|
+
# * FirstArrayElementIndentation
|
31
|
+
# * FirstHashElementIndentation
|
32
|
+
# * FirstParameterIndentation
|
33
|
+
# * HashAlignment
|
34
|
+
# * IndentationWidth
|
35
|
+
# * MultilineArrayLineBreaks
|
36
|
+
# * MultilineBlockLayout
|
37
|
+
# * MultilineHashBraceLayout
|
38
|
+
# * MultilineHashKeyLineBreaks
|
39
|
+
# * MultilineMethodArgumentLineBreaks
|
40
|
+
# * ParameterAlignment
|
41
41
|
#
|
42
42
|
# Together, these cops will pretty print hashes, arrays,
|
43
43
|
# method calls, etc. For example, let's say the max columns
|
@@ -145,7 +145,7 @@ module RuboCop
|
|
145
145
|
return nil unless next_range.line == range.line
|
146
146
|
|
147
147
|
next_char = next_range.source
|
148
|
-
return nil if /[\r\n]
|
148
|
+
return nil if /[\r\n]/.match?(next_char)
|
149
149
|
return nil if next_char == ';'
|
150
150
|
|
151
151
|
next_range
|
@@ -160,7 +160,10 @@ module RuboCop
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def highlight_start(line)
|
163
|
-
max
|
163
|
+
# TODO: The max with 0 is a quick fix to avoid crashes when a line
|
164
|
+
# begins with many tabs, but getting a correct highlighting range
|
165
|
+
# when tabs are used for indentation doesn't work currently.
|
166
|
+
[max - indentation_difference(line), 0].max
|
164
167
|
end
|
165
168
|
|
166
169
|
def check_line(line, line_index)
|
@@ -37,9 +37,7 @@ module RuboCop
|
|
37
37
|
# ...then each key/value pair is treated as a method 'argument'
|
38
38
|
# when determining where line breaks should appear.
|
39
39
|
if (last_arg = args.last)
|
40
|
-
if last_arg.hash_type? && !last_arg.braces?
|
41
|
-
args = args.concat(args.pop.children)
|
42
|
-
end
|
40
|
+
args = args.concat(args.pop.children) if last_arg.hash_type? && !last_arg.braces?
|
43
41
|
end
|
44
42
|
|
45
43
|
check_line_breaks(node, args)
|
@@ -193,7 +193,7 @@ module RuboCop
|
|
193
193
|
node = node.receiver while node.receiver
|
194
194
|
# ascend to first call which has a dot
|
195
195
|
node = node.parent
|
196
|
-
node = node.parent until node.loc.dot
|
196
|
+
node = node.parent until node.loc.respond_to?(:dot) && node.loc.dot
|
197
197
|
|
198
198
|
return if node.loc.dot.line != node.first_line
|
199
199
|
|
@@ -6,30 +6,39 @@ module RuboCop
|
|
6
6
|
# This cop checks the indentation of the right hand side operand in
|
7
7
|
# binary operations that span more than one line.
|
8
8
|
#
|
9
|
+
# The `aligned` style checks that operators are aligned if they are part
|
10
|
+
# of an `if` or `while` condition, a `return` statement, etc. In other
|
11
|
+
# contexts, the second operand should be indented regardless of enforced
|
12
|
+
# style.
|
13
|
+
#
|
9
14
|
# @example EnforcedStyle: aligned (default)
|
10
15
|
# # bad
|
11
16
|
# if a +
|
12
17
|
# b
|
13
|
-
# something
|
18
|
+
# something &&
|
19
|
+
# something_else
|
14
20
|
# end
|
15
21
|
#
|
16
22
|
# # good
|
17
23
|
# if a +
|
18
24
|
# b
|
19
|
-
# something
|
25
|
+
# something &&
|
26
|
+
# something_else
|
20
27
|
# end
|
21
28
|
#
|
22
29
|
# @example EnforcedStyle: indented
|
23
30
|
# # bad
|
24
31
|
# if a +
|
25
32
|
# b
|
26
|
-
# something
|
33
|
+
# something &&
|
34
|
+
# something_else
|
27
35
|
# end
|
28
36
|
#
|
29
37
|
# # good
|
30
38
|
# if a +
|
31
39
|
# b
|
32
|
-
# something
|
40
|
+
# something &&
|
41
|
+
# something_else
|
33
42
|
# end
|
34
43
|
#
|
35
44
|
class MultilineOperationIndentation < Cop
|
@@ -43,11 +43,11 @@ module RuboCop
|
|
43
43
|
lambda do |corrector|
|
44
44
|
if target.is_a?(RuboCop::AST::Node)
|
45
45
|
if target.parent.children.first == target
|
46
|
-
corrector.insert_before(target
|
46
|
+
corrector.insert_before(target, ' ')
|
47
47
|
else
|
48
|
-
corrector.insert_after(target
|
48
|
+
corrector.insert_after(target, ' ')
|
49
49
|
end
|
50
|
-
elsif target.source
|
50
|
+
elsif /^\s+$/.match?(target.source)
|
51
51
|
corrector.remove(target)
|
52
52
|
else
|
53
53
|
corrector.insert_after(target, ' ')
|
@@ -186,7 +186,7 @@ module RuboCop
|
|
186
186
|
pos = range.begin_pos - 1
|
187
187
|
return false if pos.negative?
|
188
188
|
|
189
|
-
range.source_buffer.source[pos] !~ /[\s
|
189
|
+
range.source_buffer.source[pos] !~ /[\s(|{\[;,*=]/
|
190
190
|
end
|
191
191
|
|
192
192
|
def space_after_missing?(range)
|
@@ -198,7 +198,7 @@ module RuboCop
|
|
198
198
|
return false if accept_namespace_operator?(range) &&
|
199
199
|
namespace_operator?(range, pos)
|
200
200
|
|
201
|
-
char !~ /[\s
|
201
|
+
char !~ /[\s;,#\\)}\].]/
|
202
202
|
end
|
203
203
|
|
204
204
|
def accepted_opening_delimiter?(range, char)
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Layout
|
6
|
+
# Checks method call operators to not have spaces around them.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# foo. bar
|
11
|
+
# foo .bar
|
12
|
+
# foo . bar
|
13
|
+
# foo. bar .buzz
|
14
|
+
# foo
|
15
|
+
# . bar
|
16
|
+
# . buzz
|
17
|
+
# foo&. bar
|
18
|
+
# foo &.bar
|
19
|
+
# foo &. bar
|
20
|
+
# foo &. bar&. buzz
|
21
|
+
# RuboCop:: Cop
|
22
|
+
# RuboCop:: Cop:: Cop
|
23
|
+
# :: RuboCop::Cop
|
24
|
+
#
|
25
|
+
# # good
|
26
|
+
# foo.bar
|
27
|
+
# foo.bar.buzz
|
28
|
+
# foo
|
29
|
+
# .bar
|
30
|
+
# .buzz
|
31
|
+
# foo&.bar
|
32
|
+
# foo&.bar&.buzz
|
33
|
+
# RuboCop::Cop
|
34
|
+
# RuboCop::Cop::Cop
|
35
|
+
# ::RuboCop::Cop
|
36
|
+
#
|
37
|
+
class SpaceAroundMethodCallOperator < Cop
|
38
|
+
include SurroundingSpace
|
39
|
+
|
40
|
+
MSG = 'Avoid using spaces around a method call operator.'
|
41
|
+
|
42
|
+
def on_send(node)
|
43
|
+
return unless dot_or_safe_navigation_operator?(node)
|
44
|
+
|
45
|
+
check_and_add_offense(node)
|
46
|
+
end
|
47
|
+
|
48
|
+
def on_const(node)
|
49
|
+
return unless node.loc.double_colon
|
50
|
+
|
51
|
+
check_and_add_offense(node, false)
|
52
|
+
end
|
53
|
+
|
54
|
+
def autocorrect(node)
|
55
|
+
operator = operator_token(node)
|
56
|
+
left = left_token_for_auto_correction(node, operator)
|
57
|
+
right = right_token_for_auto_correction(operator)
|
58
|
+
|
59
|
+
lambda do |corrector|
|
60
|
+
SpaceCorrector.remove_space(
|
61
|
+
processed_source, corrector, left, right
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
alias on_csend on_send
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def check_and_add_offense(node, add_left_offense = true)
|
71
|
+
operator = operator_token(node)
|
72
|
+
left = previous_token(operator)
|
73
|
+
right = next_token(operator)
|
74
|
+
|
75
|
+
if !right.comment? && valid_right_token?(right, operator)
|
76
|
+
no_space_offenses(node, operator, right, MSG)
|
77
|
+
end
|
78
|
+
return unless valid_left_token?(left, operator)
|
79
|
+
|
80
|
+
no_space_offenses(node, left, operator, MSG) if add_left_offense
|
81
|
+
end
|
82
|
+
|
83
|
+
def operator_token(node)
|
84
|
+
operator_location =
|
85
|
+
node.const_type? ? node.loc.double_colon : node.loc.dot
|
86
|
+
|
87
|
+
processed_source.find_token do |token|
|
88
|
+
token.pos == operator_location
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def previous_token(current_token)
|
93
|
+
index = processed_source.tokens.index(current_token)
|
94
|
+
index.zero? ? nil : processed_source.tokens[index - 1]
|
95
|
+
end
|
96
|
+
|
97
|
+
def next_token(current_token)
|
98
|
+
index = processed_source.tokens.index(current_token)
|
99
|
+
processed_source.tokens[index + 1]
|
100
|
+
end
|
101
|
+
|
102
|
+
def dot_or_safe_navigation_operator?(node)
|
103
|
+
node.dot? || node.safe_navigation?
|
104
|
+
end
|
105
|
+
|
106
|
+
def valid_left_token?(left, operator)
|
107
|
+
left && left.line == operator.line
|
108
|
+
end
|
109
|
+
|
110
|
+
def valid_right_token?(right, operator)
|
111
|
+
right && right.line == operator.line
|
112
|
+
end
|
113
|
+
|
114
|
+
def left_token_for_auto_correction(node, operator)
|
115
|
+
left_token = previous_token(operator)
|
116
|
+
return operator if node.const_type?
|
117
|
+
return left_token if valid_left_token?(left_token, operator)
|
118
|
+
|
119
|
+
operator
|
120
|
+
end
|
121
|
+
|
122
|
+
def right_token_for_auto_correction(operator)
|
123
|
+
right_token = next_token(operator)
|
124
|
+
return right_token if !right_token.comment? && valid_right_token?(right_token, operator)
|
125
|
+
|
126
|
+
operator
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -139,7 +139,7 @@ module RuboCop
|
|
139
139
|
elsif range.source.end_with?("\n")
|
140
140
|
corrector.replace(range, " #{range.source.strip}\n")
|
141
141
|
else
|
142
|
-
corrector
|
142
|
+
enclose_operator_with_space(corrector, range)
|
143
143
|
end
|
144
144
|
end
|
145
145
|
end
|
@@ -170,12 +170,25 @@ module RuboCop
|
|
170
170
|
yield msg if msg
|
171
171
|
end
|
172
172
|
|
173
|
+
def enclose_operator_with_space(corrector, range)
|
174
|
+
operator = range.source
|
175
|
+
|
176
|
+
# If `ForceEqualSignAlignment` is true, `Layout/ExtraSpacing` cop
|
177
|
+
# inserts spaces before operator. If `Layout/SpaceAroundOperators` cop
|
178
|
+
# inserts a space, it collides and raises the infinite loop error.
|
179
|
+
if force_equal_sign_alignment?
|
180
|
+
corrector.insert_after(range, ' ') unless operator.end_with?(' ')
|
181
|
+
else
|
182
|
+
corrector.replace(range, " #{operator.strip} ")
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
173
186
|
def offense_message(type, operator, with_space, right_operand)
|
174
187
|
if should_not_have_surrounding_space?(operator)
|
175
188
|
return if with_space.is?(operator.source)
|
176
189
|
|
177
190
|
"Space around operator `#{operator.source}` detected."
|
178
|
-
elsif with_space.source
|
191
|
+
elsif !/^\s.*\s$/.match?(with_space.source)
|
179
192
|
"Surrounding space missing for operator `#{operator.source}`."
|
180
193
|
elsif excess_leading_space?(type, operator, with_space) ||
|
181
194
|
excess_trailing_space?(right_operand, with_space)
|
@@ -216,6 +229,10 @@ module RuboCop
|
|
216
229
|
cop_config['EnforcedStyleForExponentOperator'] == 'space'
|
217
230
|
end
|
218
231
|
|
232
|
+
def force_equal_sign_alignment?
|
233
|
+
config.for_cop('Layout/ExtraSpacing')['ForceEqualSignAlignment']
|
234
|
+
end
|
235
|
+
|
219
236
|
def should_not_have_surrounding_space?(operator)
|
220
237
|
operator.is?('**') ? !space_around_exponent_operator? : false
|
221
238
|
end
|