rubocop 0.80.0 → 0.84.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 +4 -4
- data/config/default.yml +171 -34
- data/lib/rubocop.rb +15 -62
- data/lib/rubocop/ast_aliases.rb +8 -0
- data/lib/rubocop/cli.rb +11 -5
- data/lib/rubocop/cli/command/show_cops.rb +2 -6
- data/lib/rubocop/config.rb +41 -13
- data/lib/rubocop/config_loader.rb +40 -36
- data/lib/rubocop/config_loader_resolver.rb +27 -4
- data/lib/rubocop/config_obsoletion.rb +2 -0
- data/lib/rubocop/config_validator.rb +18 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -2
- data/lib/rubocop/cop/badge.rb +5 -5
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
- data/lib/rubocop/cop/corrector.rb +49 -27
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +4 -8
- data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -2
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -3
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
- data/lib/rubocop/cop/generator.rb +4 -3
- data/lib/rubocop/cop/ignored_node.rb +1 -3
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/array_alignment.rb +53 -10
- data/lib/rubocop/cop/layout/block_end_newline.rb +5 -3
- data/lib/rubocop/cop/layout/condition_position.rb +12 -2
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +8 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -6
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +126 -0
- data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +0 -2
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +14 -10
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -3
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +4 -8
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/{tab.rb → indentation_style.rb} +48 -6
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +7 -4
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -4
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +13 -4
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -3
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +129 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +19 -2
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -3
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_range_literal.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -6
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +40 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +14 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +12 -0
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +133 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -5
- data/lib/rubocop/cop/lint/empty_when.rb +29 -6
- data/lib/rubocop/cop/lint/ensure_return.rb +18 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -7
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
- data/lib/rubocop/cop/lint/interpolation_check.rb +1 -1
- data/lib/rubocop/cop/lint/literal_as_condition.rb +10 -13
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/loop.rb +6 -4
- data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
- data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +31 -11
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
- data/lib/rubocop/cop/lint/raise_exception.rb +75 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -6
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
- data/lib/rubocop/cop/lint/struct_new_override.rb +58 -0
- data/lib/rubocop/cop/lint/suppressed_exception.rb +20 -25
- data/lib/rubocop/cop/lint/syntax.rb +1 -3
- data/lib/rubocop/cop/lint/unified_integer.rb +0 -2
- data/lib/rubocop/cop/lint/unused_method_argument.rb +32 -6
- data/lib/rubocop/cop/lint/uri_regexp.rb +4 -4
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +13 -3
- data/lib/rubocop/cop/lint/useless_assignment.rb +3 -2
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +5 -0
- data/lib/rubocop/cop/migration/department_name.rb +21 -12
- data/lib/rubocop/cop/mixin/alignment.rb +1 -3
- data/lib/rubocop/cop/mixin/array_min_size.rb +2 -6
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +4 -12
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -3
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +10 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +9 -3
- data/lib/rubocop/cop/mixin/line_length_help.rb +2 -1
- data/lib/rubocop/cop/mixin/method_complexity.rb +5 -0
- data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +1 -3
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -22
- data/lib/rubocop/cop/mixin/surrounding_space.rb +1 -3
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +5 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +2 -1
- data/lib/rubocop/cop/naming/file_name.rb +1 -3
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +26 -0
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
- data/lib/rubocop/cop/registry.rb +13 -10
- data/lib/rubocop/cop/severity.rb +1 -3
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -6
- data/lib/rubocop/cop/style/alias.rb +4 -4
- data/lib/rubocop/cop/style/and_or.rb +7 -8
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -8
- data/lib/rubocop/cop/style/case_equality.rb +24 -1
- data/lib/rubocop/cop/style/character_literal.rb +2 -2
- data/lib/rubocop/cop/style/collection_methods.rb +2 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +9 -11
- data/lib/rubocop/cop/style/copyright.rb +1 -1
- data/lib/rubocop/cop/style/dir.rb +1 -1
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +49 -0
- data/lib/rubocop/cop/style/documentation.rb +43 -5
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +41 -4
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +3 -3
- data/lib/rubocop/cop/style/empty_literal.rb +1 -3
- data/lib/rubocop/cop/style/empty_method.rb +1 -5
- data/lib/rubocop/cop/style/end_block.rb +6 -0
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -3
- data/lib/rubocop/cop/style/exponential_notation.rb +119 -0
- data/lib/rubocop/cop/style/format_string.rb +2 -2
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +2 -4
- data/lib/rubocop/cop/style/guard_clause.rb +25 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +5 -3
- data/lib/rubocop/cop/style/hash_syntax.rb +15 -10
- data/lib/rubocop/cop/style/hash_transform_keys.rb +6 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +6 -5
- data/lib/rubocop/cop/style/if_unless_modifier.rb +23 -3
- data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +9 -5
- data/lib/rubocop/cop/style/lambda.rb +3 -2
- data/lib/rubocop/cop/style/lambda_call.rb +1 -21
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -3
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/module_function.rb +58 -12
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +16 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +2 -4
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +4 -4
- data/lib/rubocop/cop/style/next.rb +2 -2
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
- data/lib/rubocop/cop/style/non_nil_check.rb +4 -4
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
- data/lib/rubocop/cop/style/one_line_conditional.rb +6 -9
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
- data/lib/rubocop/cop/style/or_assignment.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
- data/lib/rubocop/cop/style/redundant_condition.rb +18 -6
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +3 -3
- data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -6
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
- data/lib/rubocop/cop/style/redundant_return.rb +5 -7
- data/lib/rubocop/cop/style/redundant_self.rb +1 -1
- data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/return_nil.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +3 -7
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +39 -0
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -7
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -4
- data/lib/rubocop/cop/style/string_hash_keys.rb +1 -1
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/symbol_literal.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -5
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +35 -0
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +41 -0
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +88 -0
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +44 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +2 -6
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +0 -4
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -1
- data/lib/rubocop/cop/util.rb +24 -0
- data/lib/rubocop/cop/variable_force.rb +3 -9
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -0
- data/lib/rubocop/cop/variable_force/branch.rb +2 -6
- data/lib/rubocop/cop/variable_force/scope.rb +1 -0
- data/lib/rubocop/cop/variable_force/variable.rb +3 -6
- data/lib/rubocop/ext/processed_source.rb +18 -0
- data/lib/rubocop/formatter/base_formatter.rb +0 -4
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -12
- data/lib/rubocop/formatter/formatter_set.rb +1 -4
- data/lib/rubocop/formatter/junit_formatter.rb +17 -6
- data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
- data/lib/rubocop/formatter/tap_formatter.rb +1 -1
- data/lib/rubocop/name_similarity.rb +12 -9
- data/lib/rubocop/options.rb +20 -13
- data/lib/rubocop/remote_config.rb +1 -3
- data/lib/rubocop/result_cache.rb +1 -3
- data/lib/rubocop/rspec/cop_helper.rb +2 -4
- data/lib/rubocop/rspec/expect_offense.rb +4 -10
- data/lib/rubocop/rspec/shared_contexts.rb +54 -20
- data/lib/rubocop/runner.rb +15 -12
- data/lib/rubocop/target_finder.rb +5 -7
- data/lib/rubocop/target_ruby.rb +2 -2
- data/lib/rubocop/version.rb +5 -3
- metadata +32 -77
- data/lib/rubocop/ast/builder.rb +0 -83
- data/lib/rubocop/ast/node.rb +0 -632
- data/lib/rubocop/ast/node/alias_node.rb +0 -24
- data/lib/rubocop/ast/node/and_node.rb +0 -29
- data/lib/rubocop/ast/node/args_node.rb +0 -29
- data/lib/rubocop/ast/node/array_node.rb +0 -57
- data/lib/rubocop/ast/node/block_node.rb +0 -117
- data/lib/rubocop/ast/node/break_node.rb +0 -17
- data/lib/rubocop/ast/node/case_node.rb +0 -56
- data/lib/rubocop/ast/node/class_node.rb +0 -31
- data/lib/rubocop/ast/node/def_node.rb +0 -82
- data/lib/rubocop/ast/node/defined_node.rb +0 -17
- data/lib/rubocop/ast/node/ensure_node.rb +0 -17
- data/lib/rubocop/ast/node/float_node.rb +0 -12
- data/lib/rubocop/ast/node/for_node.rb +0 -53
- data/lib/rubocop/ast/node/forward_args_node.rb +0 -18
- data/lib/rubocop/ast/node/hash_node.rb +0 -109
- data/lib/rubocop/ast/node/if_node.rb +0 -175
- data/lib/rubocop/ast/node/int_node.rb +0 -12
- data/lib/rubocop/ast/node/keyword_splat_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/basic_literal_node.rb +0 -16
- data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +0 -43
- data/lib/rubocop/ast/node/mixin/collection_node.rb +0 -15
- data/lib/rubocop/ast/node/mixin/conditional_node.rb +0 -45
- data/lib/rubocop/ast/node/mixin/hash_element_node.rb +0 -125
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +0 -261
- data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +0 -114
- data/lib/rubocop/ast/node/mixin/modifier_node.rb +0 -17
- data/lib/rubocop/ast/node/mixin/numeric_node.rb +0 -21
- data/lib/rubocop/ast/node/mixin/parameterized_node.rb +0 -61
- data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +0 -35
- data/lib/rubocop/ast/node/module_node.rb +0 -24
- data/lib/rubocop/ast/node/or_node.rb +0 -29
- data/lib/rubocop/ast/node/pair_node.rb +0 -63
- data/lib/rubocop/ast/node/range_node.rb +0 -18
- data/lib/rubocop/ast/node/regexp_node.rb +0 -33
- data/lib/rubocop/ast/node/resbody_node.rb +0 -24
- data/lib/rubocop/ast/node/retry_node.rb +0 -17
- data/lib/rubocop/ast/node/return_node.rb +0 -24
- data/lib/rubocop/ast/node/self_class_node.rb +0 -24
- data/lib/rubocop/ast/node/send_node.rb +0 -13
- data/lib/rubocop/ast/node/str_node.rb +0 -16
- data/lib/rubocop/ast/node/super_node.rb +0 -21
- data/lib/rubocop/ast/node/symbol_node.rb +0 -12
- data/lib/rubocop/ast/node/until_node.rb +0 -35
- data/lib/rubocop/ast/node/when_node.rb +0 -53
- data/lib/rubocop/ast/node/while_node.rb +0 -35
- data/lib/rubocop/ast/node/yield_node.rb +0 -21
- data/lib/rubocop/ast/sexp.rb +0 -16
- data/lib/rubocop/ast/traversal.rb +0 -200
- data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
- data/lib/rubocop/node_pattern.rb +0 -887
- data/lib/rubocop/processed_source.rb +0 -216
- data/lib/rubocop/string_util.rb +0 -14
- data/lib/rubocop/token.rb +0 -114
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module AST
|
5
|
-
# A node extension for `defined?` nodes. This will be used in place of a
|
6
|
-
# plain node when the builder constructs the AST, making its methods
|
7
|
-
# available to all `send` nodes within RuboCop.
|
8
|
-
class DefinedNode < Node
|
9
|
-
include ParameterizedNode
|
10
|
-
include MethodDispatchNode
|
11
|
-
|
12
|
-
def node_parts
|
13
|
-
[nil, :defined?, *to_a]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module AST
|
5
|
-
# A node extension for `ensure` 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 `ensure` nodes within RuboCop.
|
8
|
-
class EnsureNode < Node
|
9
|
-
# Returns the body of the `ensure` clause.
|
10
|
-
#
|
11
|
-
# @return [Node, nil] The body of the `ensure`.
|
12
|
-
def body
|
13
|
-
node_parts[1]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module AST
|
5
|
-
# A node extension for `float` nodes. This will be used in place of a plain
|
6
|
-
# node when the builder constructs the AST, making its methods available to
|
7
|
-
# all `float` nodes within RuboCop.
|
8
|
-
class FloatNode < Node
|
9
|
-
include NumericNode
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module AST
|
5
|
-
# A node extension for `for` 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 `for` nodes within RuboCop.
|
8
|
-
class ForNode < Node
|
9
|
-
# Returns the keyword of the `for` statement as a string.
|
10
|
-
#
|
11
|
-
# @return [String] the keyword of the `until` statement
|
12
|
-
def keyword
|
13
|
-
'for'
|
14
|
-
end
|
15
|
-
|
16
|
-
# Checks whether the `for` node has a `do` keyword.
|
17
|
-
#
|
18
|
-
# @return [Boolean] whether the `for` node has a `do` keyword
|
19
|
-
def do?
|
20
|
-
loc.begin&.is?('do')
|
21
|
-
end
|
22
|
-
|
23
|
-
# Checks whether this node body is a void context.
|
24
|
-
# Always `true` for `for`.
|
25
|
-
#
|
26
|
-
# @return [true] whether the `for` node body is a void context
|
27
|
-
def void_context?
|
28
|
-
true
|
29
|
-
end
|
30
|
-
|
31
|
-
# Returns the iteration variable of the `for` loop.
|
32
|
-
#
|
33
|
-
# @return [Node] The iteration variable of the `for` loop
|
34
|
-
def variable
|
35
|
-
node_parts[0]
|
36
|
-
end
|
37
|
-
|
38
|
-
# Returns the collection the `for` loop is iterating over.
|
39
|
-
#
|
40
|
-
# @return [Node] The collection the `for` loop is iterating over
|
41
|
-
def collection
|
42
|
-
node_parts[1]
|
43
|
-
end
|
44
|
-
|
45
|
-
# Returns the body of the `for` loop.
|
46
|
-
#
|
47
|
-
# @return [Node, nil] The body of the `for` loop.
|
48
|
-
def body
|
49
|
-
node_parts[2]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module AST
|
5
|
-
# A node extension for `forward-args` nodes. This will be used in place
|
6
|
-
# of a plain node when the builder constructs the AST, making its methods
|
7
|
-
# available to all `forward-args` nodes within RuboCop.
|
8
|
-
class ForwardArgsNode < Node
|
9
|
-
include CollectionNode
|
10
|
-
|
11
|
-
# Node wraps itself in an array to be compatible with other
|
12
|
-
# enumerable argument types.
|
13
|
-
def to_a
|
14
|
-
[self]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module AST
|
5
|
-
# A node extension for `hash` 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 `hash` nodes within RuboCop.
|
8
|
-
class HashNode < Node
|
9
|
-
# Returns an array of all the key value pairs in the `hash` literal.
|
10
|
-
#
|
11
|
-
# @return [Array<PairNode>] an array of `pair` nodes
|
12
|
-
def pairs
|
13
|
-
each_pair.to_a
|
14
|
-
end
|
15
|
-
|
16
|
-
# Checks whether the `hash` node contains any `pair`- or `kwsplat` nodes.
|
17
|
-
#
|
18
|
-
# @return[Boolean] whether the `hash` is empty
|
19
|
-
def empty?
|
20
|
-
children.empty?
|
21
|
-
end
|
22
|
-
|
23
|
-
# Calls the given block for each `pair` node in the `hash` literal.
|
24
|
-
# If no block is given, an `Enumerator` is returned.
|
25
|
-
#
|
26
|
-
# @return [self] if a block is given
|
27
|
-
# @return [Enumerator] if no block is given
|
28
|
-
def each_pair
|
29
|
-
return each_child_node(:pair).to_enum unless block_given?
|
30
|
-
|
31
|
-
each_child_node(:pair) do |pair|
|
32
|
-
yield(*pair)
|
33
|
-
end
|
34
|
-
|
35
|
-
self
|
36
|
-
end
|
37
|
-
|
38
|
-
# Returns an array of all the keys in the `hash` literal.
|
39
|
-
#
|
40
|
-
# @return [Array<Node>] an array of keys in the `hash` literal
|
41
|
-
def keys
|
42
|
-
each_key.to_a
|
43
|
-
end
|
44
|
-
|
45
|
-
# Calls the given block for each `key` node in the `hash` literal.
|
46
|
-
# If no block is given, an `Enumerator` is returned.
|
47
|
-
#
|
48
|
-
# @return [self] if a block is given
|
49
|
-
# @return [Enumerator] if no block is given
|
50
|
-
def each_key
|
51
|
-
return pairs.map(&:key).to_enum unless block_given?
|
52
|
-
|
53
|
-
pairs.map(&:key).each do |key|
|
54
|
-
yield key
|
55
|
-
end
|
56
|
-
|
57
|
-
self
|
58
|
-
end
|
59
|
-
|
60
|
-
# Returns an array of all the values in the `hash` literal.
|
61
|
-
#
|
62
|
-
# @return [Array<Node>] an array of values in the `hash` literal
|
63
|
-
def values
|
64
|
-
each_pair.map(&:value)
|
65
|
-
end
|
66
|
-
|
67
|
-
# Calls the given block for each `value` node in the `hash` literal.
|
68
|
-
# If no block is given, an `Enumerator` is returned.
|
69
|
-
#
|
70
|
-
# @return [self] if a block is given
|
71
|
-
# @return [Enumerator] if no block is given
|
72
|
-
def each_value
|
73
|
-
return pairs.map(&:value).to_enum unless block_given?
|
74
|
-
|
75
|
-
pairs.map(&:value).each do |value|
|
76
|
-
yield value
|
77
|
-
end
|
78
|
-
|
79
|
-
self
|
80
|
-
end
|
81
|
-
|
82
|
-
# Checks whether any of the key value pairs in the `hash` literal are on
|
83
|
-
# the same line.
|
84
|
-
#
|
85
|
-
# @note A multiline `pair` is considered to be on the same line if it
|
86
|
-
# shares any of its lines with another `pair`
|
87
|
-
#
|
88
|
-
# @return [Boolean] whether any `pair` nodes are on the same line
|
89
|
-
def pairs_on_same_line?
|
90
|
-
pairs.each_cons(2).any? { |first, second| first.same_line?(second) }
|
91
|
-
end
|
92
|
-
|
93
|
-
# Checks whether this `hash` uses a mix of hash rocket and colon
|
94
|
-
# delimiters for its pairs.
|
95
|
-
#
|
96
|
-
# @return [Boolean] whether the `hash` uses mixed delimiters
|
97
|
-
def mixed_delimiters?
|
98
|
-
pairs.map(&:delimiter).uniq.size > 1
|
99
|
-
end
|
100
|
-
|
101
|
-
# Checks whether the `hash` literal is delimited by curly braces.
|
102
|
-
#
|
103
|
-
# @return [Boolean] whether the `hash` literal is enclosed in braces
|
104
|
-
def braces?
|
105
|
-
loc.end&.is?('}')
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,175 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module AST
|
5
|
-
# A node extension for `if` 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 `if` nodes within RuboCop.
|
8
|
-
class IfNode < Node
|
9
|
-
include ConditionalNode
|
10
|
-
include ModifierNode
|
11
|
-
|
12
|
-
# Checks whether this node is an `if` statement. (This is not true of
|
13
|
-
# ternary operators and `unless` statements.)
|
14
|
-
#
|
15
|
-
# @return [Boolean] whether the node is an `if` statement
|
16
|
-
def if?
|
17
|
-
keyword == 'if'
|
18
|
-
end
|
19
|
-
|
20
|
-
# Checks whether this node is an `unless` statement. (This is not true
|
21
|
-
# of ternary operators and `if` statements.)
|
22
|
-
#
|
23
|
-
# @return [Boolean] whether the node is an `unless` statement
|
24
|
-
def unless?
|
25
|
-
keyword == 'unless'
|
26
|
-
end
|
27
|
-
|
28
|
-
# Checks whether the `if` is an `elsif`. Parser handles these by nesting
|
29
|
-
# `if` nodes in the `else` branch.
|
30
|
-
#
|
31
|
-
# @return [Boolean] whether the node is an `elsif`
|
32
|
-
def elsif?
|
33
|
-
keyword == 'elsif'
|
34
|
-
end
|
35
|
-
|
36
|
-
# Checks whether the `if` node has an `else` clause.
|
37
|
-
#
|
38
|
-
# @note This returns `true` for nodes containing an `elsif` clause.
|
39
|
-
# This is legacy behavior, and many cops rely on it.
|
40
|
-
#
|
41
|
-
# @return [Boolean] whether the node has an `else` clause
|
42
|
-
def else?
|
43
|
-
loc.respond_to?(:else) && loc.else
|
44
|
-
end
|
45
|
-
|
46
|
-
# Checks whether the `if` node is a ternary operator.
|
47
|
-
#
|
48
|
-
# @return [Boolean] whether the `if` node is a ternary operator
|
49
|
-
def ternary?
|
50
|
-
loc.respond_to?(:question)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Returns the keyword of the `if` statement as a string. Returns an empty
|
54
|
-
# string for ternary operators.
|
55
|
-
#
|
56
|
-
# @return [String] the keyword of the `if` statement
|
57
|
-
def keyword
|
58
|
-
ternary? ? '' : loc.keyword.source
|
59
|
-
end
|
60
|
-
|
61
|
-
# Returns the inverse keyword of the `if` node as a string. Returns `if`
|
62
|
-
# for `unless` nodes and vice versa. Returns an empty string for ternary
|
63
|
-
# operators.
|
64
|
-
#
|
65
|
-
# @return [String] the inverse keyword of the `if` statement
|
66
|
-
def inverse_keyword
|
67
|
-
if keyword == 'if'
|
68
|
-
'unless'
|
69
|
-
elsif keyword == 'unless'
|
70
|
-
'if'
|
71
|
-
else
|
72
|
-
''
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Checks whether the `if` node is in a modifier form, i.e. a condition
|
77
|
-
# trailing behind an expression. Only `if` and `unless` nodes without
|
78
|
-
# other branches can be modifiers.
|
79
|
-
#
|
80
|
-
# @return [Boolean] whether the `if` node is a modifier
|
81
|
-
def modifier_form?
|
82
|
-
(if? || unless?) && super
|
83
|
-
end
|
84
|
-
|
85
|
-
# Chacks whether the `if` node has nested `if` nodes in any of its
|
86
|
-
# branches.
|
87
|
-
#
|
88
|
-
# @note This performs a shallow search.
|
89
|
-
#
|
90
|
-
# @return [Boolean] whether the `if` node contains nested conditionals
|
91
|
-
def nested_conditional?
|
92
|
-
node_parts[1..2].compact.each do |branch|
|
93
|
-
branch.each_node(:if) do |nested|
|
94
|
-
return true unless nested.elsif?
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
false
|
99
|
-
end
|
100
|
-
|
101
|
-
# Checks whether the `if` node has at least one `elsif` branch. Returns
|
102
|
-
# true if this `if` node itself is an `elsif`.
|
103
|
-
#
|
104
|
-
# @return [Boolean] whether the `if` node has at least one `elsif` branch
|
105
|
-
def elsif_conditional?
|
106
|
-
else_branch&.if_type? && else_branch&.elsif?
|
107
|
-
end
|
108
|
-
|
109
|
-
# Returns the branch of the `if` node that gets evaluated when its
|
110
|
-
# condition is truthy.
|
111
|
-
#
|
112
|
-
# @note This is normalized for `unless` nodes.
|
113
|
-
#
|
114
|
-
# @return [Node] the truthy branch node of the `if` node
|
115
|
-
# @return [nil] if the truthy branch is empty
|
116
|
-
def if_branch
|
117
|
-
node_parts[1]
|
118
|
-
end
|
119
|
-
|
120
|
-
# Returns the branch of the `if` node that gets evaluated when its
|
121
|
-
# condition is falsey.
|
122
|
-
#
|
123
|
-
# @note This is normalized for `unless` nodes.
|
124
|
-
#
|
125
|
-
# @return [Node] the falsey branch node of the `if` node
|
126
|
-
# @return [nil] when there is no else branch
|
127
|
-
def else_branch
|
128
|
-
node_parts[2]
|
129
|
-
end
|
130
|
-
|
131
|
-
# Custom destructuring method. This is used to normalize the branches
|
132
|
-
# for `if` and `unless` nodes, to aid comparisons and conversions.
|
133
|
-
#
|
134
|
-
# @return [Array<Node>] the different parts of the `if` statement
|
135
|
-
def node_parts
|
136
|
-
if unless?
|
137
|
-
condition, false_branch, true_branch = *self
|
138
|
-
else
|
139
|
-
condition, true_branch, false_branch = *self
|
140
|
-
end
|
141
|
-
|
142
|
-
[condition, true_branch, false_branch]
|
143
|
-
end
|
144
|
-
|
145
|
-
# Returns an array of all the branches in the conditional statement.
|
146
|
-
#
|
147
|
-
# @return [Array<Node>] an array of branch nodes
|
148
|
-
def branches
|
149
|
-
branches = [if_branch]
|
150
|
-
|
151
|
-
return branches unless else_branch
|
152
|
-
|
153
|
-
other_branches = if elsif_conditional?
|
154
|
-
else_branch.branches
|
155
|
-
else
|
156
|
-
[else_branch]
|
157
|
-
end
|
158
|
-
branches.concat(other_branches)
|
159
|
-
end
|
160
|
-
|
161
|
-
# Calls the given block for each branch node in the conditional statement.
|
162
|
-
# If no block is given, an `Enumerator` is returned.
|
163
|
-
#
|
164
|
-
# @return [self] if a block is given
|
165
|
-
# @return [Enumerator] if no block is given
|
166
|
-
def each_branch
|
167
|
-
return branches.to_enum(__method__) unless block_given?
|
168
|
-
|
169
|
-
branches.each do |branch|
|
170
|
-
yield branch
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module AST
|
5
|
-
# A node extension for `int` nodes. This will be used in place of a plain
|
6
|
-
# node when the builder constructs the AST, making its methods available to
|
7
|
-
# all `int` nodes within RuboCop.
|
8
|
-
class IntNode < Node
|
9
|
-
include NumericNode
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module AST
|
5
|
-
# A node extension for `kwsplat` nodes. This will be used in place of a
|
6
|
-
# plain node when the builder constructs the AST, making its methods
|
7
|
-
# available to all `kwsplat` nodes within RuboCop.
|
8
|
-
class KeywordSplatNode < Node
|
9
|
-
include HashElementNode
|
10
|
-
|
11
|
-
DOUBLE_SPLAT = '**'
|
12
|
-
|
13
|
-
# This is used for duck typing with `pair` nodes which also appear as
|
14
|
-
# `hash` elements.
|
15
|
-
#
|
16
|
-
# @return [false]
|
17
|
-
def hash_rocket?
|
18
|
-
false
|
19
|
-
end
|
20
|
-
|
21
|
-
# This is used for duck typing with `pair` nodes which also appear as
|
22
|
-
# `hash` elements.
|
23
|
-
#
|
24
|
-
# @return [false]
|
25
|
-
def colon?
|
26
|
-
false
|
27
|
-
end
|
28
|
-
|
29
|
-
# Returns the operator for the `kwsplat` as a string.
|
30
|
-
#
|
31
|
-
# @return [String] the double splat operator
|
32
|
-
def operator
|
33
|
-
DOUBLE_SPLAT
|
34
|
-
end
|
35
|
-
|
36
|
-
# Custom destructuring method. This is used to normalize the branches
|
37
|
-
# for `pair` and `kwsplat` nodes, to add duck typing to `hash` elements.
|
38
|
-
#
|
39
|
-
# @return [Array<KeywordSplatNode>] the different parts of the `kwsplat`
|
40
|
-
def node_parts
|
41
|
-
[self, self]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|