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
@@ -24,6 +24,7 @@ module RuboCop
|
|
24
24
|
'`%<receiver>s.unpack(%<format>s)%<method>s`.'
|
25
25
|
RESTRICT_ON_SEND = %i[first [] slice at].freeze
|
26
26
|
|
27
|
+
# @!method unpack_and_first_element?(node)
|
27
28
|
def_node_matcher :unpack_and_first_element?, <<~PATTERN
|
28
29
|
{
|
29
30
|
(send $(send (...) :unpack $(...)) :first)
|
@@ -72,6 +72,7 @@ module RuboCop
|
|
72
72
|
|
73
73
|
PROGRAM_NAMES = %i[$0 $PROGRAM_NAME].freeze
|
74
74
|
|
75
|
+
# @!method file_constant_equal_program_name?(node)
|
75
76
|
def_node_matcher :file_constant_equal_program_name?, <<~PATTERN
|
76
77
|
(send #source_file_path_constant? {:== :!=} (gvar #program_name?))
|
77
78
|
PATTERN
|
@@ -71,6 +71,7 @@ module RuboCop
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
# @!method zero_length_predicate(node)
|
74
75
|
def_node_matcher :zero_length_predicate, <<~PATTERN
|
75
76
|
{(send (send (...) ${:length :size}) $:== (int $0))
|
76
77
|
(send (int $0) $:== (send (...) ${:length :size}))
|
@@ -78,6 +79,7 @@ module RuboCop
|
|
78
79
|
(send (int $1) $:> (send (...) ${:length :size}))}
|
79
80
|
PATTERN
|
80
81
|
|
82
|
+
# @!method nonzero_length_predicate(node)
|
81
83
|
def_node_matcher :nonzero_length_predicate, <<~PATTERN
|
82
84
|
{(send (send (...) ${:length :size}) ${:> :!=} (int $0))
|
83
85
|
(send (int $0) ${:< :!=} (send (...) ${:length :size}))}
|
@@ -90,6 +92,7 @@ module RuboCop
|
|
90
92
|
"!#{other_receiver(node).source}.empty?"
|
91
93
|
end
|
92
94
|
|
95
|
+
# @!method zero_length_receiver(node)
|
93
96
|
def_node_matcher :zero_length_receiver, <<~PATTERN
|
94
97
|
{(send (send $_ _) :== (int 0))
|
95
98
|
(send (int 0) :== (send $_ _))
|
@@ -97,6 +100,7 @@ module RuboCop
|
|
97
100
|
(send (int 1) :> (send $_ _))}
|
98
101
|
PATTERN
|
99
102
|
|
103
|
+
# @!method other_receiver(node)
|
100
104
|
def_node_matcher :other_receiver, <<~PATTERN
|
101
105
|
{(send (send $_ _) _ _)
|
102
106
|
(send _ _ (send $_ _))}
|
@@ -105,6 +109,7 @@ module RuboCop
|
|
105
109
|
# Some collection like objects in the Ruby standard library
|
106
110
|
# implement `#size`, but not `#empty`. We ignore those to
|
107
111
|
# reduce false positives.
|
112
|
+
# @!method non_polymorphic_collection?(node)
|
108
113
|
def_node_matcher :non_polymorphic_collection?, <<~PATTERN
|
109
114
|
{(send (send (send (const {nil? cbase} :File) :stat _) ...) ...)
|
110
115
|
(send (send (send (const {nil? cbase} {:Tempfile :StringIO}) {:new :open} ...) ...) ...)}
|
data/lib/rubocop/cop/util.rb
CHANGED
@@ -38,7 +38,10 @@ module RuboCop
|
|
38
38
|
elsif node.arguments.empty?
|
39
39
|
corrector.insert_after(node, '()')
|
40
40
|
else
|
41
|
-
|
41
|
+
args_begin = args_begin(node)
|
42
|
+
|
43
|
+
corrector.remove(args_begin)
|
44
|
+
corrector.insert_before(args_begin, '(')
|
42
45
|
corrector.insert_after(args_end(node), ')')
|
43
46
|
end
|
44
47
|
end
|
@@ -5,28 +5,88 @@ module RuboCop
|
|
5
5
|
# special `rubocop:disable` and `rubocop:enable` comment and exposes what
|
6
6
|
# cops it contains.
|
7
7
|
class DirectiveComment
|
8
|
-
|
8
|
+
# @api private
|
9
|
+
REDUNDANT_COP = 'Lint/RedundantCopDisableDirective'
|
10
|
+
# @api private
|
11
|
+
COP_NAME_PATTERN = '([A-Z]\w+/)*(?:[A-Z]\w+)'
|
12
|
+
# @api private
|
13
|
+
COP_NAMES_PATTERN = "(?:#{COP_NAME_PATTERN} , )*#{COP_NAME_PATTERN}"
|
14
|
+
# @api private
|
15
|
+
COPS_PATTERN = "(all|#{COP_NAMES_PATTERN})"
|
16
|
+
# @api private
|
17
|
+
DIRECTIVE_COMMENT_REGEXP = Regexp.new(
|
18
|
+
"# rubocop : ((?:disable|enable|todo))\\b #{COPS_PATTERN}"
|
19
|
+
.gsub(' ', '\s*')
|
20
|
+
)
|
21
|
+
|
22
|
+
def self.before_comment(line)
|
23
|
+
line.split(DIRECTIVE_COMMENT_REGEXP).first
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :comment, :mode, :cops
|
9
27
|
|
10
28
|
def initialize(comment)
|
11
29
|
@comment = comment
|
30
|
+
@mode, @cops = match_captures
|
12
31
|
end
|
13
32
|
|
14
|
-
#
|
15
|
-
def
|
16
|
-
|
17
|
-
return unless match
|
18
|
-
|
19
|
-
cops_string = match.captures[1]
|
20
|
-
cops_string.split(/,\s*/).uniq.sort
|
33
|
+
# Checks if this directive relates to single line
|
34
|
+
def single_line?
|
35
|
+
!self.class.before_comment(comment.text).empty?
|
21
36
|
end
|
22
37
|
|
23
38
|
# Checks if this directive contains all the given cop names
|
24
39
|
def match?(cop_names)
|
25
|
-
|
40
|
+
parsed_cop_names.uniq.sort == cop_names.uniq.sort
|
26
41
|
end
|
27
42
|
|
28
43
|
def range
|
29
44
|
comment.location.expression
|
30
45
|
end
|
46
|
+
|
47
|
+
# Returns match captures to directive comment pattern
|
48
|
+
def match_captures
|
49
|
+
@match_captures ||= comment.text.match(DIRECTIVE_COMMENT_REGEXP)&.captures
|
50
|
+
end
|
51
|
+
|
52
|
+
# Checks if this directive disables cops
|
53
|
+
def disabled?
|
54
|
+
%w[disable todo].include?(mode)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Checks if this directive enables cops
|
58
|
+
def enabled?
|
59
|
+
mode == 'enable'
|
60
|
+
end
|
61
|
+
|
62
|
+
# Checks if this directive enables all cops
|
63
|
+
def enabled_all?
|
64
|
+
!disabled? && all_cops?
|
65
|
+
end
|
66
|
+
|
67
|
+
# Checks if all cops specified in this directive
|
68
|
+
def all_cops?
|
69
|
+
cops == 'all'
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns array of specified in this directive cop names
|
73
|
+
def cop_names
|
74
|
+
@cop_names ||= all_cops? ? all_cop_names : parsed_cop_names
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns line number for directive
|
78
|
+
def line_number
|
79
|
+
comment.loc.expression.line
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def parsed_cop_names
|
85
|
+
(cops || '').split(/,\s*/)
|
86
|
+
end
|
87
|
+
|
88
|
+
def all_cop_names
|
89
|
+
Cop::Registry.global.names - [REDUNDANT_COP]
|
90
|
+
end
|
31
91
|
end
|
32
92
|
end
|
@@ -39,9 +39,8 @@ module RuboCop
|
|
39
39
|
|
40
40
|
# Shortcut to `loc.expression`
|
41
41
|
def expression
|
42
|
-
|
43
|
-
|
44
|
-
end
|
42
|
+
end_pos = start_index + full_length
|
43
|
+
@expression ||= origin.adjust(begin_pos: start_index, end_pos: end_pos)
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
@@ -60,9 +59,7 @@ module RuboCop
|
|
60
59
|
#
|
61
60
|
# Please open issue if you need other locations
|
62
61
|
def loc
|
63
|
-
@loc ||=
|
64
|
-
Map.new(expression, **build_location)
|
65
|
-
end
|
62
|
+
@loc ||= Map.new(expression, **build_location)
|
66
63
|
end
|
67
64
|
|
68
65
|
private
|
@@ -49,8 +49,10 @@ module RuboCop
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def report_highlighted_area(highlighted_area)
|
52
|
-
|
53
|
-
|
52
|
+
space_area = highlighted_area.source_buffer.slice(0...highlighted_area.begin_pos)
|
53
|
+
source_area = highlighted_area.source
|
54
|
+
output.puts("#{' ' * Unicode::DisplayWidth.of(space_area)}" \
|
55
|
+
"#{'^' * Unicode::DisplayWidth.of(source_area)}")
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
@@ -13,6 +13,7 @@ module RuboCop
|
|
13
13
|
include PathUtil
|
14
14
|
|
15
15
|
COLOR_FOR_SEVERITY = {
|
16
|
+
info: :gray,
|
16
17
|
refactor: :yellow,
|
17
18
|
convention: :yellow,
|
18
19
|
warning: :magenta,
|
@@ -76,7 +77,7 @@ module RuboCop
|
|
76
77
|
end
|
77
78
|
|
78
79
|
def colored_severity_code(offense)
|
79
|
-
color = COLOR_FOR_SEVERITY
|
80
|
+
color = COLOR_FOR_SEVERITY.fetch(offense.severity.name)
|
80
81
|
colorize(offense.severity.code, color)
|
81
82
|
end
|
82
83
|
|
@@ -37,8 +37,10 @@ module RuboCop
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def report_highlighted_area(highlighted_area)
|
40
|
-
|
41
|
-
|
40
|
+
space_area = highlighted_area.source_buffer.slice(0...highlighted_area.begin_pos)
|
41
|
+
source_area = highlighted_area.source
|
42
|
+
output.puts("# #{' ' * Unicode::DisplayWidth.of(space_area)}" \
|
43
|
+
"#{'^' * Unicode::DisplayWidth.of(source_area)}")
|
42
44
|
end
|
43
45
|
|
44
46
|
def report_offense(file, offense)
|
@@ -47,7 +47,7 @@ module RuboCop
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def valid_shareable_constant_value?
|
50
|
-
%w[none literal experimental_everything experimental_copy].include?(
|
50
|
+
%w[none literal experimental_everything experimental_copy].include?(shareable_constant_value)
|
51
51
|
end
|
52
52
|
|
53
53
|
# Was a magic comment for the frozen string literal found?
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
# DidYouMean::SpellChecker is not available in all versions of Ruby, and
|
17
17
|
# even on versions where it *is* available (>= 2.3), it is not always
|
18
18
|
# required correctly. So we do a feature check first.
|
19
|
-
# See: https://github.com/rubocop
|
19
|
+
# See: https://github.com/rubocop/rubocop/issues/7979
|
20
20
|
return [] unless defined?(DidYouMean::SpellChecker)
|
21
21
|
|
22
22
|
names = names.dup
|
@@ -96,6 +96,7 @@ module RuboCop
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def wanted_dir_patterns(base_dir, exclude_pattern, flags)
|
99
|
+
base_dir = base_dir.gsub('/{}/', '/\{}/')
|
99
100
|
dirs = Dir.glob(File.join(base_dir.gsub('/**/', '/\**/'), '*/'), flags)
|
100
101
|
.reject do |dir|
|
101
102
|
dir.end_with?('/./', '/../') || File.fnmatch?(exclude_pattern, dir, flags)
|
data/lib/rubocop/target_ruby.rb
CHANGED
@@ -147,10 +147,12 @@ module RuboCop
|
|
147
147
|
|
148
148
|
GEMSPEC_EXTENSION = '.gemspec'
|
149
149
|
|
150
|
+
# @!method required_ruby_version(node)
|
150
151
|
def_node_search :required_ruby_version, <<~PATTERN
|
151
152
|
(send _ :required_ruby_version= $_)
|
152
153
|
PATTERN
|
153
154
|
|
155
|
+
# @!method gem_requirement?(node)
|
154
156
|
def_node_matcher :gem_requirement?, <<~PATTERN
|
155
157
|
(send (const(const _ :Gem):Requirement) :new $str)
|
156
158
|
PATTERN
|
@@ -165,14 +167,10 @@ module RuboCop
|
|
165
167
|
file = gemspec_filepath
|
166
168
|
return unless file && File.file?(file)
|
167
169
|
|
168
|
-
|
169
|
-
return if
|
170
|
+
right_hand_side = version_from_gemspec_file(file)
|
171
|
+
return if right_hand_side.nil?
|
170
172
|
|
171
|
-
|
172
|
-
return version_from_array(version) if version.array_type?
|
173
|
-
return version_from_array(requirement) if gem_requirement? version
|
174
|
-
|
175
|
-
version_from_str(version.str_content)
|
173
|
+
find_minimal_known_ruby(right_hand_side)
|
176
174
|
end
|
177
175
|
|
178
176
|
def gemspec_filename
|
@@ -192,15 +190,25 @@ module RuboCop
|
|
192
190
|
required_ruby_version(processed_source.ast).first
|
193
191
|
end
|
194
192
|
|
193
|
+
def version_from_right_hand_side(right_hand_side)
|
194
|
+
if right_hand_side.array_type?
|
195
|
+
version_from_array(right_hand_side)
|
196
|
+
elsif gem_requirement?(right_hand_side)
|
197
|
+
right_hand_side.children.last.value
|
198
|
+
else
|
199
|
+
right_hand_side.value
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
195
203
|
def version_from_array(array)
|
196
|
-
|
197
|
-
versions.compact.min
|
204
|
+
array.children.map(&:value)
|
198
205
|
end
|
199
206
|
|
200
|
-
def
|
201
|
-
|
202
|
-
|
203
|
-
|
207
|
+
def find_minimal_known_ruby(right_hand_side)
|
208
|
+
version = version_from_right_hand_side(right_hand_side)
|
209
|
+
requirement = Gem::Requirement.new(version)
|
210
|
+
|
211
|
+
KNOWN_RUBIES.detect { |v| requirement.satisfied_by?(Gem::Version.new("#{v}.99")) }
|
204
212
|
end
|
205
213
|
end
|
206
214
|
|
data/lib/rubocop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-04-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parallel
|
@@ -242,7 +242,9 @@ files:
|
|
242
242
|
- lib/rubocop/cop/correctors/string_literal_corrector.rb
|
243
243
|
- lib/rubocop/cop/correctors/unused_arg_corrector.rb
|
244
244
|
- lib/rubocop/cop/documentation.rb
|
245
|
+
- lib/rubocop/cop/exclude_limit.rb
|
245
246
|
- lib/rubocop/cop/force.rb
|
247
|
+
- lib/rubocop/cop/gemspec/date_assignment.rb
|
246
248
|
- lib/rubocop/cop/gemspec/duplicated_assignment.rb
|
247
249
|
- lib/rubocop/cop/gemspec/ordered_dependencies.rb
|
248
250
|
- lib/rubocop/cop/gemspec/required_ruby_version.rb
|
@@ -256,6 +258,7 @@ files:
|
|
256
258
|
- lib/rubocop/cop/internal_affairs/example_description.rb
|
257
259
|
- lib/rubocop/cop/internal_affairs/method_name_equal.rb
|
258
260
|
- lib/rubocop/cop/internal_affairs/node_destructuring.rb
|
261
|
+
- lib/rubocop/cop/internal_affairs/node_matcher_directive.rb
|
259
262
|
- lib/rubocop/cop/internal_affairs/node_type_predicate.rb
|
260
263
|
- lib/rubocop/cop/internal_affairs/offense_location_keyword.rb
|
261
264
|
- lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb
|
@@ -598,6 +601,7 @@ files:
|
|
598
601
|
- lib/rubocop/cop/style/bare_percent_literals.rb
|
599
602
|
- lib/rubocop/cop/style/begin_block.rb
|
600
603
|
- lib/rubocop/cop/style/bisected_attr_accessor.rb
|
604
|
+
- lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
|
601
605
|
- lib/rubocop/cop/style/block_comments.rb
|
602
606
|
- lib/rubocop/cop/style/block_delimiters.rb
|
603
607
|
- lib/rubocop/cop/style/case_equality.rb
|
@@ -654,6 +658,7 @@ files:
|
|
654
658
|
- lib/rubocop/cop/style/global_vars.rb
|
655
659
|
- lib/rubocop/cop/style/guard_clause.rb
|
656
660
|
- lib/rubocop/cop/style/hash_as_last_array_item.rb
|
661
|
+
- lib/rubocop/cop/style/hash_conversion.rb
|
657
662
|
- lib/rubocop/cop/style/hash_each_methods.rb
|
658
663
|
- lib/rubocop/cop/style/hash_except.rb
|
659
664
|
- lib/rubocop/cop/style/hash_like_case.rb
|
@@ -764,6 +769,7 @@ files:
|
|
764
769
|
- lib/rubocop/cop/style/stabby_lambda_parentheses.rb
|
765
770
|
- lib/rubocop/cop/style/static_class.rb
|
766
771
|
- lib/rubocop/cop/style/stderr_puts.rb
|
772
|
+
- lib/rubocop/cop/style/string_chars.rb
|
767
773
|
- lib/rubocop/cop/style/string_concatenation.rb
|
768
774
|
- lib/rubocop/cop/style/string_hash_keys.rb
|
769
775
|
- lib/rubocop/cop/style/string_literals.rb
|
@@ -787,6 +793,7 @@ files:
|
|
787
793
|
- lib/rubocop/cop/style/trailing_underscore_variable.rb
|
788
794
|
- lib/rubocop/cop/style/trivial_accessors.rb
|
789
795
|
- lib/rubocop/cop/style/unless_else.rb
|
796
|
+
- lib/rubocop/cop/style/unless_logical_operators.rb
|
790
797
|
- lib/rubocop/cop/style/unpack_first.rb
|
791
798
|
- lib/rubocop/cop/style/variable_interpolation.rb
|
792
799
|
- lib/rubocop/cop/style/when_then.rb
|
@@ -858,15 +865,15 @@ files:
|
|
858
865
|
- lib/rubocop/version.rb
|
859
866
|
- lib/rubocop/warning.rb
|
860
867
|
- lib/rubocop/yaml_duplication_checker.rb
|
861
|
-
homepage: https://github.com/rubocop
|
868
|
+
homepage: https://github.com/rubocop/rubocop
|
862
869
|
licenses:
|
863
870
|
- MIT
|
864
871
|
metadata:
|
865
872
|
homepage_uri: https://rubocop.org/
|
866
|
-
changelog_uri: https://github.com/rubocop
|
867
|
-
source_code_uri: https://github.com/rubocop
|
868
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
869
|
-
bug_tracker_uri: https://github.com/rubocop
|
873
|
+
changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
|
874
|
+
source_code_uri: https://github.com/rubocop/rubocop/
|
875
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.12/
|
876
|
+
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
870
877
|
post_install_message:
|
871
878
|
rdoc_options: []
|
872
879
|
require_paths:
|