rubocop 0.83.0 → 0.87.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -18
- data/config/default.yml +128 -23
- data/lib/rubocop.rb +21 -59
- data/lib/rubocop/ast_aliases.rb +8 -0
- data/lib/rubocop/cli.rb +2 -4
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +42 -7
- data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
- data/lib/rubocop/cli/command/show_cops.rb +2 -6
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_loader.rb +24 -70
- data/lib/rubocop/config_loader_resolver.rb +21 -9
- data/lib/rubocop/config_obsoletion.rb +0 -1
- data/lib/rubocop/config_store.rb +12 -2
- data/lib/rubocop/cop/autocorrect_logic.rb +14 -25
- data/lib/rubocop/cop/base.rb +399 -0
- data/lib/rubocop/cop/bundler/gem_comment.rb +70 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
- data/lib/rubocop/cop/commissioner.rb +48 -71
- data/lib/rubocop/cop/cop.rb +91 -227
- data/lib/rubocop/cop/corrector.rb +38 -115
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -6
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/generator.rb +2 -2
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/ignored_node.rb +1 -3
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
- data/lib/rubocop/cop/layout/case_indentation.rb +21 -22
- data/lib/rubocop/cop/layout/class_structure.rb +19 -16
- data/lib/rubocop/cop/layout/comment_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +57 -4
- data/lib/rubocop/cop/layout/end_of_line.rb +3 -3
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -4
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -3
- data/lib/rubocop/cop/layout/first_array_element_line_break.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 +8 -9
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +3 -7
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +20 -103
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
- data/lib/rubocop/cop/layout/line_length.rb +17 -17
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -2
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
- data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +19 -25
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -3
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +14 -0
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -4
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -3
- data/lib/rubocop/cop/legacy/corrections_proxy.rb +49 -0
- data/lib/rubocop/cop/legacy/corrector.rb +29 -0
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +5 -2
- data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +137 -0
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -3
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +38 -2
- data/lib/rubocop/cop/lint/interpolation_check.rb +13 -0
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +69 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
- 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/parentheses_as_grouped_expression.rb +20 -5
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +12 -4
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +31 -25
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +9 -1
- data/lib/rubocop/cop/lint/suppressed_exception.rb +15 -2
- data/lib/rubocop/cop/lint/syntax.rb +11 -28
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -4
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +22 -0
- data/lib/rubocop/cop/metrics/class_length.rb +25 -2
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +35 -3
- data/lib/rubocop/cop/metrics/method_length.rb +23 -0
- data/lib/rubocop/cop/metrics/module_length.rb +25 -2
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +129 -0
- data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
- data/lib/rubocop/cop/migration/department_name.rb +7 -7
- data/lib/rubocop/cop/mixin/alignment.rb +1 -3
- data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
- data/lib/rubocop/cop/mixin/array_min_size.rb +1 -3
- data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -9
- data/lib/rubocop/cop/mixin/code_length.rb +4 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +3 -5
- data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +3 -1
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/nil_methods.rb +3 -5
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +6 -1
- data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +1 -1
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +43 -0
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +10 -5
- data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -13
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +7 -5
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +27 -4
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +3 -3
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
- data/lib/rubocop/cop/naming/file_name.rb +28 -17
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +4 -6
- data/lib/rubocop/cop/naming/variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/variable_number.rb +1 -1
- data/lib/rubocop/cop/offense.rb +16 -2
- data/lib/rubocop/cop/registry.rb +63 -10
- data/lib/rubocop/cop/severity.rb +1 -3
- data/lib/rubocop/cop/style/accessor_grouping.rb +136 -0
- data/lib/rubocop/cop/style/and_or.rb +2 -2
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +2 -2
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +121 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +4 -12
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/class_vars.rb +21 -0
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -4
- data/lib/rubocop/cop/style/copyright.rb +5 -5
- data/lib/rubocop/cop/style/date_time.rb +1 -1
- data/lib/rubocop/cop/style/dir.rb +2 -2
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +2 -2
- data/lib/rubocop/cop/style/double_negation.rb +41 -4
- data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
- data/lib/rubocop/cop/style/empty_literal.rb +6 -8
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
- data/lib/rubocop/cop/style/exponential_notation.rb +5 -5
- 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/hash_each_methods.rb +1 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +16 -7
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
- data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -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/ip_addresses.rb +1 -1
- 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/multiline_block_chain.rb +10 -1
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +17 -6
- data/lib/rubocop/cop/style/mutable_constant.rb +4 -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 -5
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +27 -0
- data/lib/rubocop/cop/style/next.rb +2 -2
- data/lib/rubocop/cop/style/non_nil_check.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -6
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +4 -10
- data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
- data/lib/rubocop/cop/style/redundant_conditional.rb +4 -3
- data/lib/rubocop/cop/style/redundant_exception.rb +14 -10
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +122 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +10 -8
- data/lib/rubocop/cop/style/redundant_percent_q.rb +3 -3
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +90 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +121 -0
- data/lib/rubocop/cop/style/redundant_self.rb +6 -9
- data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -6
- data/lib/rubocop/cop/style/sample.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/signal_exception.rb +1 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +2 -6
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +23 -2
- data/lib/rubocop/cop/style/symbol_array.rb +5 -5
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +3 -3
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +3 -3
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +13 -13
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +3 -3
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -3
- data/lib/rubocop/cop/style/trivial_accessors.rb +8 -7
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +18 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +2 -2
- data/lib/rubocop/cop/team.rb +141 -81
- data/lib/rubocop/cop/util.rb +3 -3
- data/lib/rubocop/cop/utils/format_string.rb +19 -2
- data/lib/rubocop/cop/variable_force.rb +3 -9
- data/lib/rubocop/cop/variable_force/branch.rb +1 -3
- data/lib/rubocop/cop/variable_force/variable.rb +2 -6
- data/lib/rubocop/ext/processed_source.rb +18 -0
- data/lib/rubocop/formatter/base_formatter.rb +0 -4
- data/lib/rubocop/formatter/disabled_config_formatter.rb +5 -13
- data/lib/rubocop/formatter/formatter_set.rb +2 -4
- data/lib/rubocop/formatter/junit_formatter.rb +14 -4
- data/lib/rubocop/magic_comment.rb +1 -1
- data/lib/rubocop/name_similarity.rb +7 -3
- data/lib/rubocop/options.rb +30 -15
- data/lib/rubocop/path_util.rb +2 -2
- data/lib/rubocop/platform.rb +1 -1
- data/lib/rubocop/rake_task.rb +6 -9
- data/lib/rubocop/remote_config.rb +1 -3
- data/lib/rubocop/result_cache.rb +5 -7
- data/lib/rubocop/rspec/cop_helper.rb +5 -28
- data/lib/rubocop/rspec/expect_offense.rb +60 -23
- data/lib/rubocop/rspec/shared_contexts.rb +55 -17
- data/lib/rubocop/runner.rb +42 -38
- data/lib/rubocop/target_finder.rb +2 -4
- data/lib/rubocop/target_ruby.rb +5 -2
- data/lib/rubocop/version.rb +5 -3
- metadata +60 -62
- data/lib/rubocop/ast/builder.rb +0 -85
- data/lib/rubocop/ast/node.rb +0 -637
- 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 -70
- data/lib/rubocop/ast/node/block_node.rb +0 -121
- data/lib/rubocop/ast/node/break_node.rb +0 -17
- data/lib/rubocop/ast/node/case_match_node.rb +0 -56
- 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 -269
- 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 -17
- 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 -202
- data/lib/rubocop/cop/mixin/classish_length.rb +0 -37
- data/lib/rubocop/node_pattern.rb +0 -887
- data/lib/rubocop/processed_source.rb +0 -213
- data/lib/rubocop/token.rb +0 -114
@@ -109,7 +109,7 @@ module RuboCop
|
|
109
109
|
|
110
110
|
def own_line_comment?(comment)
|
111
111
|
own_line = processed_source.lines[comment.loc.line - 1]
|
112
|
-
|
112
|
+
/\A\s*#/.match?(own_line)
|
113
113
|
end
|
114
114
|
|
115
115
|
def line_after_comment(comment)
|
@@ -129,11 +129,11 @@ module RuboCop
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def less_indented?(line)
|
132
|
-
|
132
|
+
/^\s*(end\b|[)}\]])/.match?(line)
|
133
133
|
end
|
134
134
|
|
135
135
|
def two_alternatives?(line)
|
136
|
-
|
136
|
+
/^\s*(else|elsif|when|rescue|ensure)\b/.match?(line)
|
137
137
|
end
|
138
138
|
end
|
139
139
|
end
|
@@ -99,9 +99,7 @@ module RuboCop
|
|
99
99
|
lambda do |corrector|
|
100
100
|
line = range_by_whole_lines(node.source_range)
|
101
101
|
|
102
|
-
unless previous_line_empty?(node.first_line)
|
103
|
-
corrector.insert_before(line, "\n")
|
104
|
-
end
|
102
|
+
corrector.insert_before(line, "\n") unless previous_line_empty?(node.first_line)
|
105
103
|
|
106
104
|
correct_next_line_if_denied_style(corrector, node, line)
|
107
105
|
end
|
@@ -120,9 +118,7 @@ module RuboCop
|
|
120
118
|
def correct_next_line_if_denied_style(corrector, node, line)
|
121
119
|
case style
|
122
120
|
when :around
|
123
|
-
unless next_line_empty?(node.last_line)
|
124
|
-
corrector.insert_after(line, "\n")
|
125
|
-
end
|
121
|
+
corrector.insert_after(line, "\n") unless next_line_empty?(node.last_line)
|
126
122
|
when :only_before
|
127
123
|
if next_line_empty?(node.last_line)
|
128
124
|
range = next_empty_line_range(node)
|
@@ -3,7 +3,9 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Layout
|
6
|
-
# Checks for a newline after attribute accessor.
|
6
|
+
# Checks for a newline after an attribute accessor or a group of them.
|
7
|
+
# `alias` syntax and `alias_method`, `public`, `protected`, and `private` methods are allowed
|
8
|
+
# by default. These are customizable with `AllowAliasSyntax` and `AllowedMethods` options.
|
7
9
|
#
|
8
10
|
# @example
|
9
11
|
# # bad
|
@@ -26,8 +28,41 @@ module RuboCop
|
|
26
28
|
# def do_something
|
27
29
|
# end
|
28
30
|
#
|
31
|
+
# @example AllowAliasSyntax: true (default)
|
32
|
+
# # good
|
33
|
+
# attr_accessor :foo
|
34
|
+
# alias :foo? :foo
|
35
|
+
#
|
36
|
+
# def do_something
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# @example AllowAliasSyntax: false
|
40
|
+
# # bad
|
41
|
+
# attr_accessor :foo
|
42
|
+
# alias :foo? :foo
|
43
|
+
#
|
44
|
+
# def do_something
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# # good
|
48
|
+
# attr_accessor :foo
|
49
|
+
#
|
50
|
+
# alias :foo? :foo
|
51
|
+
#
|
52
|
+
# def do_something
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# @example AllowedMethods: ['private']
|
56
|
+
# # good
|
57
|
+
# attr_accessor :foo
|
58
|
+
# private :foo
|
59
|
+
#
|
60
|
+
# def do_something
|
61
|
+
# end
|
62
|
+
#
|
29
63
|
class EmptyLinesAroundAttributeAccessor < Cop
|
30
64
|
include RangeHelp
|
65
|
+
include AllowedMethods
|
31
66
|
|
32
67
|
MSG = 'Add an empty line after attribute accessor.'
|
33
68
|
|
@@ -36,7 +71,7 @@ module RuboCop
|
|
36
71
|
return if next_line_empty?(node.last_line)
|
37
72
|
|
38
73
|
next_line_node = next_line_node(node)
|
39
|
-
return
|
74
|
+
return unless require_empty_line?(next_line_node)
|
40
75
|
|
41
76
|
add_offense(node)
|
42
77
|
end
|
@@ -55,12 +90,30 @@ module RuboCop
|
|
55
90
|
processed_source[line].blank?
|
56
91
|
end
|
57
92
|
|
93
|
+
def require_empty_line?(node)
|
94
|
+
return false unless node&.respond_to?(:type)
|
95
|
+
|
96
|
+
!allow_alias?(node) && !attribute_or_allowed_method?(node)
|
97
|
+
end
|
98
|
+
|
58
99
|
def next_line_node(node)
|
100
|
+
return if node.parent.if_type?
|
101
|
+
|
59
102
|
node.parent.children[node.sibling_index + 1]
|
60
103
|
end
|
61
104
|
|
62
|
-
def
|
63
|
-
|
105
|
+
def allow_alias?(node)
|
106
|
+
allow_alias_syntax? && node.alias_type?
|
107
|
+
end
|
108
|
+
|
109
|
+
def attribute_or_allowed_method?(node)
|
110
|
+
return false unless node.send_type?
|
111
|
+
|
112
|
+
node.attribute_accessor? || allowed_method?(node.method_name)
|
113
|
+
end
|
114
|
+
|
115
|
+
def allow_alias_syntax?
|
116
|
+
cop_config.fetch('AllowAliasSyntax', true)
|
64
117
|
end
|
65
118
|
end
|
66
119
|
end
|
@@ -65,7 +65,7 @@ module RuboCop
|
|
65
65
|
|
66
66
|
# If there is no LF on the last line, we don't care if there's no CR.
|
67
67
|
def unimportant_missing_cr?(index, last_line, line)
|
68
|
-
style == :crlf && index == last_line - 1 && line
|
68
|
+
style == :crlf && index == last_line - 1 && !/\n$/.match?(line)
|
69
69
|
end
|
70
70
|
|
71
71
|
def offense_message(line)
|
@@ -75,8 +75,8 @@ module RuboCop
|
|
75
75
|
style
|
76
76
|
end
|
77
77
|
case effective_style
|
78
|
-
when :lf then MSG_DETECTED if
|
79
|
-
else MSG_MISSING unless
|
78
|
+
when :lf then MSG_DETECTED if line.end_with?("\r", "\r\n")
|
79
|
+
else MSG_MISSING unless line.end_with?("\r\n")
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -2,13 +2,12 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
# rubocop:disable Layout/LineLength
|
6
5
|
module Layout
|
7
6
|
# This cop checks the indentation of the first argument in a method call.
|
8
7
|
# Arguments after the first one are checked by Layout/ArgumentAlignment,
|
9
8
|
# not by this cop.
|
10
9
|
#
|
11
|
-
# For indenting the first parameter of method
|
10
|
+
# For indenting the first parameter of method _definitions_, check out
|
12
11
|
# Layout/FirstParameterIndentation.
|
13
12
|
#
|
14
13
|
# @example
|
@@ -143,7 +142,6 @@ module RuboCop
|
|
143
142
|
# second_param
|
144
143
|
#
|
145
144
|
class FirstArgumentIndentation < Cop
|
146
|
-
# rubocop:enable Layout/LineLength
|
147
145
|
include Alignment
|
148
146
|
include ConfigurableEnforcedStyle
|
149
147
|
include RangeHelp
|
@@ -170,7 +168,7 @@ module RuboCop
|
|
170
168
|
|
171
169
|
send_node = arg_node.parent
|
172
170
|
text = base_range(send_node, arg_node).source.strip
|
173
|
-
base = if text
|
171
|
+
base = if !/\n/.match?(text) && special_inner_call_indentation?(send_node)
|
174
172
|
"`#{text}`"
|
175
173
|
elsif comment_line?(text.lines.reverse_each.first)
|
176
174
|
'the start of the previous line (not counting the comment)'
|
@@ -243,6 +241,10 @@ module RuboCop
|
|
243
241
|
.select { |c| begins_its_line?(c.loc.expression) }
|
244
242
|
.map { |c| c.loc.line }
|
245
243
|
end
|
244
|
+
|
245
|
+
def on_new_investigation
|
246
|
+
@comment_lines = nil
|
247
|
+
end
|
246
248
|
end
|
247
249
|
end
|
248
250
|
end
|
@@ -125,9 +125,7 @@ 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
|
-
if /\S/.match?(right_bracket.source_line[0...right_bracket.column])
|
129
|
-
return
|
130
|
-
end
|
128
|
+
return if /\S/.match?(right_bracket.source_line[0...right_bracket.column])
|
131
129
|
|
132
130
|
expected_column = base_column(left_bracket, left_parenthesis)
|
133
131
|
@column_delta = expected_column - right_bracket.column
|
@@ -36,9 +36,7 @@ module RuboCop
|
|
36
36
|
# ...then each key/value pair is treated as a method 'argument'
|
37
37
|
# when determining where line breaks should appear.
|
38
38
|
if (last_arg = args.last)
|
39
|
-
if last_arg.hash_type? && !last_arg.braces?
|
40
|
-
args = args.concat(args.pop.children)
|
41
|
-
end
|
39
|
+
args = args.concat(args.pop.children) if last_arg.hash_type? && !last_arg.braces?
|
42
40
|
end
|
43
41
|
|
44
42
|
check_method_line_break(node, args)
|
@@ -7,9 +7,9 @@ module RuboCop
|
|
7
7
|
# definition. Parameters after the first one are checked by
|
8
8
|
# Layout/ParameterAlignment, not by this cop.
|
9
9
|
#
|
10
|
-
# For indenting the first argument of method
|
10
|
+
# For indenting the first argument of method _calls_, check out
|
11
11
|
# Layout/FirstArgumentIndentation, which supports options related to
|
12
|
-
# nesting that are irrelevant for method
|
12
|
+
# nesting that are irrelevant for method _definitions_.
|
13
13
|
#
|
14
14
|
# @example
|
15
15
|
#
|
@@ -7,16 +7,16 @@ module RuboCop
|
|
7
7
|
# literal are aligned according to configuration. The configuration
|
8
8
|
# options are:
|
9
9
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
10
|
+
# * key (left align keys, one space before hash rockets and values)
|
11
|
+
# * separator (align hash rockets and colons, right align keys)
|
12
|
+
# * table (left align keys, hash rockets, and values)
|
13
13
|
#
|
14
14
|
# The treatment of hashes passed as the last argument to a method call
|
15
15
|
# can also be configured. The options are:
|
16
16
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
17
|
+
# * always_inspect
|
18
|
+
# * always_ignore
|
19
|
+
# * ignore_implicit (without curly braces)
|
20
20
|
#
|
21
21
|
# Alternatively you can specify multiple allowed styles. That's done by
|
22
22
|
# passing a list of styles to EnforcedStyles.
|
@@ -200,7 +200,7 @@ module RuboCop
|
|
200
200
|
alias on_super on_send
|
201
201
|
alias on_yield on_send
|
202
202
|
|
203
|
-
def on_hash(node)
|
203
|
+
def on_hash(node) # rubocop:todo Metrics/CyclomaticComplexity
|
204
204
|
return if ignored_node?(node)
|
205
205
|
return if node.pairs.empty? || node.single_line?
|
206
206
|
|
@@ -219,8 +219,7 @@ module RuboCop
|
|
219
219
|
correct_node(node, delta)
|
220
220
|
end
|
221
221
|
|
222
|
-
attr_accessor :offences_by
|
223
|
-
attr_accessor :column_deltas
|
222
|
+
attr_accessor :offences_by, :column_deltas
|
224
223
|
|
225
224
|
private
|
226
225
|
|
@@ -98,13 +98,9 @@ module RuboCop
|
|
98
98
|
lambda do |corrector|
|
99
99
|
fix_closing_parenthesis(node, corrector)
|
100
100
|
|
101
|
-
if internal_trailing_comma?(node)
|
102
|
-
remove_internal_trailing_comma(node, corrector)
|
103
|
-
end
|
101
|
+
remove_internal_trailing_comma(node, corrector) if internal_trailing_comma?(node)
|
104
102
|
|
105
|
-
if external_trailing_comma?(node)
|
106
|
-
fix_external_trailing_comma(node, corrector)
|
107
|
-
end
|
103
|
+
fix_external_trailing_comma(node, corrector) if external_trailing_comma?(node)
|
108
104
|
end
|
109
105
|
end
|
110
106
|
|
@@ -194,7 +190,7 @@ module RuboCop
|
|
194
190
|
def safe_to_remove_line_containing_closing_paren?(node)
|
195
191
|
last_line = processed_source[node.loc.end.line - 1]
|
196
192
|
# Safe to remove if last line only contains `)`, `,`, and whitespace.
|
197
|
-
last_line.match(/^
|
193
|
+
last_line.match?(/^ *\) {0,20},{0,1} *$/)
|
198
194
|
end
|
199
195
|
|
200
196
|
def incorrect_parenthesis_removal_end(node)
|
@@ -5,66 +5,29 @@ module RuboCop
|
|
5
5
|
module Layout
|
6
6
|
# This cop checks the indentation of the here document bodies. The bodies
|
7
7
|
# are indented one step.
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# (e.g. ActiveSupport, Powerpack or Unindent).
|
11
|
-
# Note: When `Layout/LineLength`'s `AllowHeredoc` is false (not default),
|
8
|
+
#
|
9
|
+
# Note: When ``Layout/LineLength``'s `AllowHeredoc` is false (not default),
|
12
10
|
# this cop does not add any offenses for long here documents to
|
13
11
|
# avoid `Layout/LineLength`'s offenses.
|
14
12
|
#
|
15
|
-
# @example
|
13
|
+
# @example
|
16
14
|
# # bad
|
17
15
|
# <<-RUBY
|
18
16
|
# something
|
19
17
|
# RUBY
|
20
18
|
#
|
21
19
|
# # good
|
22
|
-
# # When EnforcedStyle is squiggly, bad code is auto-corrected to the
|
23
|
-
# # following code.
|
24
20
|
# <<~RUBY
|
25
21
|
# something
|
26
22
|
# RUBY
|
27
23
|
#
|
28
|
-
# @example EnforcedStyle: active_support
|
29
|
-
# # good
|
30
|
-
# # When EnforcedStyle is active_support, bad code is auto-corrected to
|
31
|
-
# # the following code.
|
32
|
-
# <<-RUBY.strip_heredoc
|
33
|
-
# something
|
34
|
-
# RUBY
|
35
|
-
#
|
36
|
-
# @example EnforcedStyle: powerpack
|
37
|
-
# # good
|
38
|
-
# # When EnforcedStyle is powerpack, bad code is auto-corrected to
|
39
|
-
# # the following code.
|
40
|
-
# <<-RUBY.strip_indent
|
41
|
-
# something
|
42
|
-
# RUBY
|
43
|
-
#
|
44
|
-
# @example EnforcedStyle: unindent
|
45
|
-
# # good
|
46
|
-
# # When EnforcedStyle is unindent, bad code is auto-corrected to
|
47
|
-
# # the following code.
|
48
|
-
# <<-RUBY.unindent
|
49
|
-
# something
|
50
|
-
# RUBY
|
51
24
|
#
|
52
25
|
class HeredocIndentation < Cop
|
53
26
|
include Heredoc
|
54
|
-
include ConfigurableEnforcedStyle
|
55
27
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
RUBY23_WIDTH_MSG = 'Use %<indentation_width>d spaces for '\
|
60
|
-
'indentation in a heredoc.'
|
61
|
-
LIBRARY_MSG = 'Use %<indentation_width>d spaces for indentation in a ' \
|
62
|
-
'heredoc by using %<method>s.'
|
63
|
-
STRIP_METHODS = {
|
64
|
-
unindent: 'unindent',
|
65
|
-
active_support: 'strip_heredoc',
|
66
|
-
powerpack: 'strip_indent'
|
67
|
-
}.freeze
|
28
|
+
TYPE_MSG = 'Use %<indentation_width>d spaces for indentation in a ' \
|
29
|
+
'heredoc by using `<<~` instead of `%<current_indent_type>s`.'
|
30
|
+
WIDTH_MSG = 'Use %<indentation_width>d spaces for indentation in a heredoc.'
|
68
31
|
|
69
32
|
def on_heredoc(node)
|
70
33
|
body = heredoc_body(node)
|
@@ -85,59 +48,38 @@ module RuboCop
|
|
85
48
|
end
|
86
49
|
|
87
50
|
def autocorrect(node)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
correct_by_library(node)
|
51
|
+
lambda do |corrector|
|
52
|
+
if heredoc_indent_type(node) == '~'
|
53
|
+
adjust_squiggly(corrector, node)
|
54
|
+
else
|
55
|
+
adjust_minus(corrector, node)
|
56
|
+
end
|
95
57
|
end
|
96
58
|
end
|
97
59
|
|
98
60
|
private
|
99
61
|
|
100
62
|
def message(node)
|
101
|
-
|
102
|
-
when :squiggly
|
103
|
-
current_indent_type = "<<#{heredoc_indent_type(node)}"
|
104
|
-
ruby23_message(indentation_width, current_indent_type)
|
105
|
-
when nil
|
106
|
-
method = "some library(e.g. ActiveSupport's `String#strip_heredoc`)"
|
107
|
-
library_message(indentation_width, method)
|
108
|
-
else
|
109
|
-
method = "`String##{STRIP_METHODS[style]}`"
|
110
|
-
library_message(indentation_width, method)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def library_message(indentation_width, method)
|
115
|
-
format(
|
116
|
-
LIBRARY_MSG,
|
117
|
-
indentation_width: indentation_width,
|
118
|
-
method: method
|
119
|
-
)
|
120
|
-
end
|
63
|
+
current_indent_type = "<<#{heredoc_indent_type(node)}"
|
121
64
|
|
122
|
-
def ruby23_message(indentation_width, current_indent_type)
|
123
65
|
if current_indent_type == '<<~'
|
124
|
-
|
66
|
+
width_message(indentation_width)
|
125
67
|
else
|
126
|
-
|
68
|
+
type_message(indentation_width, current_indent_type)
|
127
69
|
end
|
128
70
|
end
|
129
71
|
|
130
|
-
def
|
72
|
+
def type_message(indentation_width, current_indent_type)
|
131
73
|
format(
|
132
|
-
|
74
|
+
TYPE_MSG,
|
133
75
|
indentation_width: indentation_width,
|
134
76
|
current_indent_type: current_indent_type
|
135
77
|
)
|
136
78
|
end
|
137
79
|
|
138
|
-
def
|
80
|
+
def width_message(indentation_width)
|
139
81
|
format(
|
140
|
-
|
82
|
+
WIDTH_MSG,
|
141
83
|
indentation_width: indentation_width
|
142
84
|
)
|
143
85
|
end
|
@@ -166,16 +108,6 @@ module RuboCop
|
|
166
108
|
config.for_cop('Layout/LineLength')['Max']
|
167
109
|
end
|
168
110
|
|
169
|
-
def correct_by_squiggly(node)
|
170
|
-
lambda do |corrector|
|
171
|
-
if heredoc_indent_type(node) == '~'
|
172
|
-
adjust_squiggly(corrector, node)
|
173
|
-
else
|
174
|
-
adjust_minus(corrector, node)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
111
|
def adjust_squiggly(corrector, node)
|
180
112
|
corrector.replace(node.loc.heredoc_body, indented_body(node))
|
181
113
|
corrector.replace(node.loc.heredoc_end, indented_end(node))
|
@@ -187,21 +119,6 @@ module RuboCop
|
|
187
119
|
corrector.replace(node, corrected)
|
188
120
|
end
|
189
121
|
|
190
|
-
def correct_by_library(node)
|
191
|
-
lambda do |corrector|
|
192
|
-
corrector.replace(node.loc.heredoc_body, indented_body(node))
|
193
|
-
corrected = ".#{STRIP_METHODS[style]}"
|
194
|
-
corrector.insert_after(node, corrected)
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
def check_style!
|
199
|
-
return if style
|
200
|
-
|
201
|
-
raise Warning, "Auto-correction does not work for #{cop_name}. " \
|
202
|
-
'Please configure EnforcedStyle.'
|
203
|
-
end
|
204
|
-
|
205
122
|
def indented_body(node)
|
206
123
|
body = heredoc_body(node)
|
207
124
|
body_indent_level = indent_level(body)
|
@@ -230,7 +147,7 @@ module RuboCop
|
|
230
147
|
def indent_level(str)
|
231
148
|
indentations = str.lines
|
232
149
|
.map { |line| line[/^\s*/] }
|
233
|
-
.reject { |line| line
|
150
|
+
.reject { |line| line.end_with?("\n") }
|
234
151
|
indentations.empty? ? 0 : indentations.min_by(&:size).size
|
235
152
|
end
|
236
153
|
|