rubocop 0.81.0 → 0.85.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 +13 -17
- data/config/default.yml +141 -35
- data/lib/rubocop.rb +17 -61
- data/lib/rubocop/ast_aliases.rb +8 -0
- data/lib/rubocop/cli.rb +13 -7
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +2 -2
- data/lib/rubocop/cli/command/show_cops.rb +2 -6
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +14 -2
- data/lib/rubocop/config_loader.rb +37 -33
- data/lib/rubocop/config_loader_resolver.rb +45 -6
- data/lib/rubocop/config_obsoletion.rb +1 -0
- data/lib/rubocop/config_store.rb +12 -2
- 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/gem_comment.rb +70 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
- data/lib/rubocop/cop/commissioner.rb +0 -21
- data/lib/rubocop/cop/cop.rb +36 -21
- data/lib/rubocop/cop/corrector.rb +48 -24
- 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 +4 -4
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
- 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/case_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/class_structure.rb +19 -16
- 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/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 +1 -3
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +14 -10
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +1 -1
- 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/first_parameter_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +6 -6
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +5 -9
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +21 -104
- 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 +23 -20
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
- 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_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +131 -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 +1 -3
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +41 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +14 -0
- data/lib/rubocop/cop/lint/boolean_symbol.rb +2 -2
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +137 -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 +19 -2
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -3
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +33 -2
- 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 +1 -1
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +69 -0
- data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +7 -7
- data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +33 -11
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
- data/lib/rubocop/cop/lint/raise_exception.rb +42 -6
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -6
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/suppressed_exception.rb +11 -4
- data/lib/rubocop/cop/lint/syntax.rb +1 -3
- data/lib/rubocop/cop/lint/unified_integer.rb +0 -2
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- 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 +6 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/migration/department_name.rb +7 -7
- data/lib/rubocop/cop/mixin/alignment.rb +1 -3
- data/lib/rubocop/cop/mixin/array_min_size.rb +1 -3
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -9
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +2 -4
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +10 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +9 -2
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +3 -2
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +1 -1
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +16 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -22
- 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/mixin/uncommunicative_name.rb +1 -1
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
- data/lib/rubocop/cop/naming/constant_name.rb +2 -1
- data/lib/rubocop/cop/naming/file_name.rb +27 -14
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +1 -5
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
- data/lib/rubocop/cop/registry.rb +74 -14
- data/lib/rubocop/cop/severity.rb +1 -3
- 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 +2 -2
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
- 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/conditional_assignment.rb +9 -11
- data/lib/rubocop/cop/style/copyright.rb +3 -3
- 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/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 +2 -6
- 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/format_string_token.rb +2 -3
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -6
- data/lib/rubocop/cop/style/guard_clause.rb +25 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +4 -4
- data/lib/rubocop/cop/style/hash_syntax.rb +19 -12
- data/lib/rubocop/cop/style/hash_transform_values.rb +0 -3
- 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/inline_comment.rb +1 -1
- data/lib/rubocop/cop/style/lambda.rb +2 -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 +2 -2
- 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/negated_if.rb +3 -3
- data/lib/rubocop/cop/style/negated_unless.rb +3 -3
- 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 +5 -5
- 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 +3 -7
- 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 +3 -4
- data/lib/rubocop/cop/style/redundant_conditional.rb +5 -4
- 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 +3 -3
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +89 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +130 -0
- 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/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 +2 -2
- 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 +4 -3
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +3 -3
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +16 -13
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +3 -3
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -3
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unless_else.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/when_then.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/team.rb +69 -25
- data/lib/rubocop/cop/util.rb +25 -1
- data/lib/rubocop/cop/utils/format_string.rb +18 -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 +1 -3
- 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/disabled_config_formatter.rb +4 -12
- data/lib/rubocop/formatter/formatter_set.rb +1 -4
- data/lib/rubocop/formatter/junit_formatter.rb +14 -4
- data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
- data/lib/rubocop/magic_comment.rb +1 -1
- data/lib/rubocop/name_similarity.rb +12 -9
- data/lib/rubocop/options.rb +33 -12
- data/lib/rubocop/remote_config.rb +1 -3
- data/lib/rubocop/result_cache.rb +5 -7
- data/lib/rubocop/rspec/cop_helper.rb +3 -26
- data/lib/rubocop/rspec/expect_offense.rb +49 -16
- data/lib/rubocop/rspec/shared_contexts.rb +54 -20
- data/lib/rubocop/runner.rb +21 -14
- data/lib/rubocop/target_finder.rb +7 -7
- data/lib/rubocop/target_ruby.rb +5 -2
- data/lib/rubocop/version.rb +5 -3
- metadata +47 -77
- data/lib/rubocop/ast/builder.rb +0 -85
- data/lib/rubocop/ast/node.rb +0 -637
- 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 -121
- data/lib/rubocop/ast/node/break_node.rb +0 -17
- data/lib/rubocop/ast/node/case_match_node.rb +0 -56
- 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 -202
- 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
@@ -48,15 +48,15 @@ module RuboCop
|
|
48
48
|
|
49
49
|
first_arg, second_arg = *node.arguments
|
50
50
|
|
51
|
-
corrector.replace(first_arg
|
52
|
-
corrector.replace(second_arg
|
51
|
+
corrector.replace(first_arg, second_arg.source)
|
52
|
+
corrector.replace(second_arg, first_arg.source)
|
53
53
|
|
54
54
|
return_value = return_value(node.body)
|
55
55
|
|
56
56
|
if return_value_occupies_whole_line?(return_value)
|
57
57
|
corrector.remove(whole_line_expression(return_value))
|
58
58
|
else
|
59
|
-
corrector.remove(return_value
|
59
|
+
corrector.remove(return_value)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -68,9 +68,7 @@ module RuboCop
|
|
68
68
|
|
69
69
|
def first_argument_unparenthesized?(node)
|
70
70
|
parent = node.parent
|
71
|
-
unless parent && %i[send super zsuper].include?(parent.type)
|
72
|
-
return false
|
73
|
-
end
|
71
|
+
return false unless parent && %i[send super zsuper].include?(parent.type)
|
74
72
|
|
75
73
|
node.object_id == parent.arguments.first.object_id &&
|
76
74
|
!parentheses?(node.parent)
|
@@ -8,7 +8,7 @@ module RuboCop
|
|
8
8
|
# line (compact style), but it can be configured to enforce the `end`
|
9
9
|
# to go on its own line (expanded style).
|
10
10
|
#
|
11
|
-
#
|
11
|
+
# NOTE: A method definition is not considered empty if it contains
|
12
12
|
# comments.
|
13
13
|
#
|
14
14
|
# @example EnforcedStyle: compact (default)
|
@@ -57,7 +57,7 @@ module RuboCop
|
|
57
57
|
|
58
58
|
def autocorrect(node)
|
59
59
|
lambda do |corrector|
|
60
|
-
corrector.replace(node
|
60
|
+
corrector.replace(node, corrected(node))
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -90,10 +90,6 @@ module RuboCop
|
|
90
90
|
compact_style? ? '; ' : "\n#{indent}"
|
91
91
|
end
|
92
92
|
|
93
|
-
def comment_lines?(node)
|
94
|
-
processed_source[line_range(node)].any? { |line| comment_line?(line) }
|
95
|
-
end
|
96
|
-
|
97
93
|
def compact?(node)
|
98
94
|
node.single_line?
|
99
95
|
end
|
@@ -38,7 +38,7 @@ module RuboCop
|
|
38
38
|
replacement_method = replacement_method(arg, method)
|
39
39
|
|
40
40
|
correction = "#{base_number.source}.#{replacement_method}?"
|
41
|
-
->(corrector) { corrector.replace(node
|
41
|
+
->(corrector) { corrector.replace(node, correction) }
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -97,7 +97,7 @@ module RuboCop
|
|
97
97
|
autocorrect_expand_path(corrector, current_path, default_dir)
|
98
98
|
elsif (default_dir = pathname_parent_expand_path(node)) ||
|
99
99
|
(default_dir = pathname_new_parent_expand_path(node))
|
100
|
-
corrector.replace(default_dir
|
100
|
+
corrector.replace(default_dir, '__dir__')
|
101
101
|
remove_parent_method(corrector, default_dir)
|
102
102
|
end
|
103
103
|
end
|
@@ -145,8 +145,8 @@ module RuboCop
|
|
145
145
|
else
|
146
146
|
new_path = "'#{parent_path(stripped_current_path)}'"
|
147
147
|
|
148
|
-
corrector.replace(current_path
|
149
|
-
corrector.replace(default_dir
|
148
|
+
corrector.replace(current_path, new_path)
|
149
|
+
corrector.replace(default_dir, '__dir__')
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop enforces consistency when using exponential notation
|
7
|
+
# for numbers in the code (eg 1.2e4). Different styles are supported:
|
8
|
+
# * `scientific` which enforces a mantissa between 1 (inclusive)
|
9
|
+
# and 10 (exclusive).
|
10
|
+
# * `engineering` which enforces the exponent to be a multiple of 3
|
11
|
+
# and the mantissa to be between 0.1 (inclusive)
|
12
|
+
# and 10 (exclusive).
|
13
|
+
# * `integral` which enforces the mantissa to always be a whole number
|
14
|
+
# without trailing zeroes.
|
15
|
+
#
|
16
|
+
# @example EnforcedStyle: scientific (default)
|
17
|
+
# # Enforces a mantissa between 1 (inclusive) and 10 (exclusive).
|
18
|
+
#
|
19
|
+
# # bad
|
20
|
+
# 10e6
|
21
|
+
# 0.3e4
|
22
|
+
# 11.7e5
|
23
|
+
# 3.14e0
|
24
|
+
#
|
25
|
+
# # good
|
26
|
+
# 1e7
|
27
|
+
# 3e3
|
28
|
+
# 1.17e6
|
29
|
+
# 3.14
|
30
|
+
#
|
31
|
+
# @example EnforcedStyle: engineering
|
32
|
+
# # Enforces using multiple of 3 exponents,
|
33
|
+
# # mantissa should be between 0.1 (inclusive) and 1000 (exclusive)
|
34
|
+
#
|
35
|
+
# # bad
|
36
|
+
# 3.2e7
|
37
|
+
# 0.1e5
|
38
|
+
# 12e5
|
39
|
+
# 1232e6
|
40
|
+
#
|
41
|
+
# # good
|
42
|
+
# 32e6
|
43
|
+
# 10e3
|
44
|
+
# 1.2e6
|
45
|
+
# 1.232e9
|
46
|
+
#
|
47
|
+
# @example EnforcedStyle: integral
|
48
|
+
# # Enforces the mantissa to have no decimal part and no
|
49
|
+
# # trailing zeroes.
|
50
|
+
#
|
51
|
+
# # bad
|
52
|
+
# 3.2e7
|
53
|
+
# 0.1e5
|
54
|
+
# 120e4
|
55
|
+
#
|
56
|
+
# # good
|
57
|
+
# 32e6
|
58
|
+
# 1e4
|
59
|
+
# 12e5
|
60
|
+
#
|
61
|
+
class ExponentialNotation < Cop
|
62
|
+
include ConfigurableEnforcedStyle
|
63
|
+
|
64
|
+
def on_float(node)
|
65
|
+
add_offense(node) if offense?(node)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def scientific?(node)
|
71
|
+
mantissa, = node.source.split('e')
|
72
|
+
mantissa =~ /^-?[1-9](\.\d*[0-9])?$/
|
73
|
+
end
|
74
|
+
|
75
|
+
def engineering?(node)
|
76
|
+
mantissa, exponent = node.source.split('e')
|
77
|
+
return false unless /^-?\d+$/.match?(exponent)
|
78
|
+
return false unless (exponent.to_i % 3).zero?
|
79
|
+
return false if /^-?\d{4}/.match?(mantissa)
|
80
|
+
return false if /^-?0\d/.match?(mantissa)
|
81
|
+
return false if /^-?0.0/.match?(mantissa)
|
82
|
+
|
83
|
+
true
|
84
|
+
end
|
85
|
+
|
86
|
+
def integral(node)
|
87
|
+
mantissa, = node.source.split('e')
|
88
|
+
mantissa =~ /^-?[1-9](\d*[1-9])?$/
|
89
|
+
end
|
90
|
+
|
91
|
+
def offense?(node)
|
92
|
+
return false unless node.source['e']
|
93
|
+
|
94
|
+
case style
|
95
|
+
when :scientific
|
96
|
+
!scientific?(node)
|
97
|
+
when :engineering
|
98
|
+
!engineering?(node)
|
99
|
+
when :integral
|
100
|
+
!integral(node)
|
101
|
+
else
|
102
|
+
false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def message(_node)
|
107
|
+
case style
|
108
|
+
when :scientific
|
109
|
+
'Use a mantissa in [1, 10[.'
|
110
|
+
when :engineering
|
111
|
+
'Use an exponent divisible by 3 and a mantissa in [0.1, 1000[.'
|
112
|
+
when :integral
|
113
|
+
'Use an integer as mantissa, without trailing zero.'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -104,7 +104,7 @@ module RuboCop
|
|
104
104
|
|
105
105
|
corrected = "#{style}(#{node.receiver.source}, #{args})"
|
106
106
|
|
107
|
-
corrector.replace(node
|
107
|
+
corrector.replace(node, corrected)
|
108
108
|
end
|
109
109
|
|
110
110
|
def autocorrect_to_percent(corrector, node)
|
@@ -119,7 +119,7 @@ module RuboCop
|
|
119
119
|
"[#{param_args.map(&:source).join(', ')}]"
|
120
120
|
end
|
121
121
|
|
122
|
-
corrector.replace(node
|
122
|
+
corrector.replace(node, "#{format} % #{args}")
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
@@ -5,11 +5,10 @@ module RuboCop
|
|
5
5
|
module Style
|
6
6
|
# Use a consistent style for named format string tokens.
|
7
7
|
#
|
8
|
-
#
|
9
|
-
# `unannotated` style cop only works for strings
|
8
|
+
# NOTE: `unannotated` style cop only works for strings
|
10
9
|
# which are passed as arguments to those methods:
|
11
10
|
# `printf`, `sprintf`, `format`, `%`.
|
12
|
-
# The reason is that
|
11
|
+
# The reason is that _unannotated_ format is very similar
|
13
12
|
# to encoded URLs or Date/Time formatting strings.
|
14
13
|
#
|
15
14
|
# @example EnforcedStyle: annotated (default)
|
@@ -8,8 +8,7 @@ module RuboCop
|
|
8
8
|
# It will add the comment `# frozen_string_literal: true` to the top of
|
9
9
|
# files to enable frozen string literals. Frozen string literals may be
|
10
10
|
# default in future Ruby. The comment will be added below a shebang and
|
11
|
-
# encoding comment.
|
12
|
-
# Ruby 2.3+.
|
11
|
+
# encoding comment.
|
13
12
|
#
|
14
13
|
# Note that the cop will ignore files where the comment exists but is set
|
15
14
|
# to `false` instead of `true`.
|
@@ -149,9 +148,7 @@ module RuboCop
|
|
149
148
|
end
|
150
149
|
|
151
150
|
next_token = processed_source.tokens[token_number]
|
152
|
-
if next_token && next_token.text =~ Encoding::ENCODING_PATTERN
|
153
|
-
token = next_token
|
154
|
-
end
|
151
|
+
token = next_token if next_token && next_token.text =~ Encoding::ENCODING_PATTERN
|
155
152
|
|
156
153
|
token
|
157
154
|
end
|
@@ -216,7 +213,7 @@ module RuboCop
|
|
216
213
|
if comment
|
217
214
|
corrector.insert_after(line_range(comment.line), following_comment)
|
218
215
|
else
|
219
|
-
corrector.insert_before(
|
216
|
+
corrector.insert_before(processed_source.buffer.source_range, preceding_comment)
|
220
217
|
end
|
221
218
|
end
|
222
219
|
|
@@ -35,6 +35,17 @@ module RuboCop
|
|
35
35
|
# # good
|
36
36
|
# raise 'exception' if something
|
37
37
|
# ok
|
38
|
+
#
|
39
|
+
# # bad
|
40
|
+
# if something
|
41
|
+
# foo || raise('exception')
|
42
|
+
# else
|
43
|
+
# ok
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# # good
|
47
|
+
# foo || raise('exception') if something
|
48
|
+
# ok
|
38
49
|
class GuardClause < Cop
|
39
50
|
include MinBodyLength
|
40
51
|
include StatementModifier
|
@@ -69,7 +80,8 @@ module RuboCop
|
|
69
80
|
else
|
70
81
|
opposite_keyword(node)
|
71
82
|
end
|
72
|
-
|
83
|
+
|
84
|
+
register_offense(node, guard_clause_source(guard_clause), kw)
|
73
85
|
end
|
74
86
|
|
75
87
|
private
|
@@ -98,13 +110,24 @@ module RuboCop
|
|
98
110
|
message: format(MSG, example: example))
|
99
111
|
end
|
100
112
|
|
113
|
+
def guard_clause_source(guard_clause)
|
114
|
+
parent = guard_clause.parent
|
115
|
+
|
116
|
+
if parent.and_type? || parent.or_type?
|
117
|
+
guard_clause.parent.source
|
118
|
+
else
|
119
|
+
guard_clause.source
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
101
123
|
def too_long_for_single_line?(node, example)
|
102
124
|
max = max_line_length
|
103
125
|
max && node.source_range.column + example.length > max
|
104
126
|
end
|
105
127
|
|
106
128
|
def accepted_form?(node, ending = false)
|
107
|
-
accepted_if?(node, ending) || node.condition.multiline?
|
129
|
+
accepted_if?(node, ending) || node.condition.multiline? ||
|
130
|
+
node.parent&.assignment?
|
108
131
|
end
|
109
132
|
|
110
133
|
def accepted_if?(node, ending)
|
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Style
|
6
6
|
# This cop checks for uses of `each_key` and `each_value` Hash methods.
|
7
7
|
#
|
8
|
-
#
|
8
|
+
# NOTE: If you have an array of two-element arrays, you can put
|
9
9
|
# parentheses around the block arguments to indicate that you're not
|
10
10
|
# working with a hash, and suppress RuboCop offenses.
|
11
11
|
#
|
@@ -60,7 +60,7 @@ module RuboCop
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def correct_implicit(node, corrector, method_name)
|
63
|
-
corrector.replace(node
|
63
|
+
corrector.replace(node, method_name)
|
64
64
|
correct_args(node, corrector)
|
65
65
|
end
|
66
66
|
|
@@ -70,14 +70,14 @@ module RuboCop
|
|
70
70
|
return correct_implicit(node, corrector, name) unless receiver
|
71
71
|
|
72
72
|
new_source = receiver.source + ".#{name}"
|
73
|
-
corrector.replace(node
|
73
|
+
corrector.replace(node, new_source)
|
74
74
|
end
|
75
75
|
|
76
76
|
def correct_args(node, corrector)
|
77
77
|
args = node.parent.arguments
|
78
78
|
name, = *args.children.find { |arg| used?(arg) }
|
79
79
|
|
80
|
-
corrector.replace(args
|
80
|
+
corrector.replace(args, "|#{name}|")
|
81
81
|
end
|
82
82
|
|
83
83
|
def kv_range(outer_node)
|
@@ -13,11 +13,11 @@ module RuboCop
|
|
13
13
|
# The supported styles are:
|
14
14
|
#
|
15
15
|
# * ruby19 - forces use of the 1.9 syntax (e.g. `{a: 1}`) when hashes have
|
16
|
-
#
|
16
|
+
# all symbols for keys
|
17
17
|
# * hash_rockets - forces use of hash rockets for all hashes
|
18
18
|
# * no_mixed_keys - simply checks for hashes with mixed syntaxes
|
19
19
|
# * ruby19_no_mixed_keys - forces use of ruby 1.9 syntax and forbids mixed
|
20
|
-
#
|
20
|
+
# syntax hashes
|
21
21
|
#
|
22
22
|
# @example EnforcedStyle: ruby19 (default)
|
23
23
|
# # bad
|
@@ -144,11 +144,11 @@ module RuboCop
|
|
144
144
|
# Prefer { :production? => false } over { production?: false } and
|
145
145
|
# similarly for other non-alnum final characters (except quotes,
|
146
146
|
# to prefer { "x y": 1 } over { :"x y" => 1 }).
|
147
|
-
return false unless
|
147
|
+
return false unless /[\p{Alnum}"']\z/.match?(sym_name)
|
148
148
|
end
|
149
149
|
|
150
150
|
# Most hash keys can be matched against a simple regex.
|
151
|
-
return true if
|
151
|
+
return true if /\A[_a-z]\w*[?!]?\z/i.match?(sym_name)
|
152
152
|
|
153
153
|
# For more complicated hash keys, let the parser validate the syntax.
|
154
154
|
parse("{ #{sym_name}: :foo }").valid_syntax?
|
@@ -168,11 +168,7 @@ module RuboCop
|
|
168
168
|
end
|
169
169
|
|
170
170
|
def autocorrect_ruby19(corrector, pair_node)
|
171
|
-
|
172
|
-
op = pair_node.loc.operator
|
173
|
-
|
174
|
-
range = key.join(op)
|
175
|
-
range = range_with_surrounding_space(range: range, side: :right)
|
171
|
+
range = range_for_autocorrect_ruby19(pair_node)
|
176
172
|
|
177
173
|
space = argument_without_space?(pair_node.parent) ? ' ' : ''
|
178
174
|
|
@@ -180,6 +176,19 @@ module RuboCop
|
|
180
176
|
range,
|
181
177
|
range.source.sub(/^:(.*\S)\s*=>\s*$/, space.to_s + '\1: ')
|
182
178
|
)
|
179
|
+
|
180
|
+
hash_node = pair_node.parent
|
181
|
+
return unless hash_node.parent&.return_type? && !hash_node.braces?
|
182
|
+
|
183
|
+
corrector.wrap(hash_node, '{', '}')
|
184
|
+
end
|
185
|
+
|
186
|
+
def range_for_autocorrect_ruby19(pair_node)
|
187
|
+
key = pair_node.key.source_range
|
188
|
+
operator = pair_node.loc.operator
|
189
|
+
|
190
|
+
range = key.join(operator)
|
191
|
+
range_with_surrounding_space(range: range, side: :right)
|
183
192
|
end
|
184
193
|
|
185
194
|
def argument_without_space?(node)
|
@@ -188,11 +197,9 @@ module RuboCop
|
|
188
197
|
end
|
189
198
|
|
190
199
|
def autocorrect_hash_rockets(corrector, pair_node)
|
191
|
-
key = pair_node.key.source_range
|
192
200
|
op = pair_node.loc.operator
|
193
201
|
|
194
|
-
corrector.
|
195
|
-
corrector.insert_before(key, ':')
|
202
|
+
corrector.wrap(pair_node.key, ':', pair_node.inverse_delimiter(true))
|
196
203
|
corrector.remove(range_with_surrounding_space(range: op))
|
197
204
|
end
|
198
205
|
|
@@ -24,11 +24,8 @@ module RuboCop
|
|
24
24
|
# {a: 1, b: 2}.transform_values { |v| foo(v) }
|
25
25
|
# {a: 1, b: 2}.transform_values { |v| v * v }
|
26
26
|
class HashTransformValues < Cop
|
27
|
-
extend TargetRubyVersion
|
28
27
|
include HashTransformMethod
|
29
28
|
|
30
|
-
minimum_target_ruby_version 2.4
|
31
|
-
|
32
29
|
def_node_matcher :on_bad_each_with_object, <<~PATTERN
|
33
30
|
(block
|
34
31
|
({send csend}
|