rubocop 0.49.1 → 0.50.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 +5 -3
- data/bin/rubocop +1 -1
- data/config/default.yml +160 -99
- data/config/disabled.yml +4 -5
- data/config/enabled.yml +149 -47
- data/lib/rubocop.rb +41 -14
- data/lib/rubocop/ast/builder.rb +4 -1
- data/lib/rubocop/ast/node.rb +36 -42
- data/lib/rubocop/ast/node/args_node.rb +1 -13
- data/lib/rubocop/ast/node/array_node.rb +9 -0
- data/lib/rubocop/ast/node/block_node.rb +9 -0
- data/lib/rubocop/ast/node/def_node.rb +71 -0
- data/lib/rubocop/ast/node/for_node.rb +8 -0
- data/lib/rubocop/ast/node/if_node.rb +10 -2
- data/lib/rubocop/ast/node/mixin/collection_node.rb +15 -0
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +174 -0
- data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +89 -0
- data/lib/rubocop/ast/node/mixin/parameterized_node.rb +18 -31
- data/lib/rubocop/ast/node/regexp_node.rb +35 -0
- data/lib/rubocop/ast/node/send_node.rb +1 -154
- data/lib/rubocop/ast/node/super_node.rb +3 -24
- data/lib/rubocop/ast/node/yield_node.rb +21 -0
- data/lib/rubocop/ast/traversal.rb +6 -6
- data/lib/rubocop/cli.rb +7 -3
- data/lib/rubocop/config.rb +45 -8
- data/lib/rubocop/config_loader.rb +7 -5
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +3 -3
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +64 -0
- data/lib/rubocop/cop/bundler/ordered_gems.rb +12 -12
- data/lib/rubocop/cop/commissioner.rb +8 -2
- data/lib/rubocop/cop/cop.rb +3 -1
- data/lib/rubocop/cop/generator.rb +94 -21
- data/lib/rubocop/cop/internal_affairs.rb +3 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +14 -3
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +43 -0
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +46 -0
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +49 -0
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +1 -1
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +2 -3
- data/lib/rubocop/cop/layout/align_array.rb +2 -2
- data/lib/rubocop/cop/layout/align_hash.rb +2 -2
- data/lib/rubocop/cop/layout/align_parameters.rb +5 -11
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -5
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +9 -0
- data/lib/rubocop/cop/layout/else_alignment.rb +30 -13
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +20 -4
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +3 -3
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +3 -3
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +3 -3
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +5 -2
- data/lib/rubocop/cop/layout/indent_heredoc.rb +19 -24
- data/lib/rubocop/cop/layout/indentation_consistency.rb +1 -2
- data/lib/rubocop/cop/layout/indentation_width.rb +12 -8
- data/lib/rubocop/cop/layout/leading_comment_space.rb +33 -18
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +20 -17
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +3 -3
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +6 -0
- data/lib/rubocop/cop/layout/space_after_colon.rb +7 -0
- data/lib/rubocop/cop/layout/space_after_comma.rb +10 -0
- data/lib/rubocop/cop/layout/space_after_method_name.rb +5 -3
- data/lib/rubocop/cop/layout/space_after_not.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +13 -4
- data/lib/rubocop/cop/layout/space_around_keyword.rb +9 -5
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +54 -5
- data/lib/rubocop/cop/layout/space_before_comment.rb +7 -0
- data/lib/rubocop/cop/layout/space_before_semicolon.rb +7 -0
- data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_range_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +8 -4
- data/lib/rubocop/cop/layout/tab.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +4 -2
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +15 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +15 -6
- data/lib/rubocop/cop/lint/boolean_symbol.rb +38 -0
- data/lib/rubocop/cop/lint/condition_position.rb +5 -1
- data/lib/rubocop/cop/lint/debugger.rb +16 -9
- data/lib/rubocop/cop/lint/def_end_alignment.rb +4 -4
- data/lib/rubocop/cop/lint/duplicate_case_condition.rb +3 -3
- data/lib/rubocop/cop/lint/duplicate_methods.rb +73 -5
- data/lib/rubocop/cop/lint/duplicated_key.rb +1 -1
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/else_layout.rb +1 -1
- data/lib/rubocop/cop/lint/empty_expression.rb +1 -1
- data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/empty_when.rb +1 -1
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/float_out_of_range.rb +5 -5
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +35 -40
- data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -1
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +18 -13
- data/lib/rubocop/cop/lint/inherit_exception.rb +8 -7
- data/lib/rubocop/cop/lint/interpolation_check.rb +36 -0
- data/lib/rubocop/cop/lint/literal_in_condition.rb +3 -3
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/multiple_compare.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +5 -7
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
- data/lib/rubocop/cop/lint/percent_string_array.rb +3 -12
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/rand_one.rb +7 -1
- data/lib/rubocop/cop/lint/redundant_with_index.rb +77 -0
- data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +13 -6
- data/lib/rubocop/cop/lint/rescue_without_error_class.rb +38 -0
- data/lib/rubocop/cop/lint/return_in_void_context.rb +63 -0
- data/lib/rubocop/cop/lint/script_permission.rb +6 -0
- data/lib/rubocop/cop/lint/syntax.rb +17 -20
- data/lib/rubocop/cop/lint/unified_integer.rb +3 -2
- data/lib/rubocop/cop/lint/unneeded_disable.rb +1 -1
- data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +53 -8
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +74 -0
- data/lib/rubocop/cop/lint/uri_regexp.rb +73 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -8
- data/lib/rubocop/cop/lint/useless_setter_call.rb +10 -11
- data/lib/rubocop/cop/lint/void.rb +29 -23
- data/lib/rubocop/cop/metrics/line_length.rb +2 -2
- data/lib/rubocop/cop/metrics/method_length.rb +8 -3
- data/lib/rubocop/cop/metrics/parameter_lists.rb +5 -2
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -2
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +12 -3
- data/lib/rubocop/cop/mixin/heredoc.rb +28 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +9 -6
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +68 -31
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +18 -0
- data/lib/rubocop/cop/mixin/negative_conditional.rb +1 -1
- data/lib/rubocop/cop/mixin/percent_array.rb +52 -0
- data/lib/rubocop/cop/mixin/string_help.rb +1 -1
- data/lib/rubocop/cop/{style → naming}/accessor_method_name.rb +11 -12
- data/lib/rubocop/cop/{style → naming}/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/{style/op_method.rb → naming/binary_operator_parameter_name.rb} +2 -2
- data/lib/rubocop/cop/{style → naming}/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/{style → naming}/constant_name.rb +1 -1
- data/lib/rubocop/cop/{style → naming}/file_name.rb +8 -4
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +68 -0
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +58 -0
- data/lib/rubocop/cop/{style → naming}/method_name.rb +1 -1
- data/lib/rubocop/cop/{style → naming}/predicate_name.rb +6 -7
- data/lib/rubocop/cop/{style → naming}/variable_name.rb +11 -15
- data/lib/rubocop/cop/{style → naming}/variable_number.rb +1 -1
- data/lib/rubocop/cop/performance/caller.rb +39 -11
- data/lib/rubocop/cop/performance/casecmp.rb +4 -4
- data/lib/rubocop/cop/performance/compare_with_block.rb +4 -4
- data/lib/rubocop/cop/performance/double_start_end_with.rb +4 -4
- data/lib/rubocop/cop/performance/end_with.rb +3 -3
- data/lib/rubocop/cop/performance/fixed_size.rb +1 -1
- data/lib/rubocop/cop/performance/hash_each_methods.rb +66 -25
- data/lib/rubocop/cop/performance/lstrip_rstrip.rb +2 -2
- data/lib/rubocop/cop/performance/range_include.rb +2 -2
- data/lib/rubocop/cop/performance/redundant_block_call.rb +6 -6
- data/lib/rubocop/cop/performance/redundant_match.rb +5 -5
- data/lib/rubocop/cop/performance/redundant_merge.rb +39 -23
- data/lib/rubocop/cop/performance/redundant_sort_by.rb +2 -2
- data/lib/rubocop/cop/performance/regexp_match.rb +13 -5
- data/lib/rubocop/cop/performance/size.rb +1 -1
- data/lib/rubocop/cop/performance/start_with.rb +3 -3
- data/lib/rubocop/cop/performance/times_map.rb +23 -12
- data/lib/rubocop/cop/performance/unfreeze_string.rb +50 -0
- data/lib/rubocop/cop/performance/uri_default_parser.rb +47 -0
- data/lib/rubocop/cop/rails/active_support_aliases.rb +1 -1
- data/lib/rubocop/cop/rails/delegate.rb +36 -7
- data/lib/rubocop/cop/rails/delegate_allow_blank.rb +1 -1
- data/lib/rubocop/cop/rails/enum_uniqueness.rb +2 -2
- data/lib/rubocop/cop/rails/file_path.rb +3 -4
- data/lib/rubocop/cop/rails/find_each.rb +1 -1
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +48 -0
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +5 -5
- data/lib/rubocop/cop/rails/not_null_column.rb +1 -1
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +2 -2
- data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
- data/lib/rubocop/cop/rails/request_referer.rb +2 -2
- data/lib/rubocop/cop/rails/reversible_migration.rb +12 -12
- data/lib/rubocop/cop/rails/save_bang.rb +8 -6
- data/lib/rubocop/cop/rails/scope_args.rb +1 -1
- data/lib/rubocop/cop/security/eval.rb +2 -2
- data/lib/rubocop/cop/security/json_load.rb +2 -2
- data/lib/rubocop/cop/security/marshal_load.rb +2 -2
- data/lib/rubocop/cop/security/yaml_load.rb +2 -2
- data/lib/rubocop/cop/style/alias.rb +44 -20
- data/lib/rubocop/cop/style/and_or.rb +48 -34
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +3 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -1
- data/lib/rubocop/cop/style/command_literal.rb +20 -9
- data/lib/rubocop/cop/style/conditional_assignment.rb +30 -28
- data/lib/rubocop/cop/style/copyright.rb +10 -10
- data/lib/rubocop/cop/style/def_with_parentheses.rb +6 -5
- data/lib/rubocop/cop/style/dir.rb +52 -0
- data/lib/rubocop/cop/style/documentation_method.rb +2 -6
- data/lib/rubocop/cop/style/empty_case_condition.rb +1 -1
- data/lib/rubocop/cop/style/empty_else.rb +3 -2
- data/lib/rubocop/cop/style/empty_literal.rb +1 -2
- data/lib/rubocop/cop/style/empty_method.rb +27 -17
- data/lib/rubocop/cop/style/flip_flop.rb +2 -2
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +4 -2
- data/lib/rubocop/cop/style/hash_syntax.rb +10 -10
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +5 -1
- data/lib/rubocop/cop/style/if_with_semicolon.rb +1 -1
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +4 -3
- data/lib/rubocop/cop/style/inline_comment.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +20 -8
- data/lib/rubocop/cop/style/lambda.rb +19 -9
- data/lib/rubocop/cop/style/lambda_call.rb +22 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +4 -20
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +6 -4
- data/lib/rubocop/cop/style/method_def_parentheses.rb +18 -26
- data/lib/rubocop/cop/style/method_missing.rb +5 -18
- data/lib/rubocop/cop/style/min_max.rb +67 -0
- data/lib/rubocop/cop/style/missing_else.rb +16 -3
- data/lib/rubocop/cop/style/mixin_grouping.rb +2 -2
- data/lib/rubocop/cop/style/module_function.rb +8 -4
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +5 -1
- data/lib/rubocop/cop/style/multiline_memoization.rb +25 -3
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +2 -6
- data/lib/rubocop/cop/style/negated_if.rb +8 -4
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +8 -8
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/non_nil_check.rb +14 -14
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +6 -2
- data/lib/rubocop/cop/style/numeric_literals.rb +2 -2
- data/lib/rubocop/cop/style/numeric_predicate.rb +8 -4
- data/lib/rubocop/cop/style/one_line_conditional.rb +8 -3
- data/lib/rubocop/cop/style/option_hash.rb +1 -1
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -2
- data/lib/rubocop/cop/style/or_assignment.rb +88 -0
- data/lib/rubocop/cop/style/parallel_assignment.rb +2 -2
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +12 -11
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +2 -2
- data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +16 -17
- data/lib/rubocop/cop/style/redundant_begin.rb +6 -5
- data/lib/rubocop/cop/style/redundant_conditional.rb +95 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +13 -11
- data/lib/rubocop/cop/style/redundant_return.rb +23 -11
- data/lib/rubocop/cop/style/redundant_self.rb +18 -9
- data/lib/rubocop/cop/style/regexp_literal.rb +12 -4
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/return_nil.rb +98 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +80 -43
- data/lib/rubocop/cop/style/single_line_block_params.rb +14 -13
- data/lib/rubocop/cop/style/single_line_methods.rb +9 -13
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -3
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +17 -39
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +22 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
- data/lib/rubocop/cop/style/symbol_array.rb +5 -25
- data/lib/rubocop/cop/style/symbol_literal.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +3 -18
- data/lib/rubocop/cop/style/ternary_parentheses.rb +14 -10
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +28 -9
- data/lib/rubocop/cop/style/trivial_accessors.rb +39 -56
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +1 -1
- data/lib/rubocop/cop/style/unneeded_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +8 -3
- data/lib/rubocop/cop/style/word_array.rb +7 -24
- data/lib/rubocop/cop/style/yoda_condition.rb +49 -14
- data/lib/rubocop/cop/style/zero_length_predicate.rb +25 -18
- data/lib/rubocop/cop/team.rb +16 -8
- data/lib/rubocop/cop/util.rb +11 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +2 -1
- data/lib/rubocop/formatter/offense_count_formatter.rb +2 -0
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/formatter/tap_formatter.rb +71 -0
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +2 -0
- data/lib/rubocop/node_pattern.rb +44 -26
- data/lib/rubocop/options.rb +1 -0
- data/lib/rubocop/processed_source.rb +3 -1
- data/lib/rubocop/remote_config.rb +5 -1
- data/lib/rubocop/result_cache.rb +1 -0
- data/lib/rubocop/rspec/cop_helper.rb +10 -10
- data/lib/rubocop/rspec/expect_offense.rb +6 -8
- data/lib/rubocop/rspec/shared_examples.rb +8 -8
- data/lib/rubocop/string_util.rb +2 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +51 -18
- data/lib/rubocop/cop/mixin/access_modifier_node.rb +0 -41
- data/lib/rubocop/cop/mixin/on_method_def.rb +0 -44
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# A node extension for `regexp` nodes. This will be used in place of a plain
|
6
|
+
# node when the builder constructs the AST, making its methods available
|
7
|
+
# to all `regexp` nodes within RuboCop.
|
8
|
+
class RegexpNode < Node
|
9
|
+
OPTIONS = {
|
10
|
+
x: Regexp::EXTENDED,
|
11
|
+
i: Regexp::IGNORECASE,
|
12
|
+
m: Regexp::MULTILINE,
|
13
|
+
n: Regexp::NOENCODING
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
# @return [Regexp] a regexp of this node
|
17
|
+
def to_regexp
|
18
|
+
option = regopt.children.map { |opt| OPTIONS[opt] }.inject(:|)
|
19
|
+
Regexp.new(content, option)
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [RuboCop::AST::Node] a regopt node
|
23
|
+
def regopt
|
24
|
+
first, second = *self
|
25
|
+
first.regopt_type? ? first : second
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [String] a string of regexp content
|
29
|
+
def content
|
30
|
+
str = children.first
|
31
|
+
str.str_content || ''
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -7,153 +7,7 @@ module RuboCop
|
|
7
7
|
# to all `send` nodes within RuboCop.
|
8
8
|
class SendNode < Node
|
9
9
|
include ParameterizedNode
|
10
|
-
|
11
|
-
ENUMERATOR_METHODS = %i[collect collect_concat detect downto each
|
12
|
-
find find_all find_index inject loop map!
|
13
|
-
map reduce reject reject! reverse_each select
|
14
|
-
select! times upto].freeze
|
15
|
-
|
16
|
-
# The receiving node of the method invocation.
|
17
|
-
#
|
18
|
-
# @return [Node, nil] the receiver of the invoked method or `nil`
|
19
|
-
def receiver
|
20
|
-
node_parts[0]
|
21
|
-
end
|
22
|
-
|
23
|
-
# The name of the invoked method called as a string.
|
24
|
-
#
|
25
|
-
# @return [Symbol] the name of the invoked method
|
26
|
-
def method_name
|
27
|
-
node_parts[1]
|
28
|
-
end
|
29
|
-
|
30
|
-
# An array containing the arguments of the method invocation.
|
31
|
-
#
|
32
|
-
# @return [Array<Node>] the arguments of the method invocation or `nil`
|
33
|
-
def arguments
|
34
|
-
node_parts[2..-1]
|
35
|
-
end
|
36
|
-
|
37
|
-
# Checks whether the method name matches the argument.
|
38
|
-
#
|
39
|
-
# @param [Symbol, String] name the method name to check for
|
40
|
-
# @return [Boolean] whether the method name matches the argument
|
41
|
-
def method?(name)
|
42
|
-
method_name == name.to_sym
|
43
|
-
end
|
44
|
-
|
45
|
-
# Checks whether the method is a macro method. A macro method is defined
|
46
|
-
# as a method that sits in a class- or module body and has an implicit
|
47
|
-
# receiver.
|
48
|
-
#
|
49
|
-
# @note This does not include DSLs that use nested blocks, like RSpec
|
50
|
-
#
|
51
|
-
# @return [Boolean] whether the method is a macro method
|
52
|
-
def macro?
|
53
|
-
!receiver && macro_scope?
|
54
|
-
end
|
55
|
-
|
56
|
-
# Checks whether the method name matches the argument and has an
|
57
|
-
# implicit receiver.
|
58
|
-
#
|
59
|
-
# @param [Symbol, String] name the method name to check for
|
60
|
-
# @return [Boolean] whether the method name matches the argument
|
61
|
-
def command?(name)
|
62
|
-
!receiver && method?(name)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Checks whether the invoked method is a setter method.
|
66
|
-
#
|
67
|
-
# @return [Boolean] whether the invoked method is a setter
|
68
|
-
def setter_method?
|
69
|
-
loc.operator
|
70
|
-
end
|
71
|
-
|
72
|
-
# Checks whether the invoked method is an operator method.
|
73
|
-
#
|
74
|
-
# @return [Boolean] whether the invoked method is an operator
|
75
|
-
def operator_method?
|
76
|
-
RuboCop::Cop::Util::OPERATOR_METHODS.include?(method_name)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Checks whether the invoked method is a comparison method.
|
80
|
-
#
|
81
|
-
# @return [Boolean] whether the involed method is a comparison
|
82
|
-
def comparison_method?
|
83
|
-
COMPARISON_OPERATORS.include?(method_name)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Checks whether the invoked method is an assignment method.
|
87
|
-
#
|
88
|
-
# @return [Boolean] whether the invoked method is an assignment.
|
89
|
-
def assignment_method?
|
90
|
-
!comparison_method? && method_name.to_s.end_with?('=')
|
91
|
-
end
|
92
|
-
|
93
|
-
# Checks whether the invoked method is an enumerator method.
|
94
|
-
#
|
95
|
-
# @return [Boolean] whether the invoked method is an enumerator.
|
96
|
-
def enumerator_method?
|
97
|
-
ENUMERATOR_METHODS.include?(method_name) ||
|
98
|
-
method_name.to_s.start_with?('each_')
|
99
|
-
end
|
100
|
-
|
101
|
-
# Checks whether the method call uses a dot to connect the receiver and
|
102
|
-
# the method name.
|
103
|
-
#
|
104
|
-
# This is useful for comparison operators, which can be called either
|
105
|
-
# with or without a dot, i.e. `foo == bar` or `foo.== bar`.
|
106
|
-
#
|
107
|
-
# @return [Boolean] whether the method was called with a connecting dot
|
108
|
-
def dot?
|
109
|
-
loc.dot && loc.dot.is?('.')
|
110
|
-
end
|
111
|
-
|
112
|
-
# Checks whether the method call uses a double colon to connect the
|
113
|
-
# receiver and the method name.
|
114
|
-
#
|
115
|
-
# @return [Boolean] whether the method was called with a connecting dot
|
116
|
-
def double_colon?
|
117
|
-
loc.dot && loc.dot.is?('::')
|
118
|
-
end
|
119
|
-
|
120
|
-
# Checks whether the receiver of this method invocation is `self`.
|
121
|
-
#
|
122
|
-
# @return [Boolean] whether the receiver of this method invocation
|
123
|
-
# is `self`
|
124
|
-
def self_receiver?
|
125
|
-
receiver && receiver.self_type?
|
126
|
-
end
|
127
|
-
|
128
|
-
# Checks whether the method call is of the implicit form of `#call`,
|
129
|
-
# e.g. `foo.(bar)`.
|
130
|
-
#
|
131
|
-
# @return [Boolean] whether the method is an implicit form of `#call`
|
132
|
-
def implicit_call?
|
133
|
-
method_name == :call && !loc.selector
|
134
|
-
end
|
135
|
-
|
136
|
-
# Checks whether the invoked method is a predicate method.
|
137
|
-
#
|
138
|
-
# @return [Boolean] whether the invoked method is a predicate method
|
139
|
-
def predicate_method?
|
140
|
-
method_name.to_s.end_with?('?')
|
141
|
-
end
|
142
|
-
|
143
|
-
# Checks whether the invoked method is a bang method.
|
144
|
-
#
|
145
|
-
# @return [Boolean] whether the invoked method is a bang method
|
146
|
-
def bang_method?
|
147
|
-
method_name.to_s.end_with?('!')
|
148
|
-
end
|
149
|
-
|
150
|
-
# Checks whether the invoked method is a camel case method,
|
151
|
-
# e.g. `Integer()`.
|
152
|
-
#
|
153
|
-
# @return [Boolean] whether the invoked method is a camel case method
|
154
|
-
def camel_case_method?
|
155
|
-
method_name.to_s =~ /\A[A-Z]/
|
156
|
-
end
|
10
|
+
include MethodDispatchNode
|
157
11
|
|
158
12
|
# Custom destructuring method. This can be used to normalize
|
159
13
|
# destructuring for different variations of the node.
|
@@ -162,13 +16,6 @@ module RuboCop
|
|
162
16
|
def node_parts
|
163
17
|
to_a
|
164
18
|
end
|
165
|
-
|
166
|
-
private
|
167
|
-
|
168
|
-
def_matcher :macro_scope?, <<-PATTERN
|
169
|
-
{^({class module} ...)
|
170
|
-
^^({class module} ... (begin ...))}
|
171
|
-
PATTERN
|
172
19
|
end
|
173
20
|
end
|
174
21
|
end
|
@@ -7,35 +7,14 @@ module RuboCop
|
|
7
7
|
# methods available to all `super`- and `zsuper` nodes within RuboCop.
|
8
8
|
class SuperNode < Node
|
9
9
|
include ParameterizedNode
|
10
|
-
|
11
|
-
# The method name of this `super` node. Always `:super`.
|
12
|
-
#
|
13
|
-
# @return [Symbol] the method name of `super`
|
14
|
-
def method_name
|
15
|
-
:super
|
16
|
-
end
|
17
|
-
|
18
|
-
# An array containing the arguments of the super invocation.
|
19
|
-
#
|
20
|
-
# @return [Array<Node>] the arguments of the super invocation
|
21
|
-
def arguments
|
22
|
-
node_parts
|
23
|
-
end
|
24
|
-
|
25
|
-
# Checks whether the method name matches the argument.
|
26
|
-
#
|
27
|
-
# @param [Symbol, String] name the method name to check for
|
28
|
-
# @return [Boolean] whether the method name matches the argument
|
29
|
-
def method?(name)
|
30
|
-
method_name == name.to_sym
|
31
|
-
end
|
10
|
+
include MethodDispatchNode
|
32
11
|
|
33
12
|
# Custom destructuring method. This can be used to normalize
|
34
13
|
# destructuring for different variations of the node.
|
35
14
|
#
|
36
|
-
# @return [Array] the different parts of the `
|
15
|
+
# @return [Array] the different parts of the `super` node
|
37
16
|
def node_parts
|
38
|
-
to_a
|
17
|
+
[nil, :super, *to_a]
|
39
18
|
end
|
40
19
|
end
|
41
20
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# A node extension for `yield` nodes. This will be used in place of a plain
|
6
|
+
# node when the builder constructs the AST, making its methods available
|
7
|
+
# to all `yield` nodes within RuboCop.
|
8
|
+
class YieldNode < Node
|
9
|
+
include ParameterizedNode
|
10
|
+
include MethodDispatchNode
|
11
|
+
|
12
|
+
# Custom destructuring method. This can be used to normalize
|
13
|
+
# destructuring for different variations of the node.
|
14
|
+
#
|
15
|
+
# @return [Array] the different parts of the `send` node
|
16
|
+
def node_parts
|
17
|
+
[nil, :yield, *to_a]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -34,33 +34,33 @@ module RuboCop
|
|
34
34
|
end
|
35
35
|
|
36
36
|
ONE_CHILD_NODE.each do |type|
|
37
|
-
module_eval(<<-
|
37
|
+
module_eval(<<-RUBY)
|
38
38
|
def on_#{type}(node)
|
39
39
|
if (child = node.children[0])
|
40
40
|
send(:"on_\#{child.type}", child)
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
RUBY
|
44
44
|
end
|
45
45
|
|
46
46
|
MANY_CHILD_NODES.each do |type|
|
47
|
-
module_eval(<<-
|
47
|
+
module_eval(<<-RUBY)
|
48
48
|
def on_#{type}(node)
|
49
49
|
node.children.each { |child| send(:"on_\#{child.type}", child) }
|
50
50
|
nil
|
51
51
|
end
|
52
|
-
|
52
|
+
RUBY
|
53
53
|
end
|
54
54
|
|
55
55
|
SECOND_CHILD_ONLY.each do |type|
|
56
56
|
# Guard clause is for nodes nested within mlhs
|
57
|
-
module_eval(<<-
|
57
|
+
module_eval(<<-RUBY)
|
58
58
|
def on_#{type}(node)
|
59
59
|
if (child = node.children[1])
|
60
60
|
send(:"on_\#{child.type}", child)
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
RUBY
|
64
64
|
end
|
65
65
|
|
66
66
|
def on_const(node)
|
data/lib/rubocop/cli.rb
CHANGED
@@ -15,9 +15,13 @@ module RuboCop
|
|
15
15
|
@config_store = ConfigStore.new
|
16
16
|
end
|
17
17
|
|
18
|
+
# @api public
|
19
|
+
#
|
18
20
|
# Entry point for the application logic. Here we
|
19
21
|
# do the command line arguments processing and inspect
|
20
|
-
# the target files
|
22
|
+
# the target files.
|
23
|
+
#
|
24
|
+
# @param args [Array<String>] command line arguments
|
21
25
|
# @return [Integer] UNIX exit code
|
22
26
|
def run(args = ARGV)
|
23
27
|
@options, paths = Options.new.parse(args)
|
@@ -177,12 +181,12 @@ module RuboCop
|
|
177
181
|
|
178
182
|
errors.each { |error| warn error }
|
179
183
|
|
180
|
-
warn <<-
|
184
|
+
warn <<-WARNING.strip_indent
|
181
185
|
Errors are usually caused by RuboCop bugs.
|
182
186
|
Please, report your problems to RuboCop's issue tracker.
|
183
187
|
Mention the following information in the issue report:
|
184
188
|
#{RuboCop::Version.version(true)}
|
185
|
-
|
189
|
+
WARNING
|
186
190
|
end
|
187
191
|
|
188
192
|
def maybe_print_corrected_source
|
data/lib/rubocop/config.rb
CHANGED
@@ -52,7 +52,36 @@ module RuboCop
|
|
52
52
|
'The `Lint/Eval` cop has been renamed to `Security/Eval`.',
|
53
53
|
'Style/DeprecatedHashMethods' =>
|
54
54
|
'The `Style/DeprecatedHashMethods` cop has been renamed to ' \
|
55
|
-
'`Style/PreferredHashMethods`.'
|
55
|
+
'`Style/PreferredHashMethods`.',
|
56
|
+
'Style/AccessorMethodName' =>
|
57
|
+
'The `Style/AccessorMethodName` cop has been moved to ' \
|
58
|
+
'`Naming/AccessorMethodName`.',
|
59
|
+
'Style/AsciiIdentifiers' =>
|
60
|
+
'The `Style/AsciiIdentifiers` cop has been moved to ' \
|
61
|
+
'`Naming/AccessorMethodName`.',
|
62
|
+
'Style/OpMethod' =>
|
63
|
+
'The `Style/OpMethods` cop has been renamed and moved to ' \
|
64
|
+
'`Naming/BinaryOperatorParameter`.',
|
65
|
+
'Style/ClassAndModuleCamelCase' =>
|
66
|
+
'The `Style/ClassAndModuleCamelCase` cop has been renamed to ' \
|
67
|
+
'`Naming/ClassAndModuleCamelCase`.',
|
68
|
+
'Style/ConstantName' =>
|
69
|
+
'The `Style/ConstantName` cop has been renamed to ' \
|
70
|
+
'`Naming/ConstantName`.',
|
71
|
+
'Style/FileName' =>
|
72
|
+
'The `Style/FileName` cop has been renamed to `Naming/FileName`.',
|
73
|
+
'Style/MethodName' =>
|
74
|
+
'The `Style/MethodName` cop has been renamed to ' \
|
75
|
+
'`Naming/MethodName`.',
|
76
|
+
'Style/PredicateName' =>
|
77
|
+
'The `Style/PredicateName` cop has been renamed to ' \
|
78
|
+
'`Naming/PredicateName`.',
|
79
|
+
'Style/VariableName' =>
|
80
|
+
'The `Style/VariableName` cop has been renamed to ' \
|
81
|
+
'`Naming/VariableName`.',
|
82
|
+
'Style/VariableNumber' =>
|
83
|
+
'The `Style/VariableNumber` cop has been renamed to ' \
|
84
|
+
'`Naming/VariableNumber`.'
|
56
85
|
}.freeze
|
57
86
|
|
58
87
|
OBSOLETE_PARAMETERS = [
|
@@ -145,6 +174,10 @@ module RuboCop
|
|
145
174
|
@hash.keys
|
146
175
|
end
|
147
176
|
|
177
|
+
def each_key(&block)
|
178
|
+
@hash.each_key(&block)
|
179
|
+
end
|
180
|
+
|
148
181
|
def map(&block)
|
149
182
|
@hash.map(&block)
|
150
183
|
end
|
@@ -166,7 +199,7 @@ module RuboCop
|
|
166
199
|
end
|
167
200
|
|
168
201
|
def make_excludes_absolute
|
169
|
-
|
202
|
+
each_key do |key|
|
170
203
|
validate_section_presence(key)
|
171
204
|
next unless self[key]['Exclude']
|
172
205
|
|
@@ -227,6 +260,7 @@ module RuboCop
|
|
227
260
|
check_target_ruby
|
228
261
|
validate_parameter_names(valid_cop_names)
|
229
262
|
validate_enforced_styles(valid_cop_names)
|
263
|
+
validate_syntax_cop(valid_cop_names)
|
230
264
|
reject_mutually_exclusive_defaults
|
231
265
|
end
|
232
266
|
|
@@ -317,12 +351,6 @@ module RuboCop
|
|
317
351
|
|
318
352
|
def warn_about_unrecognized_cops(invalid_cop_names)
|
319
353
|
invalid_cop_names.each do |name|
|
320
|
-
if name == 'Syntax'
|
321
|
-
raise ValidationError,
|
322
|
-
"configuration for Syntax cop found in #{loaded_path}\n" \
|
323
|
-
'This cop cannot be configured.'
|
324
|
-
end
|
325
|
-
|
326
354
|
# There could be a custom cop with this name. If so, don't warn
|
327
355
|
next if Cop::Cop.registry.contains_cop_matching?([name])
|
328
356
|
|
@@ -331,6 +359,15 @@ module RuboCop
|
|
331
359
|
end
|
332
360
|
end
|
333
361
|
|
362
|
+
def validate_syntax_cop(valid_cop_names)
|
363
|
+
return unless valid_cop_names.include?('Lint/Syntax') ||
|
364
|
+
valid_cop_names.include?('Syntax')
|
365
|
+
|
366
|
+
raise ValidationError,
|
367
|
+
"configuration for Syntax cop found in #{loaded_path}\n" \
|
368
|
+
'This cop cannot be configured.'
|
369
|
+
end
|
370
|
+
|
334
371
|
def validate_section_presence(name)
|
335
372
|
return unless key?(name) && self[name].nil?
|
336
373
|
raise ValidationError, "empty section #{name} found in #{loaded_path}"
|
@@ -59,14 +59,16 @@ module RuboCop
|
|
59
59
|
config
|
60
60
|
end
|
61
61
|
|
62
|
+
# rubocop:disable Performance/HashEachMethods
|
62
63
|
def add_missing_namespaces(path, hash)
|
63
|
-
hash.keys.each do |
|
64
|
-
q = Cop::Cop.qualified_cop_name(
|
65
|
-
next if q ==
|
64
|
+
hash.keys.each do |key|
|
65
|
+
q = Cop::Cop.qualified_cop_name(key, path)
|
66
|
+
next if q == key
|
66
67
|
|
67
|
-
hash[q] = hash.delete(
|
68
|
+
hash[q] = hash.delete(key)
|
68
69
|
end
|
69
70
|
end
|
71
|
+
# rubocop:enable Performance/HashEachMethods
|
70
72
|
|
71
73
|
# Return a recursive merge of two hashes. That is, a normal hash merge,
|
72
74
|
# with the addition that any value that is a hash, and occurs in both
|
@@ -83,7 +85,7 @@ module RuboCop
|
|
83
85
|
|
84
86
|
def base_configs(path, inherit_from)
|
85
87
|
configs = Array(inherit_from).compact.map do |f|
|
86
|
-
if f =~ /\A#{URI::
|
88
|
+
if f =~ /\A#{URI::DEFAULT_PARSER.make_regexp(%w[http https])}\z/
|
87
89
|
f = RemoteConfig.new(f, File.dirname(path)).file
|
88
90
|
else
|
89
91
|
f = File.expand_path(f, File.dirname(path))
|