rubocop 0.52.0 → 0.52.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 +6 -5
- data/config/default.yml +1 -11
- data/config/disabled.yml +5 -0
- data/config/enabled.yml +6 -8
- data/lib/rubocop.rb +13 -2
- data/lib/rubocop/ast/node.rb +23 -15
- data/lib/rubocop/cli.rb +25 -2
- data/lib/rubocop/config.rb +23 -8
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
- data/lib/rubocop/cop/bundler/ordered_gems.rb +9 -0
- data/lib/rubocop/cop/commissioner.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +121 -0
- data/lib/rubocop/cop/correctors/condition_corrector.rb +28 -0
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +26 -0
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +62 -0
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +44 -0
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +31 -0
- data/lib/rubocop/cop/correctors/punctuation_corrector.rb +29 -0
- data/lib/rubocop/cop/correctors/space_corrector.rb +34 -0
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +25 -0
- data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +31 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +9 -0
- data/lib/rubocop/cop/generator.rb +18 -87
- data/lib/rubocop/cop/generator/require_file_injector.rb +78 -0
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/align_array.rb +5 -1
- data/lib/rubocop/cop/layout/align_hash.rb +1 -1
- data/lib/rubocop/cop/layout/align_parameters.rb +5 -1
- data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +2 -2
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +5 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +3 -3
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +17 -19
- data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +4 -0
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/indent_array.rb +6 -2
- data/lib/rubocop/cop/layout/indent_assignment.rb +6 -2
- data/lib/rubocop/cop/layout/indent_hash.rb +5 -1
- data/lib/rubocop/cop/layout/indentation_consistency.rb +5 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +5 -1
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +3 -3
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -2
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -1
- data/lib/rubocop/cop/layout/space_after_comma.rb +4 -0
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +4 -0
- data/lib/rubocop/cop/layout/space_before_comma.rb +4 -0
- data/lib/rubocop/cop/layout/space_before_semicolon.rb +4 -0
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +3 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +16 -7
- data/lib/rubocop/cop/layout/tab.rb +1 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
- data/lib/rubocop/cop/lint/def_end_alignment.rb +2 -2
- data/lib/rubocop/cop/lint/end_alignment.rb +3 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/unused_block_argument.rb +4 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +6 -0
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -1
- data/lib/rubocop/cop/mixin/alignment.rb +70 -0
- data/lib/rubocop/cop/mixin/array_hash_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/array_syntax.rb +2 -0
- data/lib/rubocop/cop/mixin/code_length.rb +2 -0
- data/lib/rubocop/cop/mixin/configurable_max.rb +2 -0
- data/lib/rubocop/cop/mixin/def_node.rb +3 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -15
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -25
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +0 -6
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +5 -9
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +2 -2
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +2 -0
- data/lib/rubocop/cop/mixin/integer_node.rb +2 -0
- data/lib/rubocop/cop/mixin/match_range.rb +2 -0
- data/lib/rubocop/cop/mixin/min_body_length.rb +2 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +9 -48
- data/lib/rubocop/cop/mixin/negative_conditional.rb +2 -16
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +12 -31
- data/lib/rubocop/cop/mixin/parentheses.rb +2 -19
- data/lib/rubocop/cop/mixin/percent_literal.rb +3 -3
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +2 -0
- data/lib/rubocop/cop/mixin/rescue_node.rb +2 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +2 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -3
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -3
- data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -2
- data/lib/rubocop/cop/mixin/string_help.rb +2 -0
- data/lib/rubocop/cop/mixin/string_literals_help.rb +2 -13
- data/lib/rubocop/cop/mixin/surrounding_space.rb +4 -21
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -10
- data/lib/rubocop/cop/mixin/unused_argument.rb +2 -15
- data/lib/rubocop/cop/performance/case_when_splat.rb +1 -1
- data/lib/rubocop/cop/rails/action_filter.rb +3 -2
- data/lib/rubocop/cop/rails/active_support_aliases.rb +3 -2
- data/lib/rubocop/cop/rails/application_job.rb +6 -0
- data/lib/rubocop/cop/rails/application_record.rb +6 -0
- data/lib/rubocop/cop/rails/blank.rb +10 -9
- data/lib/rubocop/cop/rails/date.rb +22 -14
- data/lib/rubocop/cop/rails/delegate.rb +1 -1
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +3 -2
- data/lib/rubocop/cop/rails/enum_uniqueness.rb +4 -2
- data/lib/rubocop/cop/rails/environment_comparison.rb +2 -2
- data/lib/rubocop/cop/rails/file_path.rb +1 -1
- data/lib/rubocop/cop/rails/find_by.rb +2 -2
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +15 -7
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +2 -2
- data/lib/rubocop/cop/rails/inverse_of.rb +130 -8
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +3 -3
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +3 -2
- data/lib/rubocop/cop/rails/presence.rb +31 -18
- data/lib/rubocop/cop/rails/present.rb +11 -8
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +52 -10
- data/lib/rubocop/cop/rails/request_referer.rb +2 -3
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +9 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +38 -10
- data/lib/rubocop/cop/style/class_and_module_children.rb +76 -0
- data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
- data/lib/rubocop/cop/style/format_string_token.rb +24 -4
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +46 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -3
- data/lib/rubocop/cop/style/if_unless_modifier.rb +14 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +79 -0
- data/lib/rubocop/cop/style/mixin_usage.rb +13 -2
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +19 -0
- data/lib/rubocop/cop/style/negated_if.rb +1 -1
- data/lib/rubocop/cop/style/negated_while.rb +6 -4
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +4 -0
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +4 -0
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/string_literals.rb +4 -0
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +4 -0
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +4 -0
- data/lib/rubocop/cop/style/trailing_comma_in_literal.rb +4 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +33 -24
- data/lib/rubocop/options.rb +33 -10
- data/lib/rubocop/path_util.rb +7 -0
- data/lib/rubocop/token.rb +4 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +14 -4
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +0 -149
- data/lib/rubocop/cop/style/extend_self.rb +0 -92
@@ -1,92 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
module Style
|
6
|
-
# This cop checks that `#module_function` is used over `extend self`.
|
7
|
-
#
|
8
|
-
# @example EnforcedStyle: module_function (default)
|
9
|
-
#
|
10
|
-
# # bad
|
11
|
-
# module Foo
|
12
|
-
# extend self
|
13
|
-
# end
|
14
|
-
#
|
15
|
-
# # good
|
16
|
-
# module Foo
|
17
|
-
# module_function
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# @example EnforcedStyle: extend_self
|
21
|
-
#
|
22
|
-
# # bad
|
23
|
-
# module Foo
|
24
|
-
# module_function
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
# # good
|
28
|
-
# module Foo
|
29
|
-
# extend self
|
30
|
-
# end
|
31
|
-
class ExtendSelf < Cop
|
32
|
-
include ConfigurableEnforcedStyle
|
33
|
-
|
34
|
-
MSG = 'Use `%<enforced>s` instead of `%<alternate>s`.'.freeze
|
35
|
-
|
36
|
-
def_node_matcher :extend_self?, <<-PATTERN
|
37
|
-
(send nil? :extend (self))
|
38
|
-
PATTERN
|
39
|
-
|
40
|
-
def_node_matcher :module_function?, <<-PATTERN
|
41
|
-
(send nil? :module_function)
|
42
|
-
PATTERN
|
43
|
-
|
44
|
-
def_node_matcher :module_scope?, <<-PATTERN
|
45
|
-
{^(module ...) ^^(module _ ({begin kwbegin} ...))}
|
46
|
-
PATTERN
|
47
|
-
|
48
|
-
def on_send(node)
|
49
|
-
return unless module_scope?(node)
|
50
|
-
return unless module_function_enforced? && extend_self?(node) ||
|
51
|
-
extend_self_enforced? && module_function?(node)
|
52
|
-
|
53
|
-
add_offense(node)
|
54
|
-
end
|
55
|
-
|
56
|
-
def autocorrect(node)
|
57
|
-
lambda do |corrector|
|
58
|
-
corrector.replace(node.loc.expression, enforced_source)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def message(_node)
|
65
|
-
format(MSG, enforced: enforced_source, alternate: alternate_source)
|
66
|
-
end
|
67
|
-
|
68
|
-
def enforced_source
|
69
|
-
case style
|
70
|
-
when :module_function then 'module_function'
|
71
|
-
when :extend_self then 'extend self'
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def alternate_source
|
76
|
-
case style
|
77
|
-
when :module_function then 'extend self'
|
78
|
-
when :extend_self then 'module_function'
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def module_function_enforced?
|
83
|
-
style == :module_function
|
84
|
-
end
|
85
|
-
|
86
|
-
def extend_self_enforced?
|
87
|
-
style == :extend_self
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|