rubocop 1.10.0 → 1.11.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 +12 -12
- data/assets/output.html.erb +1 -1
- data/config/default.yml +13 -0
- data/lib/rubocop.rb +1 -0
- data/lib/rubocop/cli/command/execute_runner.rb +1 -1
- data/lib/rubocop/cli/command/suggest_extensions.rb +1 -1
- 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/gemspec/date_assignment.rb +1 -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/block_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +1 -0
- data/lib/rubocop/cop/layout/extra_spacing.rb +2 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -1
- 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 +3 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -0
- 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 +1 -0
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
- 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 +1 -0
- 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 +2 -0
- 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_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 +2 -0
- 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/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/metrics/module_length.rb +1 -0
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -0
- 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/def_node.rb +1 -0
- 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/method_complexity.rb +1 -0
- data/lib/rubocop/cop/mixin/negative_conditional.rb +3 -0
- data/lib/rubocop/cop/mixin/preferred_delimiters.rb +1 -1
- 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/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 +2 -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/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 +1 -0
- data/lib/rubocop/cop/style/alias.rb +1 -0
- 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/case_equality.rb +2 -1
- data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -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/conditional_assignment.rb +2 -0
- data/lib/rubocop/cop/style/constant_visibility.rb +1 -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/documentation.rb +5 -0
- data/lib/rubocop/cop/style/documentation_method.rb +1 -0
- data/lib/rubocop/cop/style/double_negation.rb +1 -0
- 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 +2 -0
- 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 +1 -0
- 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/global_std_stream.rb +1 -0
- data/lib/rubocop/cop/style/hash_conversion.rb +26 -2
- 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_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 +2 -0
- 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/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/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 +1 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +3 -0
- 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_predicate.rb +3 -0
- 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 +7 -1
- 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_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_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/slicing_with_range.rb +1 -0
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -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 +1 -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 +1 -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 +99 -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/name_similarity.rb +1 -1
- data/lib/rubocop/target_ruby.rb +21 -13
- data/lib/rubocop/version.rb +1 -1
- metadata +9 -7
@@ -10,8 +10,13 @@ module RuboCop
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
+
# @!method empty_condition?(node)
|
13
14
|
def_node_matcher :empty_condition?, '(begin)'
|
15
|
+
|
16
|
+
# @!method setter_method?(node)
|
14
17
|
def_node_matcher :setter_method?, '[(send ...) setter_method?]'
|
18
|
+
|
19
|
+
# @!method safe_assignment?(node)
|
15
20
|
def_node_matcher :safe_assignment?,
|
16
21
|
'(begin {equals_asgn? #setter_method?})'
|
17
22
|
|
@@ -22,6 +22,7 @@ module RuboCop
|
|
22
22
|
OP_LIKE_METHODS = %i[eql? equal?].freeze
|
23
23
|
EXCLUDED = %i[+@ -@ [] []= << === ` =~].freeze
|
24
24
|
|
25
|
+
# @!method op_method_candidate?(node)
|
25
26
|
def_node_matcher :op_method_candidate?, <<~PATTERN
|
26
27
|
(def [#op_method? $_] (args $(arg [!:other !:_other])) _)
|
27
28
|
PATTERN
|
@@ -23,6 +23,7 @@ module RuboCop
|
|
23
23
|
# than just standard ASCII characters
|
24
24
|
SNAKE_CASE = /^[[:digit:][:upper:]_]+$/.freeze
|
25
25
|
|
26
|
+
# @!method class_or_struct_return_method?(node)
|
26
27
|
def_node_matcher :class_or_struct_return_method?, <<~PATTERN
|
27
28
|
(send
|
28
29
|
(const _ {:Class :Struct}) :new
|
@@ -64,6 +65,7 @@ module RuboCop
|
|
64
65
|
(node.receiver.nil? || !literal_receiver?(node))
|
65
66
|
end
|
66
67
|
|
68
|
+
# @!method literal_receiver?(node)
|
67
69
|
def_node_matcher :literal_receiver?, <<~PATTERN
|
68
70
|
{(send literal? ...)
|
69
71
|
(send (begin literal?) ...)}
|
@@ -148,6 +148,7 @@ module RuboCop
|
|
148
148
|
'with `_`. Use `@%<suggested_var>s` instead.'
|
149
149
|
DYNAMIC_DEFINE_METHODS = %i[define_method define_singleton_method].to_set.freeze
|
150
150
|
|
151
|
+
# @!method method_definition?(node)
|
151
152
|
def_node_matcher :method_definition?, <<~PATTERN
|
152
153
|
${
|
153
154
|
(block (send _ %DYNAMIC_DEFINE_METHODS ({sym str} $_)) ...)
|
@@ -179,6 +180,7 @@ module RuboCop
|
|
179
180
|
end
|
180
181
|
# rubocop:enable Metrics/AbcSize
|
181
182
|
|
183
|
+
# @!method defined_memoized?(node, ivar)
|
182
184
|
def_node_matcher :defined_memoized?, <<~PATTERN
|
183
185
|
(begin
|
184
186
|
(if (defined $(ivar %1)) (return $(ivar %1)) nil?)
|
@@ -22,6 +22,7 @@ module RuboCop
|
|
22
22
|
MSG = 'Avoid using `Marshal.%<method>s`.'
|
23
23
|
RESTRICT_ON_SEND = %i[load restore].freeze
|
24
24
|
|
25
|
+
# @!method marshal_load(node)
|
25
26
|
def_node_matcher :marshal_load, <<~PATTERN
|
26
27
|
(send (const {nil? cbase} :Marshal) ${:load :restore}
|
27
28
|
!(send (const {nil? cbase} :Marshal) :dump ...))
|
@@ -77,6 +77,7 @@ module RuboCop
|
|
77
77
|
|
78
78
|
RESTRICT_ON_SEND = %i[private protected public module_function].freeze
|
79
79
|
|
80
|
+
# @!method access_modifier_with_symbol?(node)
|
80
81
|
def_node_matcher :access_modifier_with_symbol?, <<~PATTERN
|
81
82
|
(send nil? {:private :protected :public} (sym _))
|
82
83
|
PATTERN
|
@@ -47,14 +47,17 @@ module RuboCop
|
|
47
47
|
|
48
48
|
MSG = 'Use arguments forwarding.'
|
49
49
|
|
50
|
+
# @!method use_rest_arguments?(node)
|
50
51
|
def_node_matcher :use_rest_arguments?, <<~PATTERN
|
51
52
|
(args (restarg $_) $...)
|
52
53
|
PATTERN
|
53
54
|
|
55
|
+
# @!method only_rest_arguments?(node, name)
|
54
56
|
def_node_matcher :only_rest_arguments?, <<~PATTERN
|
55
57
|
(send _ _ (splat (lvar %1)))
|
56
58
|
PATTERN
|
57
59
|
|
60
|
+
# @!method forwarding_method_arguments?(node, rest_name, block_name, kwargs_name)
|
58
61
|
def_node_matcher :forwarding_method_arguments?, <<~PATTERN
|
59
62
|
{
|
60
63
|
(send _ _
|
@@ -26,10 +26,12 @@ module RuboCop
|
|
26
26
|
SPLAT_MSG = 'Use `Array(%<arg>s)` instead of `[*%<arg>s]`.'
|
27
27
|
CHECK_MSG = 'Use `Array(%<arg>s)` instead of explicit `Array` check.'
|
28
28
|
|
29
|
+
# @!method array_splat?(node)
|
29
30
|
def_node_matcher :array_splat?, <<~PATTERN
|
30
31
|
(array (splat $_))
|
31
32
|
PATTERN
|
32
33
|
|
34
|
+
# @!method unless_array?(node)
|
33
35
|
def_node_matcher :unless_array?, <<~PATTERN
|
34
36
|
(if
|
35
37
|
(send
|
@@ -35,6 +35,7 @@ module RuboCop
|
|
35
35
|
MSG = 'Avoid the use of the case equality operator `===`.'
|
36
36
|
RESTRICT_ON_SEND = %i[===].freeze
|
37
37
|
|
38
|
+
# @!method case_equality?(node)
|
38
39
|
def_node_matcher :case_equality?, '(send $#const? :=== $_)'
|
39
40
|
|
40
41
|
def on_send(node)
|
@@ -64,7 +65,7 @@ module RuboCop
|
|
64
65
|
# The automatic correction from `a === b` to `a.match?(b)` needs to
|
65
66
|
# consider `Regexp.last_match?`, `$~`, `$1`, and etc.
|
66
67
|
# This correction is expected to be supported by `Performance/Regexp` cop.
|
67
|
-
# See: https://github.com/rubocop
|
68
|
+
# See: https://github.com/rubocop/rubocop-performance/issues/152
|
68
69
|
#
|
69
70
|
# So here is noop.
|
70
71
|
when :begin
|
@@ -35,6 +35,7 @@ module RuboCop
|
|
35
35
|
|
36
36
|
RESTRICT_ON_SEND = %i[reject reject! select select!].freeze
|
37
37
|
|
38
|
+
# @!method reject_method?(node)
|
38
39
|
def_node_matcher :reject_method?, <<~PATTERN
|
39
40
|
(block
|
40
41
|
(send
|
@@ -44,6 +45,7 @@ module RuboCop
|
|
44
45
|
$(lvar _) :nil?))
|
45
46
|
PATTERN
|
46
47
|
|
48
|
+
# @!method select_method?(node)
|
47
49
|
def_node_matcher :select_method?, <<~PATTERN
|
48
50
|
(block
|
49
51
|
(send
|
@@ -231,6 +231,7 @@ module RuboCop
|
|
231
231
|
|
232
232
|
# The shovel operator `<<` does not have its own type. It is a `send`
|
233
233
|
# type.
|
234
|
+
# @!method assignment_type?(node)
|
234
235
|
def_node_matcher :assignment_type?, <<~PATTERN
|
235
236
|
{
|
236
237
|
#{ASSIGNMENT_TYPES.join(' ')}
|
@@ -300,6 +301,7 @@ module RuboCop
|
|
300
301
|
style == :assign_inside_condition && assignment_rhs_exist?(node)
|
301
302
|
end
|
302
303
|
|
304
|
+
# @!method candidate_condition?(node)
|
303
305
|
def_node_matcher :candidate_condition?, '[{if case} !#allowed_ternary?]'
|
304
306
|
|
305
307
|
def allowed_ternary?(assignment)
|
@@ -47,14 +47,17 @@ module RuboCop
|
|
47
47
|
CLASS_MSG = 'Prefer Time over DateTime.'
|
48
48
|
COERCION_MSG = 'Do not use #to_datetime.'
|
49
49
|
|
50
|
+
# @!method date_time?(node)
|
50
51
|
def_node_matcher :date_time?, <<~PATTERN
|
51
52
|
(send (const {nil? (cbase)} :DateTime) ...)
|
52
53
|
PATTERN
|
53
54
|
|
55
|
+
# @!method historic_date?(node)
|
54
56
|
def_node_matcher :historic_date?, <<~PATTERN
|
55
57
|
(send _ _ _ (const (const {nil? (cbase)} :Date) _))
|
56
58
|
PATTERN
|
57
59
|
|
60
|
+
# @!method to_datetime?(node)
|
58
61
|
def_node_matcher :to_datetime?, <<~PATTERN
|
59
62
|
(send _ :to_datetime)
|
60
63
|
PATTERN
|
@@ -22,6 +22,7 @@ module RuboCop
|
|
22
22
|
MSG = "Use `__dir__` to get an absolute path to the current file's directory."
|
23
23
|
RESTRICT_ON_SEND = %i[expand_path dirname].freeze
|
24
24
|
|
25
|
+
# @!method dir_replacement?(node)
|
25
26
|
def_node_matcher :dir_replacement?, <<~PATTERN
|
26
27
|
{(send (const {nil? cbase} :File) :expand_path (send (const {nil? cbase} :File) :dirname #file_keyword?))
|
27
28
|
(send (const {nil? cbase} :File) :dirname (send (const {nil? cbase} :File) :realpath #file_keyword?))}
|
@@ -65,8 +65,13 @@ module RuboCop
|
|
65
65
|
|
66
66
|
MSG = 'Missing top-level %<type>s documentation comment.'
|
67
67
|
|
68
|
+
# @!method constant_definition?(node)
|
68
69
|
def_node_matcher :constant_definition?, '{class module casgn}'
|
70
|
+
|
71
|
+
# @!method outer_module(node)
|
69
72
|
def_node_search :outer_module, '(const (const nil? _) _)'
|
73
|
+
|
74
|
+
# @!method constant_visibility_declaration?(node)
|
70
75
|
def_node_matcher :constant_visibility_declaration?, <<~PATTERN
|
71
76
|
(send nil? {:public_constant :private_constant} ({sym str} _))
|
72
77
|
PATTERN
|
@@ -23,6 +23,7 @@ module RuboCop
|
|
23
23
|
MSG = 'Use `each_with_object` instead of `%<method>s`.'
|
24
24
|
METHODS = %i[inject reduce].freeze
|
25
25
|
|
26
|
+
# @!method each_with_object_candidate?(node)
|
26
27
|
def_node_matcher :each_with_object_candidate?, <<~PATTERN
|
27
28
|
(block $(send _ {:inject :reduce} _) $_ $_)
|
28
29
|
PATTERN
|
@@ -27,11 +27,20 @@ module RuboCop
|
|
27
27
|
|
28
28
|
RESTRICT_ON_SEND = %i[new].freeze
|
29
29
|
|
30
|
+
# @!method array_node(node)
|
30
31
|
def_node_matcher :array_node, '(send (const {nil? cbase} :Array) :new)'
|
32
|
+
|
33
|
+
# @!method hash_node(node)
|
31
34
|
def_node_matcher :hash_node, '(send (const {nil? cbase} :Hash) :new)'
|
35
|
+
|
36
|
+
# @!method str_node(node)
|
32
37
|
def_node_matcher :str_node, '(send (const {nil? cbase} :String) :new)'
|
38
|
+
|
39
|
+
# @!method array_with_block(node)
|
33
40
|
def_node_matcher :array_with_block,
|
34
41
|
'(block (send (const {nil? cbase} :Array) :new) args _)'
|
42
|
+
|
43
|
+
# @!method hash_with_block(node)
|
35
44
|
def_node_matcher :hash_with_block, <<~PATTERN
|
36
45
|
{
|
37
46
|
(block (send (const {nil? cbase} :Hash) :new) args _)
|
@@ -11,6 +11,7 @@ module RuboCop
|
|
11
11
|
# Other method definition types are not considered by this cop.
|
12
12
|
#
|
13
13
|
# The supported styles are:
|
14
|
+
#
|
14
15
|
# * allow_single_line (default) - only single line endless method definitions are allowed.
|
15
16
|
# * allow_always - all endless method definitions are allowed.
|
16
17
|
# * disallow - all endless method definitions are disallowed.
|
@@ -65,10 +65,12 @@ module RuboCop
|
|
65
65
|
|
66
66
|
RESTRICT_ON_SEND = %i[eval class_eval module_eval instance_eval].freeze
|
67
67
|
|
68
|
+
# @!method valid_eval_receiver?(node)
|
68
69
|
def_node_matcher :valid_eval_receiver?, <<~PATTERN
|
69
70
|
{ nil? (const {nil? cbase} :Kernel) }
|
70
71
|
PATTERN
|
71
72
|
|
73
|
+
# @!method line_with_offset?(node, sign, num)
|
72
74
|
def_node_matcher :line_with_offset?, <<~PATTERN
|
73
75
|
{
|
74
76
|
(send #special_line_keyword? %1 (int %2))
|