rubocop 0.83.0 → 0.87.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +26 -18
- data/config/default.yml +128 -23
- data/lib/rubocop.rb +21 -59
- data/lib/rubocop/ast_aliases.rb +8 -0
- data/lib/rubocop/cli.rb +2 -4
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +42 -7
- data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
- data/lib/rubocop/cli/command/show_cops.rb +2 -6
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_loader.rb +24 -70
- data/lib/rubocop/config_loader_resolver.rb +21 -9
- data/lib/rubocop/config_obsoletion.rb +0 -1
- data/lib/rubocop/config_store.rb +12 -2
- data/lib/rubocop/cop/autocorrect_logic.rb +14 -25
- data/lib/rubocop/cop/base.rb +399 -0
- data/lib/rubocop/cop/bundler/gem_comment.rb +70 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +10 -20
- data/lib/rubocop/cop/commissioner.rb +48 -71
- data/lib/rubocop/cop/cop.rb +91 -227
- data/lib/rubocop/cop/corrector.rb +38 -115
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -6
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -3
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -3
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/generator.rb +2 -2
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/ignored_node.rb +1 -3
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +11 -14
- data/lib/rubocop/cop/layout/case_indentation.rb +21 -22
- data/lib/rubocop/cop/layout/class_structure.rb +19 -16
- data/lib/rubocop/cop/layout/comment_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/empty_comment.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 +57 -4
- data/lib/rubocop/cop/layout/end_of_line.rb +3 -3
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -4
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -3
- data/lib/rubocop/cop/layout/first_array_element_line_break.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 +8 -9
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +3 -7
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +20 -103
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -3
- data/lib/rubocop/cop/layout/line_length.rb +17 -17
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -2
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -3
- data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +19 -25
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -3
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +14 -0
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -4
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -3
- data/lib/rubocop/cop/legacy/corrections_proxy.rb +49 -0
- data/lib/rubocop/cop/legacy/corrector.rb +29 -0
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +5 -2
- data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +137 -0
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -3
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +38 -2
- data/lib/rubocop/cop/lint/interpolation_check.rb +13 -0
- 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/nested_method_definition.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/parentheses_as_grouped_expression.rb +20 -5
- data/lib/rubocop/cop/lint/percent_string_array.rb +2 -4
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +12 -4
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +31 -25
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +3 -3
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +2 -2
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +9 -1
- data/lib/rubocop/cop/lint/suppressed_exception.rb +15 -2
- data/lib/rubocop/cop/lint/syntax.rb +11 -28
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/unused_method_argument.rb +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -4
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +22 -0
- data/lib/rubocop/cop/metrics/class_length.rb +25 -2
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +35 -3
- data/lib/rubocop/cop/metrics/method_length.rb +23 -0
- data/lib/rubocop/cop/metrics/module_length.rb +25 -2
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +129 -0
- data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
- data/lib/rubocop/cop/migration/department_name.rb +7 -7
- data/lib/rubocop/cop/mixin/alignment.rb +1 -3
- data/lib/rubocop/cop/mixin/allowed_methods.rb +19 -0
- data/lib/rubocop/cop/mixin/array_min_size.rb +1 -3
- data/lib/rubocop/cop/mixin/auto_corrector.rb +12 -0
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -9
- data/lib/rubocop/cop/mixin/code_length.rb +4 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -3
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +3 -5
- data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +3 -1
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/nil_methods.rb +3 -5
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +6 -1
- data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +1 -1
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +43 -0
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +10 -5
- data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -13
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +7 -5
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +27 -4
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +3 -3
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +11 -1
- data/lib/rubocop/cop/naming/file_name.rb +28 -17
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +1 -1
- data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +4 -6
- data/lib/rubocop/cop/naming/variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/variable_number.rb +1 -1
- data/lib/rubocop/cop/offense.rb +16 -2
- data/lib/rubocop/cop/registry.rb +63 -10
- data/lib/rubocop/cop/severity.rb +1 -3
- data/lib/rubocop/cop/style/accessor_grouping.rb +136 -0
- data/lib/rubocop/cop/style/and_or.rb +2 -2
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +2 -2
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +121 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +4 -12
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/class_vars.rb +21 -0
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -4
- data/lib/rubocop/cop/style/copyright.rb +5 -5
- data/lib/rubocop/cop/style/date_time.rb +1 -1
- data/lib/rubocop/cop/style/dir.rb +2 -2
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +2 -2
- data/lib/rubocop/cop/style/double_negation.rb +41 -4
- data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
- data/lib/rubocop/cop/style/empty_literal.rb +6 -8
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
- data/lib/rubocop/cop/style/exponential_notation.rb +5 -5
- 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/hash_each_methods.rb +1 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +16 -7
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
- data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -0
- data/lib/rubocop/cop/style/inline_comment.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
- 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/multiline_block_chain.rb +10 -1
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +17 -6
- data/lib/rubocop/cop/style/mutable_constant.rb +4 -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/nested_parenthesized_calls.rb +2 -5
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +27 -0
- data/lib/rubocop/cop/style/next.rb +2 -2
- data/lib/rubocop/cop/style/non_nil_check.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -6
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +4 -10
- data/lib/rubocop/cop/style/redundant_assignment.rb +117 -0
- data/lib/rubocop/cop/style/redundant_conditional.rb +4 -3
- data/lib/rubocop/cop/style/redundant_exception.rb +14 -10
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +122 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +10 -8
- data/lib/rubocop/cop/style/redundant_percent_q.rb +3 -3
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +90 -0
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +121 -0
- data/lib/rubocop/cop/style/redundant_self.rb +6 -9
- data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -6
- data/lib/rubocop/cop/style/sample.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/signal_exception.rb +1 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +2 -6
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +23 -2
- data/lib/rubocop/cop/style/symbol_array.rb +5 -5
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +3 -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 +13 -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 +8 -7
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +18 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +2 -2
- data/lib/rubocop/cop/team.rb +141 -81
- data/lib/rubocop/cop/util.rb +3 -3
- data/lib/rubocop/cop/utils/format_string.rb +19 -2
- data/lib/rubocop/cop/variable_force.rb +3 -9
- data/lib/rubocop/cop/variable_force/branch.rb +1 -3
- data/lib/rubocop/cop/variable_force/variable.rb +2 -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 +5 -13
- data/lib/rubocop/formatter/formatter_set.rb +2 -4
- data/lib/rubocop/formatter/junit_formatter.rb +14 -4
- data/lib/rubocop/magic_comment.rb +1 -1
- data/lib/rubocop/name_similarity.rb +7 -3
- data/lib/rubocop/options.rb +30 -15
- data/lib/rubocop/path_util.rb +2 -2
- data/lib/rubocop/platform.rb +1 -1
- data/lib/rubocop/rake_task.rb +6 -9
- data/lib/rubocop/remote_config.rb +1 -3
- data/lib/rubocop/result_cache.rb +5 -7
- data/lib/rubocop/rspec/cop_helper.rb +5 -28
- data/lib/rubocop/rspec/expect_offense.rb +60 -23
- data/lib/rubocop/rspec/shared_contexts.rb +55 -17
- data/lib/rubocop/runner.rb +42 -38
- data/lib/rubocop/target_finder.rb +2 -4
- data/lib/rubocop/target_ruby.rb +5 -2
- data/lib/rubocop/version.rb +5 -3
- metadata +60 -62
- 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 -70
- 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 -269
- 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 -17
- 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/cop/mixin/classish_length.rb +0 -37
- data/lib/rubocop/node_pattern.rb +0 -887
- data/lib/rubocop/processed_source.rb +0 -213
- data/lib/rubocop/token.rb +0 -114
@@ -31,12 +31,12 @@ module RuboCop
|
|
31
31
|
MSG = 'Use `StandardError` over `Exception`.'
|
32
32
|
|
33
33
|
def_node_matcher :exception?, <<~PATTERN
|
34
|
-
(send nil? {:raise :fail} (const ${cbase nil?} :Exception) ... )
|
34
|
+
(send nil? {:raise :fail} $(const ${cbase nil?} :Exception) ... )
|
35
35
|
PATTERN
|
36
36
|
|
37
37
|
def_node_matcher :exception_new_with_message?, <<~PATTERN
|
38
38
|
(send nil? {:raise :fail}
|
39
|
-
(send (const ${cbase nil?} :Exception) :new ... ))
|
39
|
+
(send $(const ${cbase nil?} :Exception) :new ... ))
|
40
40
|
PATTERN
|
41
41
|
|
42
42
|
def on_send(node)
|
@@ -44,13 +44,21 @@ module RuboCop
|
|
44
44
|
exception_new_with_message?(node, &check(node))
|
45
45
|
end
|
46
46
|
|
47
|
+
def autocorrect(node)
|
48
|
+
lambda do |corrector|
|
49
|
+
exception_class = node.children.first&.cbase_type? ? '::StandardError' : 'StandardError'
|
50
|
+
|
51
|
+
corrector.replace(node, exception_class)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
47
55
|
private
|
48
56
|
|
49
57
|
def check(node)
|
50
|
-
lambda do |cbase|
|
58
|
+
lambda do |exception_class, cbase|
|
51
59
|
return if cbase.nil? && implicit_namespace?(node)
|
52
60
|
|
53
|
-
add_offense(
|
61
|
+
add_offense(exception_class)
|
54
62
|
end
|
55
63
|
end
|
56
64
|
|
@@ -25,7 +25,7 @@ module RuboCop
|
|
25
25
|
'Perhaps you meant `rand(2)` or `rand`?'
|
26
26
|
|
27
27
|
def_node_matcher :rand_one?, <<~PATTERN
|
28
|
-
(send {(const nil? :Kernel) nil?} :rand {(int {-1 1}) (float {-1.0 1.0})})
|
28
|
+
(send {(const {nil? cbase} :Kernel) nil?} :rand {(int {-1 1}) (float {-1.0 1.0})})
|
29
29
|
PATTERN
|
30
30
|
|
31
31
|
def on_send(node)
|
@@ -25,34 +25,34 @@ module RuboCop
|
|
25
25
|
#
|
26
26
|
# # good
|
27
27
|
# x += 1
|
28
|
-
class RedundantCopDisableDirective <
|
28
|
+
class RedundantCopDisableDirective < Base
|
29
29
|
include RangeHelp
|
30
|
+
extend AutoCorrector
|
30
31
|
|
31
32
|
COP_NAME = 'Lint/RedundantCopDisableDirective'
|
32
33
|
|
33
|
-
|
34
|
+
attr_accessor :offenses_to_check
|
35
|
+
|
36
|
+
def initialize(config = nil, options = nil, offenses = nil)
|
37
|
+
@offenses_to_check = offenses
|
38
|
+
super(config, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def on_new_investigation
|
42
|
+
return unless offenses_to_check
|
43
|
+
|
44
|
+
comments = processed_source.comments
|
45
|
+
cop_disabled_line_ranges = processed_source.disabled_line_ranges
|
46
|
+
|
34
47
|
redundant_cops = Hash.new { |h, k| h[k] = Set.new }
|
35
48
|
|
36
49
|
each_redundant_disable(cop_disabled_line_ranges,
|
37
|
-
|
50
|
+
offenses_to_check, comments) do |comment, redundant_cop|
|
38
51
|
redundant_cops[comment].add(redundant_cop)
|
39
52
|
end
|
40
53
|
|
41
54
|
add_offenses(redundant_cops)
|
42
|
-
|
43
|
-
|
44
|
-
def autocorrect(args)
|
45
|
-
lambda do |corrector|
|
46
|
-
ranges, range = *args # Ranges are sorted by position.
|
47
|
-
|
48
|
-
range = if range.source.start_with?('#')
|
49
|
-
comment_range_with_surrounding_space(range)
|
50
|
-
else
|
51
|
-
directive_range_in_list(range, ranges)
|
52
|
-
end
|
53
|
-
|
54
|
-
corrector.remove(range)
|
55
|
-
end
|
55
|
+
super
|
56
56
|
end
|
57
57
|
|
58
58
|
private
|
@@ -135,6 +135,7 @@ module RuboCop
|
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
+
# rubocop:todo Metrics/CyclomaticComplexity
|
138
139
|
def find_redundant(comment, offenses, cop, line_range, next_line_range)
|
139
140
|
if all_disabled?(comment)
|
140
141
|
# If there's a disable all comment followed by a comment
|
@@ -152,9 +153,10 @@ module RuboCop
|
|
152
153
|
cop if cop_offenses.none? { |o| line_range.cover?(o.line) }
|
153
154
|
end
|
154
155
|
end
|
156
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
155
157
|
|
156
158
|
def all_disabled?(comment)
|
157
|
-
|
159
|
+
/rubocop\s*:\s*(?:disable|todo)\s+all\b/.match?(comment.text)
|
158
160
|
end
|
159
161
|
|
160
162
|
def ignore_offense?(disabled_ranges, line_range)
|
@@ -185,10 +187,12 @@ module RuboCop
|
|
185
187
|
cop_list = cops.sort.map { |c| describe(c) }
|
186
188
|
|
187
189
|
add_offense(
|
188
|
-
|
189
|
-
location: location,
|
190
|
+
location,
|
190
191
|
message: "Unnecessary disabling of #{cop_list.join(', ')}."
|
191
|
-
)
|
192
|
+
) do |corrector|
|
193
|
+
range = comment_range_with_surrounding_space(location)
|
194
|
+
corrector.remove(range)
|
195
|
+
end
|
192
196
|
end
|
193
197
|
|
194
198
|
def add_offense_for_some_cops(comment, cops)
|
@@ -198,10 +202,12 @@ module RuboCop
|
|
198
202
|
|
199
203
|
cop_ranges.each do |cop, range|
|
200
204
|
add_offense(
|
201
|
-
|
202
|
-
location: range,
|
205
|
+
range,
|
203
206
|
message: "Unnecessary disabling of #{describe(cop)}."
|
204
|
-
)
|
207
|
+
) do |corrector|
|
208
|
+
range = directive_range_in_list(range, ranges)
|
209
|
+
corrector.remove(range)
|
210
|
+
end
|
205
211
|
end
|
206
212
|
end
|
207
213
|
|
@@ -225,7 +231,7 @@ module RuboCop
|
|
225
231
|
.drop_while { |r| !r.equal?(range) }
|
226
232
|
.each_cons(2)
|
227
233
|
.map { |range1, range2| range1.end.join(range2.begin).source }
|
228
|
-
.all? { |intervening|
|
234
|
+
.all? { |intervening| /\A\s*,\s*\Z/.match?(intervening) }
|
229
235
|
end
|
230
236
|
|
231
237
|
def describe(cop)
|
@@ -8,9 +8,9 @@ module RuboCop
|
|
8
8
|
# The following features are unnecessary `require` statement because
|
9
9
|
# they are already loaded.
|
10
10
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
11
|
+
# ruby -ve 'p $LOADED_FEATURES.reject { |feature| %r|/| =~ feature }'
|
12
|
+
# ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-darwin13]
|
13
|
+
# ["enumerator.so", "rational.so", "complex.so", "thread.rb"]
|
14
14
|
#
|
15
15
|
# This cop targets Ruby 2.2 or higher containing these 4 features.
|
16
16
|
#
|
@@ -60,8 +60,8 @@ module RuboCop
|
|
60
60
|
|
61
61
|
def_node_matcher :array_new?, <<~PATTERN
|
62
62
|
{
|
63
|
-
$(send (const nil? :Array) :new ...)
|
64
|
-
$(block (send (const nil? :Array) :new ...) ...)
|
63
|
+
$(send (const {nil? cbase} :Array) :new ...)
|
64
|
+
$(block (send (const {nil? cbase} :Array) :new ...) ...)
|
65
65
|
}
|
66
66
|
PATTERN
|
67
67
|
|
@@ -30,7 +30,15 @@ module RuboCop
|
|
30
30
|
def on_if(node)
|
31
31
|
return unless safe_navigation_empty_in_conditional?(node)
|
32
32
|
|
33
|
-
add_offense(node)
|
33
|
+
add_offense(node.condition)
|
34
|
+
end
|
35
|
+
|
36
|
+
def autocorrect(node)
|
37
|
+
lambda do |corrector|
|
38
|
+
receiver = node.receiver.source
|
39
|
+
|
40
|
+
corrector.replace(node, "#{receiver} && #{receiver}.#{node.method_name}")
|
41
|
+
end
|
34
42
|
end
|
35
43
|
end
|
36
44
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Lint
|
6
|
-
# This cop checks for
|
6
|
+
# This cop checks for `rescue` blocks with no body.
|
7
7
|
#
|
8
8
|
# @example
|
9
9
|
#
|
@@ -69,10 +69,23 @@ module RuboCop
|
|
69
69
|
|
70
70
|
def on_resbody(node)
|
71
71
|
return if node.body
|
72
|
-
return if cop_config['AllowComments'] &&
|
72
|
+
return if cop_config['AllowComments'] && comment_between_rescue_and_end?(node)
|
73
73
|
|
74
74
|
add_offense(node)
|
75
75
|
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def comment_between_rescue_and_end?(node)
|
80
|
+
end_line = nil
|
81
|
+
node.each_ancestor(:kwbegin, :def, :defs, :block) do |ancestor|
|
82
|
+
end_line = ancestor.loc.end.line
|
83
|
+
break
|
84
|
+
end
|
85
|
+
return false unless end_line
|
86
|
+
|
87
|
+
processed_source[node.first_line...end_line].any? { |line| comment_line?(line) }
|
88
|
+
end
|
76
89
|
end
|
77
90
|
end
|
78
91
|
end
|
@@ -3,51 +3,34 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Lint
|
6
|
-
# This
|
7
|
-
# provides methods to repack Parser's diagnostics/errors
|
6
|
+
# This cop repacks Parser's diagnostics/errors
|
8
7
|
# into RuboCop's offenses.
|
9
|
-
class Syntax <
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
ERROR_SOURCE_RANGE = PseudoSourceRange.new(1, 0, '', 0, 1).freeze
|
14
|
-
|
15
|
-
def self.offenses_from_processed_source(processed_source,
|
16
|
-
config, options)
|
17
|
-
cop = new(config, options)
|
18
|
-
|
19
|
-
if processed_source.parser_error
|
20
|
-
cop.add_offense_from_error(processed_source.parser_error)
|
21
|
-
end
|
22
|
-
|
8
|
+
class Syntax < Base
|
9
|
+
def on_other_file
|
10
|
+
add_offense_from_error(processed_source.parser_error) if processed_source.parser_error
|
23
11
|
processed_source.diagnostics.each do |diagnostic|
|
24
|
-
|
25
|
-
|
12
|
+
add_offense_from_diagnostic(diagnostic,
|
13
|
+
processed_source.ruby_version)
|
26
14
|
end
|
27
|
-
|
28
|
-
cop.offenses
|
15
|
+
super
|
29
16
|
end
|
30
17
|
|
18
|
+
private
|
19
|
+
|
31
20
|
def add_offense_from_diagnostic(diagnostic, ruby_version)
|
32
21
|
message =
|
33
22
|
"#{diagnostic.message}\n(Using Ruby #{ruby_version} parser; " \
|
34
23
|
'configure using `TargetRubyVersion` parameter, under `AllCops`)'
|
35
|
-
add_offense(
|
36
|
-
location: diagnostic.location,
|
24
|
+
add_offense(diagnostic.location,
|
37
25
|
message: message,
|
38
26
|
severity: diagnostic.level)
|
39
27
|
end
|
40
28
|
|
41
29
|
def add_offense_from_error(error)
|
42
30
|
message = beautify_message(error.message)
|
43
|
-
|
44
|
-
location: ERROR_SOURCE_RANGE,
|
45
|
-
message: message,
|
46
|
-
severity: :fatal)
|
31
|
+
add_global_offense(message, severity: :fatal)
|
47
32
|
end
|
48
33
|
|
49
|
-
private
|
50
|
-
|
51
34
|
def beautify_message(message)
|
52
35
|
message = message.capitalize
|
53
36
|
message << '.' unless message.end_with?('.')
|
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Lint
|
6
6
|
# This cop checks for unreachable code.
|
7
7
|
# The check are based on the presence of flow of control
|
8
|
-
# statement in non-final position in
|
8
|
+
# statement in non-final position in `begin` (implicit) blocks.
|
9
9
|
#
|
10
10
|
# @example
|
11
11
|
#
|
@@ -172,7 +172,7 @@ module RuboCop
|
|
172
172
|
PATTERN
|
173
173
|
|
174
174
|
def_node_matcher :class_or_module_or_struct_new_call?, <<~PATTERN
|
175
|
-
(block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
|
175
|
+
(block (send (const {nil? cbase} {:Class :Module :Struct}) :new ...) ...)
|
176
176
|
PATTERN
|
177
177
|
|
178
178
|
def check_node(node)
|
@@ -227,9 +227,7 @@ module RuboCop
|
|
227
227
|
add_offense(node, message: format(MSG, current: cur_vis))
|
228
228
|
else
|
229
229
|
# was the previous modifier never applied to any defs?
|
230
|
-
if unused
|
231
|
-
add_offense(unused, message: format(MSG, current: cur_vis))
|
232
|
-
end
|
230
|
+
add_offense(unused, message: format(MSG, current: cur_vis)) if unused
|
233
231
|
# once we have already warned about a certain modifier, don't
|
234
232
|
# warn again even if it is never applied to any method defs
|
235
233
|
unused = node
|
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Lint
|
6
6
|
# This cop checks for useless `else` in `begin..end` without `rescue`.
|
7
7
|
#
|
8
|
-
#
|
8
|
+
# NOTE: This syntax is no longer valid on Ruby 2.6 or higher and
|
9
9
|
# this cop is going to be removed at some point the future.
|
10
10
|
#
|
11
11
|
# @example
|
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
# This cop checks for setter call to local variable as the final
|
7
7
|
# expression of a function definition.
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# NOTE: There are edge cases in which the local variable references a
|
10
10
|
# value that is also accessible outside the local scope. This is not
|
11
11
|
# detected by the cop, and it can yield a false positive.
|
12
12
|
#
|
@@ -7,6 +7,28 @@ module RuboCop
|
|
7
7
|
# Comment lines can optionally be ignored.
|
8
8
|
# The maximum allowed length is configurable.
|
9
9
|
# The cop can be configured to ignore blocks passed to certain methods.
|
10
|
+
#
|
11
|
+
# You can set literals you want to fold with `CountAsOne`.
|
12
|
+
# Available are: 'array', 'hash', and 'heredoc'. Each literal
|
13
|
+
# will be counted as one line regardless of its actual size.
|
14
|
+
#
|
15
|
+
# @example CountAsOne: ['array', 'heredoc']
|
16
|
+
#
|
17
|
+
# something do
|
18
|
+
# array = [ # +1
|
19
|
+
# 1,
|
20
|
+
# 2
|
21
|
+
# ]
|
22
|
+
#
|
23
|
+
# hash = { # +3
|
24
|
+
# key: 'value'
|
25
|
+
# }
|
26
|
+
#
|
27
|
+
# msg = <<~HEREDOC # +1
|
28
|
+
# Heredoc
|
29
|
+
# content.
|
30
|
+
# HEREDOC
|
31
|
+
# end # 5 points
|
10
32
|
class BlockLength < Cop
|
11
33
|
include TooManyLines
|
12
34
|
|
@@ -6,8 +6,31 @@ module RuboCop
|
|
6
6
|
# This cop checks if the length a class exceeds some maximum value.
|
7
7
|
# Comment lines can optionally be ignored.
|
8
8
|
# The maximum allowed length is configurable.
|
9
|
+
#
|
10
|
+
# You can set literals you want to fold with `CountAsOne`.
|
11
|
+
# Available are: 'array', 'hash', and 'heredoc'. Each literal
|
12
|
+
# will be counted as one line regardless of its actual size.
|
13
|
+
#
|
14
|
+
# @example CountAsOne: ['array', 'heredoc']
|
15
|
+
#
|
16
|
+
# class Foo
|
17
|
+
# ARRAY = [ # +1
|
18
|
+
# 1,
|
19
|
+
# 2
|
20
|
+
# ]
|
21
|
+
#
|
22
|
+
# HASH = { # +3
|
23
|
+
# key: 'value'
|
24
|
+
# }
|
25
|
+
#
|
26
|
+
# MSG = <<~HEREDOC # +1
|
27
|
+
# Heredoc
|
28
|
+
# content.
|
29
|
+
# HEREDOC
|
30
|
+
# end # 5 points
|
31
|
+
#
|
9
32
|
class ClassLength < Cop
|
10
|
-
include
|
33
|
+
include TooManyLines
|
11
34
|
|
12
35
|
def on_class(node)
|
13
36
|
check_code_length(node)
|
@@ -22,7 +45,7 @@ module RuboCop
|
|
22
45
|
private
|
23
46
|
|
24
47
|
def_node_matcher :class_definition?, <<~PATTERN
|
25
|
-
(casgn nil? _ (block (send (const nil? :Class) :new) ...))
|
48
|
+
(casgn nil? _ (block (send (const {nil? cbase} :Class) :new) ...))
|
26
49
|
PATTERN
|
27
50
|
|
28
51
|
def message(length, max_length)
|