rubocop 1.9.0 → 1.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -14
- data/assets/output.html.erb +1 -1
- data/config/default.yml +70 -17
- data/config/obsoletion.yml +4 -0
- data/lib/rubocop.rb +5 -0
- data/lib/rubocop/cli/command/execute_runner.rb +1 -1
- data/lib/rubocop/cli/command/suggest_extensions.rb +3 -2
- data/lib/rubocop/comment_config.rb +43 -94
- data/lib/rubocop/config.rb +4 -1
- data/lib/rubocop/cop/base.rb +1 -0
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -0
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -0
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +3 -6
- data/lib/rubocop/cop/exclude_limit.rb +26 -0
- data/lib/rubocop/cop/gemspec/date_assignment.rb +57 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -0
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -0
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +2 -0
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +2 -0
- data/lib/rubocop/cop/generator.rb +2 -2
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +2 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +151 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +2 -0
- data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +3 -0
- data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +4 -0
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +11 -8
- data/lib/rubocop/cop/layout/argument_alignment.rb +6 -5
- data/lib/rubocop/cop/layout/array_alignment.rb +7 -6
- data/lib/rubocop/cop/layout/assignment_indentation.rb +6 -3
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/block_end_newline.rb +4 -8
- data/lib/rubocop/cop/layout/class_structure.rb +1 -0
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +14 -15
- data/lib/rubocop/cop/layout/comment_indentation.rb +16 -16
- data/lib/rubocop/cop/layout/else_alignment.rb +9 -6
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +20 -3
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +37 -17
- data/lib/rubocop/cop/layout/extra_spacing.rb +2 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +27 -7
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +9 -6
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +22 -15
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +6 -5
- data/lib/rubocop/cop/layout/indentation_consistency.rb +9 -6
- data/lib/rubocop/cop/layout/indentation_style.rb +27 -30
- data/lib/rubocop/cop/layout/indentation_width.rb +20 -9
- data/lib/rubocop/cop/layout/line_length.rb +2 -1
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +26 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +18 -5
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +10 -5
- data/lib/rubocop/cop/layout/parameter_alignment.rb +6 -5
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_brackets.rb +9 -4
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -0
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +2 -0
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -0
- data/lib/rubocop/cop/lint/debugger.rb +60 -14
- data/lib/rubocop/cop/lint/deprecated_constants.rb +5 -0
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +14 -4
- data/lib/rubocop/cop/lint/duplicate_branch.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +3 -0
- data/lib/rubocop/cop/lint/duplicate_require.rb +3 -2
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
- data/lib/rubocop/cop/lint/else_layout.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -0
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -0
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +1 -0
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -0
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -0
- data/lib/rubocop/cop/lint/multiple_comparison.rb +5 -4
- data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -0
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -0
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +7 -0
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -0
- data/lib/rubocop/cop/lint/number_conversion.rb +11 -2
- data/lib/rubocop/cop/lint/raise_exception.rb +2 -0
- data/lib/rubocop/cop/lint/rand_one.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -2
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +7 -3
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -0
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -0
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -0
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -0
- data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
- data/lib/rubocop/cop/lint/suppressed_exception.rb +44 -1
- data/lib/rubocop/cop/lint/symbol_conversion.rb +91 -3
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +3 -0
- data/lib/rubocop/cop/lint/unified_integer.rb +1 -0
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +5 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
- data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -0
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +1 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -0
- data/lib/rubocop/cop/lint/useless_times.rb +3 -0
- data/lib/rubocop/cop/message_annotator.rb +4 -1
- data/lib/rubocop/cop/metrics/block_nesting.rb +2 -2
- data/lib/rubocop/cop/metrics/module_length.rb +1 -0
- data/lib/rubocop/cop/metrics/parameter_lists.rb +6 -2
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +6 -4
- data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +2 -0
- data/lib/rubocop/cop/mixin/alignment.rb +10 -3
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +3 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +5 -1
- data/lib/rubocop/cop/mixin/configurable_max.rb +1 -0
- data/lib/rubocop/cop/mixin/def_node.rb +1 -0
- data/lib/rubocop/cop/mixin/documentation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -0
- data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -0
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -0
- data/lib/rubocop/cop/mixin/line_length_help.rb +11 -6
- data/lib/rubocop/cop/mixin/method_complexity.rb +4 -1
- data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +3 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +4 -23
- data/lib/rubocop/cop/mixin/negative_conditional.rb +3 -0
- data/lib/rubocop/cop/mixin/preferred_delimiters.rb +3 -3
- data/lib/rubocop/cop/mixin/rational_literal.rb +1 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +5 -0
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +4 -6
- data/lib/rubocop/cop/mixin/visibility_help.rb +1 -0
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -0
- data/lib/rubocop/cop/naming/constant_name.rb +2 -0
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +6 -0
- data/lib/rubocop/cop/naming/method_name.rb +3 -0
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -0
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -0
- data/lib/rubocop/cop/registry.rb +10 -1
- data/lib/rubocop/cop/security/eval.rb +1 -0
- data/lib/rubocop/cop/security/json_load.rb +1 -0
- data/lib/rubocop/cop/security/marshal_load.rb +1 -0
- data/lib/rubocop/cop/security/open.rb +1 -0
- data/lib/rubocop/cop/security/yaml_load.rb +1 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +3 -2
- data/lib/rubocop/cop/style/alias.rb +1 -0
- data/lib/rubocop/cop/style/and_or.rb +3 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -0
- data/lib/rubocop/cop/style/array_coercion.rb +2 -0
- data/lib/rubocop/cop/style/array_join.rb +1 -0
- data/lib/rubocop/cop/style/attr.rb +1 -0
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +59 -71
- data/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb +62 -0
- data/lib/rubocop/cop/style/case_equality.rb +2 -1
- data/lib/rubocop/cop/style/case_like_if.rb +15 -4
- data/lib/rubocop/cop/style/class_equality_comparison.rb +3 -0
- data/lib/rubocop/cop/style/collection_compact.rb +2 -0
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -0
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +10 -10
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -0
- data/lib/rubocop/cop/style/constant_visibility.rb +28 -0
- data/lib/rubocop/cop/style/date_time.rb +3 -0
- data/lib/rubocop/cop/style/dir.rb +1 -0
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
- data/lib/rubocop/cop/style/documentation.rb +30 -3
- data/lib/rubocop/cop/style/documentation_method.rb +1 -0
- data/lib/rubocop/cop/style/double_negation.rb +3 -2
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -0
- data/lib/rubocop/cop/style/each_with_object.rb +1 -0
- data/lib/rubocop/cop/style/empty_literal.rb +9 -0
- data/lib/rubocop/cop/style/endless_method.rb +1 -0
- data/lib/rubocop/cop/style/eval_with_location.rb +90 -28
- data/lib/rubocop/cop/style/even_odd.rb +1 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -0
- data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -1
- data/lib/rubocop/cop/style/exponential_notation.rb +6 -7
- data/lib/rubocop/cop/style/float_division.rb +4 -0
- data/lib/rubocop/cop/style/format_string.rb +2 -0
- data/lib/rubocop/cop/style/format_string_token.rb +1 -0
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +0 -3
- data/lib/rubocop/cop/style/global_std_stream.rb +1 -0
- data/lib/rubocop/cop/style/hash_conversion.rb +108 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +1 -0
- data/lib/rubocop/cop/style/hash_except.rb +1 -0
- data/lib/rubocop/cop/style/hash_like_case.rb +1 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +16 -15
- data/lib/rubocop/cop/style/hash_transform_keys.rb +4 -0
- data/lib/rubocop/cop/style/hash_transform_values.rb +4 -0
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +37 -11
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +2 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +46 -2
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +19 -3
- data/lib/rubocop/cop/style/min_max.rb +1 -0
- data/lib/rubocop/cop/style/mixin_usage.rb +2 -0
- data/lib/rubocop/cop/style/module_function.rb +5 -0
- data/lib/rubocop/cop/style/multiline_method_signature.rb +10 -3
- data/lib/rubocop/cop/style/multiple_comparison.rb +21 -2
- data/lib/rubocop/cop/style/mutable_constant.rb +3 -0
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +16 -2
- data/lib/rubocop/cop/style/nil_comparison.rb +6 -1
- data/lib/rubocop/cop/style/nil_lambda.rb +1 -0
- data/lib/rubocop/cop/style/non_nil_check.rb +7 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +6 -9
- data/lib/rubocop/cop/style/numeric_predicate.rb +4 -1
- data/lib/rubocop/cop/style/option_hash.rb +1 -0
- data/lib/rubocop/cop/style/or_assignment.rb +2 -0
- data/lib/rubocop/cop/style/parallel_assignment.rb +6 -0
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -0
- data/lib/rubocop/cop/style/proc.rb +1 -0
- data/lib/rubocop/cop/style/random_with_offset.rb +5 -0
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +44 -4
- data/lib/rubocop/cop/style/redundant_conditional.rb +2 -0
- data/lib/rubocop/cop/style/redundant_exception.rb +2 -0
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +2 -0
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +13 -0
- data/lib/rubocop/cop/style/redundant_return.rb +4 -0
- data/lib/rubocop/cop/style/redundant_self.rb +7 -3
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -0
- data/lib/rubocop/cop/style/redundant_sort.rb +1 -0
- data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -0
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/style/rescue_modifier.rb +17 -14
- data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -0
- data/lib/rubocop/cop/style/return_nil.rb +6 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -0
- data/lib/rubocop/cop/style/sample.rb +1 -0
- data/lib/rubocop/cop/style/signal_exception.rb +3 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
- data/lib/rubocop/cop/style/single_line_methods.rb +4 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -0
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +20 -4
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -3
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -0
- data/lib/rubocop/cop/style/string_chars.rb +38 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +1 -0
- data/lib/rubocop/cop/style/string_hash_keys.rb +2 -0
- data/lib/rubocop/cop/style/strip.rb +1 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +3 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +25 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -0
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +5 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -0
- data/lib/rubocop/cop/style/unless_logical_operators.rb +105 -0
- data/lib/rubocop/cop/style/unpack_first.rb +1 -0
- data/lib/rubocop/cop/style/yoda_condition.rb +1 -0
- data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -0
- data/lib/rubocop/cop/util.rb +4 -1
- data/lib/rubocop/directive_comment.rb +69 -9
- data/lib/rubocop/ext/regexp_parser.rb +3 -6
- data/lib/rubocop/formatter/clang_style_formatter.rb +4 -2
- data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +2 -1
- data/lib/rubocop/formatter/tap_formatter.rb +4 -2
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
- data/lib/rubocop/magic_comment.rb +1 -1
- data/lib/rubocop/name_similarity.rb +1 -1
- data/lib/rubocop/target_finder.rb +1 -0
- data/lib/rubocop/target_ruby.rb +21 -13
- data/lib/rubocop/version.rb +1 -1
- metadata +14 -7
@@ -34,10 +34,12 @@ module RuboCop
|
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
|
+
# @!method node_type_check(node)
|
37
38
|
def_node_matcher :node_type_check, <<~PATTERN
|
38
39
|
(send nil? :add_offense $_node $hash)
|
39
40
|
PATTERN
|
40
41
|
|
42
|
+
# @!method offending_location_argument(node)
|
41
43
|
def_node_matcher :offending_location_argument, <<~PATTERN
|
42
44
|
(pair (sym :location) $(send (send $_node :loc) $_keyword))
|
43
45
|
PATTERN
|
@@ -23,6 +23,7 @@ module RuboCop
|
|
23
23
|
MSG = 'Redundant location argument to `#add_offense`.'
|
24
24
|
RESTRICT_ON_SEND = %i[add_offense].freeze
|
25
25
|
|
26
|
+
# @!method redundant_location_argument(node)
|
26
27
|
def_node_matcher :redundant_location_argument, <<~PATTERN
|
27
28
|
(send nil? :add_offense _
|
28
29
|
(hash <$(pair (sym :location) (sym :expression)) ...>)
|
@@ -26,16 +26,19 @@ module RuboCop
|
|
26
26
|
MSG = 'Redundant message argument to `#add_offense`.'
|
27
27
|
RESTRICT_ON_SEND = %i[add_offense].freeze
|
28
28
|
|
29
|
+
# @!method node_type_check(node)
|
29
30
|
def_node_matcher :node_type_check, <<~PATTERN
|
30
31
|
(send nil? :add_offense $_node $hash)
|
31
32
|
PATTERN
|
32
33
|
|
34
|
+
# @!method redundant_message_argument(node)
|
33
35
|
def_node_matcher :redundant_message_argument, <<~PATTERN
|
34
36
|
(pair
|
35
37
|
(sym :message)
|
36
38
|
${(const nil? :MSG) (send nil? :message) (send nil? :message _)})
|
37
39
|
PATTERN
|
38
40
|
|
41
|
+
# @!method message_method_call(node)
|
39
42
|
def_node_matcher :message_method_call, '(send nil? :message $_node)'
|
40
43
|
|
41
44
|
def on_send(node)
|
@@ -67,18 +67,22 @@ module RuboCop
|
|
67
67
|
no_acceptable_style! style_detected
|
68
68
|
].freeze
|
69
69
|
|
70
|
+
# @!method correct_style_detected_check(node)
|
70
71
|
def_node_matcher :correct_style_detected_check, <<~PATTERN
|
71
72
|
(send nil? :correct_style_detected)
|
72
73
|
PATTERN
|
73
74
|
|
75
|
+
# @!method negative_style_detected_method_check(node)
|
74
76
|
def_node_matcher :negative_style_detected_method_check, <<~PATTERN
|
75
77
|
(send nil? /(?:opposite|unexpected|ambiguous|unrecognized)_style_detected|conflicting_styles_detected/ ...)
|
76
78
|
PATTERN
|
77
79
|
|
80
|
+
# @!method no_acceptable_style_check(node)
|
78
81
|
def_node_matcher :no_acceptable_style_check, <<~PATTERN
|
79
82
|
(send nil? :no_acceptable_style!)
|
80
83
|
PATTERN
|
81
84
|
|
85
|
+
# @!method style_detected_check(node)
|
82
86
|
def_node_matcher :style_detected_check, <<~PATTERN
|
83
87
|
(send nil? :style_detected ...)
|
84
88
|
PATTERN
|
@@ -16,10 +16,12 @@ module RuboCop
|
|
16
16
|
class UselessMessageAssertion < Base
|
17
17
|
MSG = 'Do not specify cop behavior using `described_class::MSG`.'
|
18
18
|
|
19
|
+
# @!method described_class_msg(node)
|
19
20
|
def_node_search :described_class_msg, <<~PATTERN
|
20
21
|
(const (send nil? :described_class) :MSG)
|
21
22
|
PATTERN
|
22
23
|
|
24
|
+
# @!method rspec_expectation_on_msg?(node)
|
23
25
|
def_node_matcher :rspec_expectation_on_msg?, <<~PATTERN
|
24
26
|
(send (send nil? :expect #contains_described_class_msg?) :to ...)
|
25
27
|
PATTERN
|
@@ -32,10 +32,11 @@ module RuboCop
|
|
32
32
|
# private
|
33
33
|
# def smooth; end
|
34
34
|
# end
|
35
|
-
class AccessModifierIndentation <
|
35
|
+
class AccessModifierIndentation < Base
|
36
36
|
include Alignment
|
37
37
|
include ConfigurableEnforcedStyle
|
38
38
|
include RangeHelp
|
39
|
+
extend AutoCorrector
|
39
40
|
|
40
41
|
MSG = '%<style>s access modifiers like `%<node>s`.'
|
41
42
|
|
@@ -48,12 +49,12 @@ module RuboCop
|
|
48
49
|
alias on_module on_class
|
49
50
|
alias on_block on_class
|
50
51
|
|
51
|
-
def autocorrect(node)
|
52
|
-
AlignmentCorrector.correct(processed_source, node, @column_delta)
|
53
|
-
end
|
54
|
-
|
55
52
|
private
|
56
53
|
|
54
|
+
def autocorrect(corrector, node)
|
55
|
+
AlignmentCorrector.correct(corrector, processed_source, node, @column_delta)
|
56
|
+
end
|
57
|
+
|
57
58
|
def check_body(body, node)
|
58
59
|
modifiers = body.each_child_node(:send)
|
59
60
|
.select(&:bare_access_modifier?)
|
@@ -69,18 +70,20 @@ module RuboCop
|
|
69
70
|
if @column_delta.zero?
|
70
71
|
correct_style_detected
|
71
72
|
else
|
72
|
-
add_offense(send_node) do
|
73
|
+
add_offense(send_node) do |corrector|
|
73
74
|
if offset == unexpected_indent_offset
|
74
75
|
opposite_style_detected
|
75
76
|
else
|
76
77
|
unrecognized_style_detected
|
77
78
|
end
|
79
|
+
|
80
|
+
autocorrect(corrector, send_node)
|
78
81
|
end
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
82
|
-
def message(
|
83
|
-
format(MSG, style: style.capitalize, node:
|
85
|
+
def message(range)
|
86
|
+
format(MSG, style: style.capitalize, node: range.source)
|
84
87
|
end
|
85
88
|
|
86
89
|
def expected_indent_offset
|
@@ -37,8 +37,9 @@ module RuboCop
|
|
37
37
|
#
|
38
38
|
# foo :bar,
|
39
39
|
# :baz
|
40
|
-
class ArgumentAlignment <
|
40
|
+
class ArgumentAlignment < Base
|
41
41
|
include Alignment
|
42
|
+
extend AutoCorrector
|
42
43
|
|
43
44
|
ALIGN_PARAMS_MSG = 'Align the arguments of a method call if ' \
|
44
45
|
'they span more than one line.'
|
@@ -54,12 +55,12 @@ module RuboCop
|
|
54
55
|
end
|
55
56
|
alias on_csend on_send
|
56
57
|
|
57
|
-
def autocorrect(node)
|
58
|
-
AlignmentCorrector.correct(processed_source, node, column_delta)
|
59
|
-
end
|
60
|
-
|
61
58
|
private
|
62
59
|
|
60
|
+
def autocorrect(corrector, node)
|
61
|
+
AlignmentCorrector.correct(corrector, processed_source, node, column_delta)
|
62
|
+
end
|
63
|
+
|
63
64
|
def message(_node)
|
64
65
|
fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG
|
65
66
|
end
|
@@ -33,8 +33,9 @@ module RuboCop
|
|
33
33
|
#
|
34
34
|
# array = [1, 2, 3,
|
35
35
|
# 4, 5, 6]
|
36
|
-
class ArrayAlignment <
|
36
|
+
class ArrayAlignment < Base
|
37
37
|
include Alignment
|
38
|
+
extend AutoCorrector
|
38
39
|
|
39
40
|
ALIGN_ELEMENTS_MSG = 'Align the elements of an array literal ' \
|
40
41
|
'if they span more than one line.'
|
@@ -49,13 +50,13 @@ module RuboCop
|
|
49
50
|
check_alignment(node.children, base_column(node, node.children))
|
50
51
|
end
|
51
52
|
|
52
|
-
def autocorrect(node)
|
53
|
-
AlignmentCorrector.correct(processed_source, node, column_delta)
|
54
|
-
end
|
55
|
-
|
56
53
|
private
|
57
54
|
|
58
|
-
def
|
55
|
+
def autocorrect(corrector, node)
|
56
|
+
AlignmentCorrector.correct(corrector, processed_source, node, column_delta)
|
57
|
+
end
|
58
|
+
|
59
|
+
def message(_range)
|
59
60
|
fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_ELEMENTS_MSG
|
60
61
|
end
|
61
62
|
|
@@ -21,13 +21,16 @@ module RuboCop
|
|
21
21
|
#
|
22
22
|
# The indentation of the remaining lines can be corrected with
|
23
23
|
# other cops such as `IndentationConsistency` and `EndAlignment`.
|
24
|
-
class AssignmentIndentation <
|
24
|
+
class AssignmentIndentation < Base
|
25
25
|
include CheckAssignment
|
26
26
|
include Alignment
|
27
|
+
extend AutoCorrector
|
27
28
|
|
28
29
|
MSG = 'Indent the first line of the right-hand-side of a ' \
|
29
30
|
'multi-line assignment.'
|
30
31
|
|
32
|
+
private
|
33
|
+
|
31
34
|
def check_assignment(node, rhs)
|
32
35
|
return unless rhs
|
33
36
|
return unless node.loc.operator
|
@@ -37,8 +40,8 @@ module RuboCop
|
|
37
40
|
check_alignment([rhs], base + configured_indentation_width)
|
38
41
|
end
|
39
42
|
|
40
|
-
def autocorrect(node)
|
41
|
-
AlignmentCorrector.correct(processed_source, node, column_delta)
|
43
|
+
def autocorrect(corrector, node)
|
44
|
+
AlignmentCorrector.correct(corrector, processed_source, node, column_delta)
|
42
45
|
end
|
43
46
|
|
44
47
|
def leftmost_multiple_assignment(node)
|
@@ -24,8 +24,9 @@ module RuboCop
|
|
24
24
|
# blah { |i|
|
25
25
|
# foo(i)
|
26
26
|
# }
|
27
|
-
class BlockEndNewline <
|
27
|
+
class BlockEndNewline < Base
|
28
28
|
include Alignment
|
29
|
+
extend AutoCorrector
|
29
30
|
|
30
31
|
MSG = 'Expression at %<line>d, %<column>d should be on its own line.'
|
31
32
|
|
@@ -35,13 +36,8 @@ module RuboCop
|
|
35
36
|
# If the end is on its own line, there is no offense
|
36
37
|
return if begins_its_line?(node.loc.end)
|
37
38
|
|
38
|
-
add_offense(node,
|
39
|
-
|
40
|
-
|
41
|
-
def autocorrect(node)
|
42
|
-
lambda do |corrector|
|
43
|
-
corrector.replace(delimiter_range(node),
|
44
|
-
"\n#{node.loc.end.source}#{offset(node)}")
|
39
|
+
add_offense(node.loc.end, message: message(node)) do |corrector|
|
40
|
+
corrector.replace(delimiter_range(node), "\n#{node.loc.end.source}#{offset(node)}")
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
@@ -68,8 +68,9 @@ module RuboCop
|
|
68
68
|
# )
|
69
69
|
#
|
70
70
|
#
|
71
|
-
class ClosingParenthesisIndentation <
|
71
|
+
class ClosingParenthesisIndentation < Base
|
72
72
|
include Alignment
|
73
|
+
extend AutoCorrector
|
73
74
|
|
74
75
|
MSG_INDENT = 'Indent `)` to column %<expected>d (not %<actual>d)'
|
75
76
|
|
@@ -89,12 +90,12 @@ module RuboCop
|
|
89
90
|
end
|
90
91
|
alias on_defs on_def
|
91
92
|
|
92
|
-
def autocorrect(node)
|
93
|
-
AlignmentCorrector.correct(processed_source, node, @column_delta)
|
94
|
-
end
|
95
|
-
|
96
93
|
private
|
97
94
|
|
95
|
+
def autocorrect(corrector, node)
|
96
|
+
AlignmentCorrector.correct(corrector, processed_source, node, @column_delta)
|
97
|
+
end
|
98
|
+
|
98
99
|
def check(node, elements)
|
99
100
|
if elements.empty?
|
100
101
|
check_for_no_elements(node)
|
@@ -115,11 +116,10 @@ module RuboCop
|
|
115
116
|
|
116
117
|
return if @column_delta.zero?
|
117
118
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
right_paren))
|
119
|
+
message = message(correct_column, left_paren, right_paren)
|
120
|
+
add_offense(right_paren, message: message) do |corrector|
|
121
|
+
autocorrect(corrector, right_paren)
|
122
|
+
end
|
123
123
|
end
|
124
124
|
|
125
125
|
def check_for_no_elements(node)
|
@@ -135,11 +135,10 @@ module RuboCop
|
|
135
135
|
# select the first one of candidates to determine a specification.
|
136
136
|
correct_column = candidates.first
|
137
137
|
@column_delta = correct_column - right_paren.column
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
right_paren))
|
138
|
+
message = message(correct_column, left_paren, right_paren)
|
139
|
+
add_offense(right_paren, message: message) do |corrector|
|
140
|
+
autocorrect(corrector, right_paren)
|
141
|
+
end
|
143
142
|
end
|
144
143
|
|
145
144
|
def expected_column(left_paren, elements)
|
@@ -32,29 +32,30 @@ module RuboCop
|
|
32
32
|
# true
|
33
33
|
# end
|
34
34
|
#
|
35
|
-
class CommentIndentation <
|
35
|
+
class CommentIndentation < Base
|
36
36
|
include Alignment
|
37
|
+
extend AutoCorrector
|
37
38
|
|
38
39
|
MSG = 'Incorrect indentation detected (column %<column>d ' \
|
39
40
|
'instead of %<correct_comment_indentation>d).'
|
40
41
|
|
41
|
-
def
|
42
|
+
def on_new_investigation
|
42
43
|
processed_source.comments.each { |comment| check(comment) }
|
43
44
|
end
|
44
45
|
|
45
|
-
def autocorrect(comment)
|
46
|
-
corrections = autocorrect_preceding_comments(comment) <<
|
47
|
-
autocorrect_one(comment)
|
48
|
-
->(corrector) { corrections.each { |corr| corr.call(corrector) } }
|
49
|
-
end
|
50
|
-
|
51
46
|
private
|
52
47
|
|
48
|
+
def autocorrect(corrector, comment)
|
49
|
+
autocorrect_preceding_comments(corrector, comment)
|
50
|
+
|
51
|
+
autocorrect_one(corrector, comment)
|
52
|
+
end
|
53
|
+
|
53
54
|
# Corrects all comment lines that occur immediately before the given
|
54
55
|
# comment and have the same indentation. This is to avoid a long chain
|
55
56
|
# of correcting, saving the file, parsing and inspecting again, and
|
56
57
|
# then correcting one more line, and so on.
|
57
|
-
def autocorrect_preceding_comments(comment)
|
58
|
+
def autocorrect_preceding_comments(corrector, comment)
|
58
59
|
comments = processed_source.comments
|
59
60
|
index = comments.index(comment)
|
60
61
|
|
@@ -62,7 +63,7 @@ module RuboCop
|
|
62
63
|
.reverse_each
|
63
64
|
.each_cons(2)
|
64
65
|
.take_while { |below, above| should_correct?(above, below) }
|
65
|
-
.map { |_, above| autocorrect_one(above) }
|
66
|
+
.map { |_, above| autocorrect_one(corrector, above) }
|
66
67
|
end
|
67
68
|
|
68
69
|
def should_correct?(preceding_comment, reference_comment)
|
@@ -71,8 +72,8 @@ module RuboCop
|
|
71
72
|
loc.line == ref_loc.line - 1 && loc.column == ref_loc.column
|
72
73
|
end
|
73
74
|
|
74
|
-
def autocorrect_one(comment)
|
75
|
-
AlignmentCorrector.correct(processed_source, comment, @column_delta)
|
75
|
+
def autocorrect_one(corrector, comment)
|
76
|
+
AlignmentCorrector.correct(corrector, processed_source, comment, @column_delta)
|
76
77
|
end
|
77
78
|
|
78
79
|
def check(comment)
|
@@ -93,10 +94,9 @@ module RuboCop
|
|
93
94
|
return if column == correct_comment_indentation
|
94
95
|
end
|
95
96
|
|
96
|
-
add_offense(
|
97
|
-
comment
|
98
|
-
|
99
|
-
)
|
97
|
+
add_offense(comment, message: message(column, correct_comment_indentation)) do |corrector|
|
98
|
+
autocorrect(corrector, comment)
|
99
|
+
end
|
100
100
|
end
|
101
101
|
|
102
102
|
def message(column, correct_comment_indentation)
|
@@ -29,10 +29,11 @@ module RuboCop
|
|
29
29
|
# else
|
30
30
|
# code
|
31
31
|
# end
|
32
|
-
class ElseAlignment <
|
32
|
+
class ElseAlignment < Base
|
33
33
|
include EndKeywordAlignment
|
34
34
|
include Alignment
|
35
35
|
include CheckAssignment
|
36
|
+
extend AutoCorrector
|
36
37
|
|
37
38
|
MSG = 'Align `%<else_range>s` with `%<base_range>s`.'
|
38
39
|
|
@@ -67,12 +68,12 @@ module RuboCop
|
|
67
68
|
)
|
68
69
|
end
|
69
70
|
|
70
|
-
def autocorrect(node)
|
71
|
-
AlignmentCorrector.correct(processed_source, node, column_delta)
|
72
|
-
end
|
73
|
-
|
74
71
|
private
|
75
72
|
|
73
|
+
def autocorrect(corrector, node)
|
74
|
+
AlignmentCorrector.correct(corrector, processed_source, node, column_delta)
|
75
|
+
end
|
76
|
+
|
76
77
|
def check_nested(node, base)
|
77
78
|
on_if(node, base)
|
78
79
|
ignore_node(node)
|
@@ -140,7 +141,9 @@ module RuboCop
|
|
140
141
|
else_range: else_range.source,
|
141
142
|
base_range: base_range.source[/^\S*/]
|
142
143
|
)
|
143
|
-
add_offense(else_range,
|
144
|
+
add_offense(else_range, message: message) do |corrector|
|
145
|
+
autocorrect(corrector, else_range)
|
146
|
+
end
|
144
147
|
end
|
145
148
|
|
146
149
|
def assignment_node(node)
|