rubocop 0.76.0 → 0.83.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/LICENSE.txt +1 -1
- data/README.md +6 -6
- data/config/default.yml +466 -306
- data/lib/rubocop/ast/builder.rb +45 -42
- data/lib/rubocop/ast/node/array_node.rb +13 -0
- data/lib/rubocop/ast/node/block_node.rb +7 -1
- data/lib/rubocop/ast/node/case_match_node.rb +56 -0
- data/lib/rubocop/ast/node/def_node.rb +11 -0
- data/lib/rubocop/ast/node/forward_args_node.rb +18 -0
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +8 -0
- data/lib/rubocop/ast/node/regexp_node.rb +2 -4
- data/lib/rubocop/ast/node/send_node.rb +4 -0
- data/lib/rubocop/ast/node.rb +13 -20
- data/lib/rubocop/ast/traversal.rb +29 -10
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
- data/lib/rubocop/cli/command/base.rb +33 -0
- data/lib/rubocop/cli/command/execute_runner.rb +76 -0
- data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
- data/lib/rubocop/cli/command/show_cops.rb +80 -0
- data/lib/rubocop/cli/command/version.rb +17 -0
- data/lib/rubocop/cli/command.rb +21 -0
- data/lib/rubocop/cli/environment.rb +21 -0
- data/lib/rubocop/cli.rb +20 -233
- data/lib/rubocop/comment_config.rb +6 -1
- data/lib/rubocop/config.rb +41 -11
- data/lib/rubocop/config_loader.rb +54 -44
- data/lib/rubocop/config_loader_resolver.rb +28 -1
- data/lib/rubocop/config_obsoletion.rb +67 -11
- data/lib/rubocop/config_validator.rb +74 -99
- data/lib/rubocop/cop/autocorrect_logic.rb +7 -4
- data/lib/rubocop/cop/badge.rb +5 -5
- data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +3 -3
- data/lib/rubocop/cop/cop.rb +21 -0
- data/lib/rubocop/cop/corrector.rb +48 -24
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -2
- 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 +3 -3
- 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 -2
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/generator.rb +6 -6
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -1
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/array_alignment.rb +82 -0
- data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +1 -1
- data/lib/rubocop/cop/layout/block_end_newline.rb +5 -3
- 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_line_between_defs.rb +2 -1
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +68 -0
- data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +5 -5
- data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +20 -14
- data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +4 -4
- data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
- data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +10 -6
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +7 -7
- data/lib/rubocop/cop/layout/{tab.rb → indentation_style.rb} +48 -6
- data/lib/rubocop/cop/layout/leading_comment_space.rb +34 -3
- data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
- data/lib/rubocop/cop/{metrics → layout}/line_length.rb +72 -110
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +15 -6
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +0 -4
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
- 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/{align_parameters.rb → parameter_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -3
- data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +133 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +69 -9
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +8 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -9
- data/lib/rubocop/cop/layout/space_inside_range_literal.rb +2 -2
- data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +38 -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 +2 -2
- data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
- data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -5
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/empty_when.rb +29 -6
- data/lib/rubocop/cop/lint/ensure_return.rb +18 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/ineffective_access_modifier.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 +6 -4
- data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +2 -2
- data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
- data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +21 -9
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -2
- data/lib/rubocop/cop/lint/raise_exception.rb +75 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +4 -9
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +13 -8
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +2 -2
- data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
- 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/{handle_exceptions.rb → suppressed_exception.rb} +13 -29
- data/lib/rubocop/cop/lint/unified_integer.rb +0 -2
- 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 +69 -23
- data/lib/rubocop/cop/lint/useless_assignment.rb +3 -2
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +5 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +5 -1
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/migration/department_name.rb +47 -6
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +4 -0
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +14 -5
- data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +178 -0
- data/lib/rubocop/cop/mixin/line_length_help.rb +89 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +5 -0
- data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -1
- data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -24
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +9 -13
- data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +2 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +6 -6
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +26 -0
- data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +4 -4
- data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
- data/lib/rubocop/cop/offense.rb +11 -0
- data/lib/rubocop/cop/registry.rb +15 -3
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -6
- data/lib/rubocop/cop/style/alias.rb +5 -5
- data/lib/rubocop/cop/style/and_or.rb +5 -6
- data/lib/rubocop/cop/style/array_join.rb +2 -2
- data/lib/rubocop/cop/style/attr.rb +8 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +60 -1
- 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 +10 -10
- data/lib/rubocop/cop/style/copyright.rb +1 -1
- 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/each_for_simple_loop.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +3 -3
- data/lib/rubocop/cop/style/empty_method.rb +1 -5
- data/lib/rubocop/cop/style/end_block.rb +6 -0
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +2 -2
- 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/frozen_string_literal_comment.rb +89 -11
- data/lib/rubocop/cop/style/guard_clause.rb +28 -4
- data/lib/rubocop/cop/style/hash_each_methods.rb +89 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +3 -5
- data/lib/rubocop/cop/style/hash_transform_keys.rb +83 -0
- data/lib/rubocop/cop/style/hash_transform_values.rb +80 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +61 -6
- data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -0
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +9 -5
- data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
- 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/omit_parentheses.rb +169 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -205
- data/lib/rubocop/cop/style/mixin_grouping.rb +2 -2
- 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_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +21 -2
- data/lib/rubocop/cop/style/mutable_constant.rb +2 -4
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +9 -9
- data/lib/rubocop/cop/style/next.rb +7 -7
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
- data/lib/rubocop/cop/style/non_nil_check.rb +4 -4
- 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 +8 -4
- data/lib/rubocop/cop/style/numeric_predicate.rb +5 -4
- data/lib/rubocop/cop/style/one_line_conditional.rb +4 -3
- data/lib/rubocop/cop/style/option_hash.rb +3 -3
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
- data/lib/rubocop/cop/style/or_assignment.rb +4 -3
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
- 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 +18 -6
- 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 +3 -3
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
- data/lib/rubocop/cop/style/redundant_return.rb +7 -15
- data/lib/rubocop/cop/style/redundant_self.rb +1 -1
- data/lib/rubocop/cop/style/redundant_sort.rb +3 -3
- 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 +1 -1
- 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 +1 -1
- 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 +3 -3
- data/lib/rubocop/cop/style/symbol_literal.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -3
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +35 -22
- 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 +7 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +6 -6
- 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/while_until_modifier.rb +2 -2
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -1
- data/lib/rubocop/cop/team.rb +5 -0
- data/lib/rubocop/cop/util.rb +24 -0
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -0
- data/lib/rubocop/cop/variable_force/scope.rb +1 -0
- data/lib/rubocop/cop/variable_force/variable.rb +1 -0
- data/lib/rubocop/cop/variable_force.rb +4 -1
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/clang_style_formatter.rb +0 -2
- data/lib/rubocop/formatter/formatter_set.rb +1 -1
- data/lib/rubocop/formatter/json_formatter.rb +6 -5
- data/lib/rubocop/formatter/junit_formatter.rb +74 -0
- data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
- data/lib/rubocop/formatter/tap_formatter.rb +0 -2
- data/lib/rubocop/name_similarity.rb +12 -9
- data/lib/rubocop/node_pattern.rb +97 -11
- data/lib/rubocop/options.rb +26 -13
- data/lib/rubocop/processed_source.rb +1 -4
- data/lib/rubocop/rake_task.rb +1 -0
- data/lib/rubocop/result_cache.rb +23 -7
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +1 -1
- data/lib/rubocop/rspec/shared_contexts.rb +5 -4
- data/lib/rubocop/runner.rb +25 -4
- data/lib/rubocop/target_finder.rb +6 -4
- data/lib/rubocop/target_ruby.rb +151 -0
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +53 -27
- metadata +73 -48
- data/lib/rubocop/cop/layout/align_array.rb +0 -39
- data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
- data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -209
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
- data/lib/rubocop/string_util.rb +0 -14
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Layout
|
6
|
+
# Checks for a newline after attribute accessor.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# attr_accessor :foo
|
11
|
+
# def do_something
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# attr_accessor :foo
|
16
|
+
#
|
17
|
+
# def do_something
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# attr_accessor :foo
|
22
|
+
# attr_reader :bar
|
23
|
+
# attr_writer :baz
|
24
|
+
# attr :qux
|
25
|
+
#
|
26
|
+
# def do_something
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
class EmptyLinesAroundAttributeAccessor < Cop
|
30
|
+
include RangeHelp
|
31
|
+
|
32
|
+
MSG = 'Add an empty line after attribute accessor.'
|
33
|
+
|
34
|
+
def on_send(node)
|
35
|
+
return unless node.attribute_accessor?
|
36
|
+
return if next_line_empty?(node.last_line)
|
37
|
+
|
38
|
+
next_line_node = next_line_node(node)
|
39
|
+
return if next_line_node.nil? || attribute_accessor?(next_line_node)
|
40
|
+
|
41
|
+
add_offense(node)
|
42
|
+
end
|
43
|
+
|
44
|
+
def autocorrect(node)
|
45
|
+
lambda do |corrector|
|
46
|
+
range = range_by_whole_lines(node.source_range)
|
47
|
+
|
48
|
+
corrector.insert_after(range, "\n")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def next_line_empty?(line)
|
55
|
+
processed_source[line].blank?
|
56
|
+
end
|
57
|
+
|
58
|
+
def next_line_node(node)
|
59
|
+
node.parent.children[node.sibling_index + 1]
|
60
|
+
end
|
61
|
+
|
62
|
+
def attribute_accessor?(node)
|
63
|
+
node.send_type? && node.attribute_accessor?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -114,7 +114,7 @@ module RuboCop
|
|
114
114
|
|
115
115
|
# Returns an array of ranges that should not be reported. It's the
|
116
116
|
# extra spaces between the keys and values in a multiline hash,
|
117
|
-
# since those are handled by the
|
117
|
+
# since those are handled by the Layout/HashAlignment cop.
|
118
118
|
def ignored_ranges(ast)
|
119
119
|
return [] unless ast
|
120
120
|
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
# rubocop:disable
|
5
|
+
# rubocop:disable Layout/LineLength
|
6
6
|
module Layout
|
7
7
|
# This cop checks the indentation of the first argument in a method call.
|
8
|
-
# Arguments after the first one are checked by Layout/
|
8
|
+
# Arguments after the first one are checked by Layout/ArgumentAlignment,
|
9
9
|
# not by this cop.
|
10
10
|
#
|
11
11
|
# For indenting the first parameter of method *definitions*, check out
|
12
|
-
# Layout/
|
12
|
+
# Layout/FirstParameterIndentation.
|
13
13
|
#
|
14
14
|
# @example
|
15
15
|
#
|
@@ -142,8 +142,8 @@ module RuboCop
|
|
142
142
|
# nested_first_param),
|
143
143
|
# second_param
|
144
144
|
#
|
145
|
-
class
|
146
|
-
# rubocop:enable
|
145
|
+
class FirstArgumentIndentation < Cop
|
146
|
+
# rubocop:enable Layout/LineLength
|
147
147
|
include Alignment
|
148
148
|
include ConfigurableEnforcedStyle
|
149
149
|
include RangeHelp
|
data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb}
RENAMED
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Layout
|
6
6
|
# This cop checks the indentation of the first element in an array literal
|
7
7
|
# where the opening bracket and the first element are on separate lines.
|
8
|
-
# The other elements' indentations are handled by the
|
8
|
+
# The other elements' indentations are handled by the ArrayAlignment cop.
|
9
9
|
#
|
10
10
|
# By default, array literals that are arguments in a method call with
|
11
11
|
# parentheses, and where the opening square bracket of the array is on the
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
22
22
|
# @example EnforcedStyle: special_inside_parentheses (default)
|
23
23
|
# # The `special_inside_parentheses` style enforces that the first
|
24
24
|
# # element in an array literal where the opening bracket and first
|
25
|
-
# # element are on
|
25
|
+
# # element are on separate lines is indented one step (two spaces) more
|
26
26
|
# # than the position inside the opening parenthesis.
|
27
27
|
#
|
28
28
|
# #bad
|
@@ -44,7 +44,7 @@ module RuboCop
|
|
44
44
|
# @example EnforcedStyle: consistent
|
45
45
|
# # The `consistent` style enforces that the first element in an array
|
46
46
|
# # literal where the opening bracket and the first element are on
|
47
|
-
# #
|
47
|
+
# # separate lines is indented the same as an array literal which is not
|
48
48
|
# # defined inside a method call.
|
49
49
|
#
|
50
50
|
# #bad
|
@@ -79,7 +79,7 @@ module RuboCop
|
|
79
79
|
# and_now_for_something = [
|
80
80
|
# :completely_different
|
81
81
|
# ]
|
82
|
-
class
|
82
|
+
class FirstArrayElementIndentation < Cop
|
83
83
|
include Alignment
|
84
84
|
include ConfigurableEnforcedStyle
|
85
85
|
include MultilineElementIndentation
|
@@ -125,21 +125,15 @@ module RuboCop
|
|
125
125
|
|
126
126
|
def check_right_bracket(right_bracket, left_bracket, left_parenthesis)
|
127
127
|
# if the right bracket is on the same line as the last value, accept
|
128
|
-
|
128
|
+
if /\S/.match?(right_bracket.source_line[0...right_bracket.column])
|
129
|
+
return
|
130
|
+
end
|
129
131
|
|
130
132
|
expected_column = base_column(left_bracket, left_parenthesis)
|
131
133
|
@column_delta = expected_column - right_bracket.column
|
132
134
|
return if @column_delta.zero?
|
133
135
|
|
134
|
-
msg =
|
135
|
-
'Indent the right bracket the same as the left bracket.'
|
136
|
-
elsif style == :special_inside_parentheses && left_parenthesis
|
137
|
-
'Indent the right bracket the same as the first position ' \
|
138
|
-
'after the preceding left parenthesis.'
|
139
|
-
else
|
140
|
-
'Indent the right bracket the same as the start of the line' \
|
141
|
-
' where the left bracket is.'
|
142
|
-
end
|
136
|
+
msg = msg(left_parenthesis)
|
143
137
|
add_offense(right_bracket, location: right_bracket, message: msg)
|
144
138
|
end
|
145
139
|
|
@@ -161,6 +155,18 @@ module RuboCop
|
|
161
155
|
base_description: base_description
|
162
156
|
)
|
163
157
|
end
|
158
|
+
|
159
|
+
def msg(left_parenthesis)
|
160
|
+
if style == :align_brackets
|
161
|
+
'Indent the right bracket the same as the left bracket.'
|
162
|
+
elsif style == :special_inside_parentheses && left_parenthesis
|
163
|
+
'Indent the right bracket the same as the first position ' \
|
164
|
+
'after the preceding left parenthesis.'
|
165
|
+
else
|
166
|
+
'Indent the right bracket the same as the start of the line' \
|
167
|
+
' where the left bracket is.'
|
168
|
+
end
|
169
|
+
end
|
164
170
|
end
|
165
171
|
end
|
166
172
|
end
|
data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb}
RENAMED
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Layout
|
6
6
|
# This cop checks the indentation of the first key in a hash literal
|
7
7
|
# where the opening brace and the first key are on separate lines. The
|
8
|
-
# other keys' indentations are handled by the
|
8
|
+
# other keys' indentations are handled by the HashAlignment cop.
|
9
9
|
#
|
10
10
|
# By default, Hash literals that are arguments in a method call with
|
11
11
|
# parentheses, and where the opening curly brace of the hash is on the
|
@@ -77,7 +77,7 @@ module RuboCop
|
|
77
77
|
# and_now_for_something = {
|
78
78
|
# completely: :different
|
79
79
|
# }
|
80
|
-
class
|
80
|
+
class FirstHashElementIndentation < Cop
|
81
81
|
include Alignment
|
82
82
|
include ConfigurableEnforcedStyle
|
83
83
|
include MultilineElementIndentation
|
@@ -128,7 +128,7 @@ module RuboCop
|
|
128
128
|
|
129
129
|
def check_right_brace(right_brace, left_brace, left_parenthesis)
|
130
130
|
# if the right brace is on the same line as the last value, accept
|
131
|
-
return if right_brace.source_line[0...right_brace.column]
|
131
|
+
return if /\S/.match?(right_brace.source_line[0...right_brace.column])
|
132
132
|
|
133
133
|
expected_column = base_column(left_brace, left_parenthesis)
|
134
134
|
@column_delta = expected_column - right_brace.column
|
@@ -149,7 +149,7 @@ module RuboCop
|
|
149
149
|
def separator_style?(first_pair)
|
150
150
|
separator = first_pair.loc.operator
|
151
151
|
key = "Enforced#{separator.is?(':') ? 'Colon' : 'HashRocket'}Style"
|
152
|
-
config.for_cop('Layout/
|
152
|
+
config.for_cop('Layout/HashAlignment')[key] == 'separator'
|
153
153
|
end
|
154
154
|
|
155
155
|
def check_based_on_longest_key(hash_node, left_brace, left_parenthesis)
|
@@ -5,10 +5,10 @@ module RuboCop
|
|
5
5
|
module Layout
|
6
6
|
# This cop checks the indentation of the first parameter in a method
|
7
7
|
# definition. Parameters after the first one are checked by
|
8
|
-
# Layout/
|
8
|
+
# Layout/ParameterAlignment, not by this cop.
|
9
9
|
#
|
10
10
|
# For indenting the first argument of method *calls*, check out
|
11
|
-
# Layout/
|
11
|
+
# Layout/FirstArgumentIndentation, which supports options related to
|
12
12
|
# nesting that are irrelevant for method *definitions*.
|
13
13
|
#
|
14
14
|
# @example
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
# second_param)
|
42
42
|
# 123
|
43
43
|
# end
|
44
|
-
class
|
44
|
+
class FirstParameterIndentation < Cop
|
45
45
|
include Alignment
|
46
46
|
include ConfigurableEnforcedStyle
|
47
47
|
include MultilineElementIndentation
|
@@ -175,12 +175,16 @@ module RuboCop
|
|
175
175
|
# do_something({foo: 1,
|
176
176
|
# bar: 2})
|
177
177
|
#
|
178
|
-
class
|
179
|
-
include
|
178
|
+
class HashAlignment < Cop
|
179
|
+
include HashAlignmentStyles
|
180
180
|
include RangeHelp
|
181
181
|
|
182
|
-
|
183
|
-
|
182
|
+
MESSAGES = { KeyAlignment => 'Align the keys of a hash literal if ' \
|
183
|
+
'they span more than one line.',
|
184
|
+
SeparatorAlignment => 'Align the separators of a hash ' \
|
185
|
+
'literal if they span more than one line.',
|
186
|
+
TableAlignment => 'Align the keys and values of a hash ' \
|
187
|
+
'literal if they span more than one line.' }.freeze
|
184
188
|
|
185
189
|
def on_send(node)
|
186
190
|
return if double_splat?(node)
|
@@ -249,9 +253,9 @@ module RuboCop
|
|
249
253
|
end
|
250
254
|
|
251
255
|
def add_offences
|
252
|
-
|
256
|
+
format, offences = offences_by.min_by { |_, v| v.length }
|
253
257
|
(offences || []).each do |offence|
|
254
|
-
add_offense
|
258
|
+
add_offense(offence, message: MESSAGES[format])
|
255
259
|
end
|
256
260
|
end
|
257
261
|
|
@@ -169,7 +169,7 @@ module RuboCop
|
|
169
169
|
end
|
170
170
|
|
171
171
|
def add_correct_closing_paren(node, corrector)
|
172
|
-
corrector.insert_after(node.arguments.last
|
172
|
+
corrector.insert_after(node.arguments.last, ')')
|
173
173
|
end
|
174
174
|
|
175
175
|
def remove_incorrect_closing_paren(node, corrector)
|
@@ -249,7 +249,7 @@ module RuboCop
|
|
249
249
|
def add_correct_external_trailing_comma(node, corrector)
|
250
250
|
return unless external_trailing_comma?(node)
|
251
251
|
|
252
|
-
corrector.insert_after(node.arguments.last
|
252
|
+
corrector.insert_after(node.arguments.last, ',')
|
253
253
|
end
|
254
254
|
|
255
255
|
def remove_incorrect_external_trailing_comma(node, corrector)
|
@@ -8,9 +8,9 @@ module RuboCop
|
|
8
8
|
# In Ruby 2.3 or newer, squiggly heredocs (`<<~`) should be used. If you
|
9
9
|
# use the older rubies, you should introduce some library to your project
|
10
10
|
# (e.g. ActiveSupport, Powerpack or Unindent).
|
11
|
-
# Note: When `
|
11
|
+
# Note: When `Layout/LineLength`'s `AllowHeredoc` is false (not default),
|
12
12
|
# this cop does not add any offenses for long here documents to
|
13
|
-
# avoid `
|
13
|
+
# avoid `Layout/LineLength`'s offenses.
|
14
14
|
#
|
15
15
|
# @example EnforcedStyle: squiggly (default)
|
16
16
|
# # bad
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
# something
|
50
50
|
# RUBY
|
51
51
|
#
|
52
|
-
class
|
52
|
+
class HeredocIndentation < Cop
|
53
53
|
include Heredoc
|
54
54
|
include ConfigurableEnforcedStyle
|
55
55
|
|
@@ -159,11 +159,11 @@ module RuboCop
|
|
159
159
|
end
|
160
160
|
|
161
161
|
def unlimited_heredoc_length?
|
162
|
-
config.for_cop('
|
162
|
+
config.for_cop('Layout/LineLength')['AllowHeredoc']
|
163
163
|
end
|
164
164
|
|
165
165
|
def max_line_length
|
166
|
-
config.for_cop('
|
166
|
+
config.for_cop('Layout/LineLength')['Max']
|
167
167
|
end
|
168
168
|
|
169
169
|
def correct_by_squiggly(node)
|
@@ -184,14 +184,14 @@ module RuboCop
|
|
184
184
|
def adjust_minus(corrector, node)
|
185
185
|
heredoc_beginning = node.loc.expression.source
|
186
186
|
corrected = heredoc_beginning.sub(/<<-?/, '<<~')
|
187
|
-
corrector.replace(node
|
187
|
+
corrector.replace(node, corrected)
|
188
188
|
end
|
189
189
|
|
190
190
|
def correct_by_library(node)
|
191
191
|
lambda do |corrector|
|
192
192
|
corrector.replace(node.loc.heredoc_body, indented_body(node))
|
193
193
|
corrected = ".#{STRIP_METHODS[style]}"
|
194
|
-
corrector.insert_after(node
|
194
|
+
corrector.insert_after(node, corrected)
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
@@ -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
|
@@ -35,6 +35,20 @@ module RuboCop
|
|
35
35
|
# # Another line of comment
|
36
36
|
# #*
|
37
37
|
#
|
38
|
+
# @example AllowGemfileRubyComment: false (default)
|
39
|
+
#
|
40
|
+
# # bad
|
41
|
+
#
|
42
|
+
# #ruby=2.7.0
|
43
|
+
# #ruby-gemset=myproject
|
44
|
+
#
|
45
|
+
# @example AllowGemfileRubyComment: true
|
46
|
+
#
|
47
|
+
# # good
|
48
|
+
#
|
49
|
+
# #ruby=2.7.0
|
50
|
+
# #ruby-gemset=myproject
|
51
|
+
#
|
38
52
|
class LeadingCommentSpace < Cop
|
39
53
|
include RangeHelp
|
40
54
|
|
@@ -42,9 +56,10 @@ module RuboCop
|
|
42
56
|
|
43
57
|
def investigate(processed_source)
|
44
58
|
processed_source.each_comment do |comment|
|
45
|
-
next unless
|
59
|
+
next unless /\A#+[^#\s=:+-]/.match?(comment.text)
|
46
60
|
next if comment.loc.line == 1 && allowed_on_first_line?(comment)
|
47
|
-
next if
|
61
|
+
next if doxygen_comment_style?(comment)
|
62
|
+
next if gemfile_ruby_comment?(comment)
|
48
63
|
|
49
64
|
add_offense(comment)
|
50
65
|
end
|
@@ -80,7 +95,23 @@ module RuboCop
|
|
80
95
|
end
|
81
96
|
|
82
97
|
def doxygen_comment_style?(comment)
|
83
|
-
comment.text.start_with?('#*')
|
98
|
+
allow_doxygen_comment? && comment.text.start_with?('#*')
|
99
|
+
end
|
100
|
+
|
101
|
+
def allow_gemfile_ruby_comment?
|
102
|
+
cop_config['AllowGemfileRubyComment']
|
103
|
+
end
|
104
|
+
|
105
|
+
def gemfile?
|
106
|
+
File.basename(processed_source.file_path).eql?('Gemfile')
|
107
|
+
end
|
108
|
+
|
109
|
+
def ruby_comment_in_gemfile?(comment)
|
110
|
+
gemfile? && comment.text.start_with?('#ruby')
|
111
|
+
end
|
112
|
+
|
113
|
+
def gemfile_ruby_comment?(comment)
|
114
|
+
allow_gemfile_ruby_comment? && ruby_comment_in_gemfile?(comment)
|
84
115
|
end
|
85
116
|
end
|
86
117
|
end
|