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
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# Algorithmic constants for `OpenSSL::Cipher` and `OpenSSL::Digest`
|
7
|
+
# deprecated since OpenSSL version 2.2.0. Prefer passing a string
|
8
|
+
# instead.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
# # Example for OpenSSL::Cipher instantiation.
|
13
|
+
#
|
14
|
+
# # bad
|
15
|
+
# OpenSSL::Cipher::AES.new(128, :GCM)
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# OpenSSL::Cipher.new('AES-128-GCM')
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
#
|
22
|
+
# # Example for OpenSSL::Digest instantiation.
|
23
|
+
#
|
24
|
+
# # bad
|
25
|
+
# OpenSSL::Digest::SHA256.new
|
26
|
+
#
|
27
|
+
# # good
|
28
|
+
# OpenSSL::Digest.new('SHA256')
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
#
|
32
|
+
# # Example for ::Digest inherited class methods.
|
33
|
+
#
|
34
|
+
# # bad
|
35
|
+
# OpenSSL::Digest::SHA256.digest('foo')
|
36
|
+
#
|
37
|
+
# # good
|
38
|
+
# OpenSSL::Digest.digest('SHA256', 'foo')
|
39
|
+
#
|
40
|
+
class DeprecatedOpenSSLConstant < Cop
|
41
|
+
include RangeHelp
|
42
|
+
|
43
|
+
MSG = 'Use `%<constant>s.%<method>s(%<replacement_args>s)`' \
|
44
|
+
' instead of `%<original>s`.'
|
45
|
+
|
46
|
+
def_node_matcher :algorithm_const, <<~PATTERN
|
47
|
+
(send
|
48
|
+
$(const
|
49
|
+
(const
|
50
|
+
(const {nil? cbase} :OpenSSL) {:Cipher :Digest})
|
51
|
+
_)
|
52
|
+
...)
|
53
|
+
PATTERN
|
54
|
+
|
55
|
+
def on_send(node)
|
56
|
+
return if node.arguments.any? { |arg| arg.variable? || arg.send_type? || arg.const_type? }
|
57
|
+
|
58
|
+
add_offense(node) if algorithm_const(node)
|
59
|
+
end
|
60
|
+
|
61
|
+
def autocorrect(node)
|
62
|
+
algorithm_constant, = algorithm_const(node)
|
63
|
+
|
64
|
+
lambda do |corrector|
|
65
|
+
corrector.remove(algorithm_constant.loc.double_colon)
|
66
|
+
corrector.remove(algorithm_constant.loc.name)
|
67
|
+
|
68
|
+
corrector.replace(
|
69
|
+
correction_range(node),
|
70
|
+
"#{node.loc.selector.source}(#{replacement_args(node)})"
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def message(node)
|
78
|
+
algorithm_constant, = algorithm_const(node)
|
79
|
+
parent_constant = openssl_class(algorithm_constant)
|
80
|
+
replacement_args = replacement_args(node)
|
81
|
+
method = node.loc.selector.source
|
82
|
+
|
83
|
+
format(
|
84
|
+
MSG,
|
85
|
+
constant: parent_constant,
|
86
|
+
method: method,
|
87
|
+
replacement_args: replacement_args,
|
88
|
+
original: node.source
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
def correction_range(node)
|
93
|
+
range_between(node.loc.dot.end_pos, node.loc.expression.end_pos)
|
94
|
+
end
|
95
|
+
|
96
|
+
def openssl_class(node)
|
97
|
+
node.children.first.source
|
98
|
+
end
|
99
|
+
|
100
|
+
def algorithm_name(node)
|
101
|
+
name = node.loc.name.source
|
102
|
+
|
103
|
+
if openssl_class(node) == 'OpenSSL::Cipher'
|
104
|
+
name.scan(/.{3}/).join('-')
|
105
|
+
else
|
106
|
+
name
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def sanitize_arguments(arguments)
|
111
|
+
arguments.flat_map do |arg|
|
112
|
+
argument = arg.str_type? ? arg.value : arg.source
|
113
|
+
|
114
|
+
argument.tr(":'", '').split('-')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def replacement_args(node)
|
119
|
+
algorithm_constant, = algorithm_const(node)
|
120
|
+
algorithm_name = algorithm_name(algorithm_constant)
|
121
|
+
|
122
|
+
if openssl_class(algorithm_constant) == 'OpenSSL::Cipher'
|
123
|
+
build_cipher_arguments(node, algorithm_name)
|
124
|
+
else
|
125
|
+
(["'#{algorithm_name}'"] + node.arguments.map(&:source)).join(', ')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def build_cipher_arguments(node, algorithm_name)
|
130
|
+
algorithm_parts = algorithm_name.split('-')
|
131
|
+
size_and_mode = sanitize_arguments(node.arguments)
|
132
|
+
"'#{(algorithm_parts + size_and_mode + ['CBC']).take(3).join('-')}'"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
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 `return` from an `ensure` block.
|
7
7
|
# Explicit return from an ensure block alters the control flow
|
8
8
|
# as the return will take precedence over any exception being raised,
|
9
9
|
# and the exception will be silently thrown away as if it were rescued.
|
@@ -141,9 +141,7 @@ module RuboCop
|
|
141
141
|
arguments = node.arguments
|
142
142
|
overridden_kwargs = kwargs.dup
|
143
143
|
|
144
|
-
if arguments[2]
|
145
|
-
overridden_kwargs[0] = "trim_mode: #{arguments[2].source}"
|
146
|
-
end
|
144
|
+
overridden_kwargs[0] = "trim_mode: #{arguments[2].source}" if arguments[2]
|
147
145
|
|
148
146
|
if arguments[3] && !arguments[3].hash_type?
|
149
147
|
overridden_kwargs[1] = "eoutvar: #{arguments[3].source}"
|
@@ -7,6 +7,10 @@ module RuboCop
|
|
7
7
|
# expected fields for format/sprintf/#% and what is actually
|
8
8
|
# passed as arguments.
|
9
9
|
#
|
10
|
+
# In addition it checks whether different formats are used in the same
|
11
|
+
# format string. Do not mix numbered, unnumbered, and named formats in
|
12
|
+
# the same format string.
|
13
|
+
#
|
10
14
|
# @example
|
11
15
|
#
|
12
16
|
# # bad
|
@@ -18,16 +22,37 @@ module RuboCop
|
|
18
22
|
# # good
|
19
23
|
#
|
20
24
|
# format('A value: %s and another: %i', a_value, another)
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
#
|
28
|
+
# # bad
|
29
|
+
#
|
30
|
+
# format('Unnumbered format: %s and numbered: %2$s', a_value, another)
|
31
|
+
#
|
32
|
+
# @example
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
#
|
36
|
+
# format('Numbered format: %1$s and numbered %2$s', a_value, another)
|
21
37
|
class FormatParameterMismatch < Cop
|
22
38
|
# http://rubular.com/r/CvpbxkcTzy
|
23
39
|
MSG = "Number of arguments (%<arg_num>i) to `%<method>s` doesn't " \
|
24
40
|
'match the number of fields (%<field_num>i).'
|
41
|
+
MSG_INVALID = 'Format string is invalid because formatting sequence types ' \
|
42
|
+
'(numbered, named or unnumbered) are mixed.'
|
25
43
|
|
26
44
|
KERNEL = 'Kernel'
|
27
45
|
SHOVEL = '<<'
|
28
46
|
STRING_TYPES = %i[str dstr].freeze
|
29
47
|
|
30
48
|
def on_send(node)
|
49
|
+
return unless format_string?(node)
|
50
|
+
|
51
|
+
if invalid_format_string?(node)
|
52
|
+
add_offense(node, location: :selector, message: MSG_INVALID)
|
53
|
+
return
|
54
|
+
end
|
55
|
+
|
31
56
|
return unless offending_node?(node)
|
32
57
|
|
33
58
|
add_offense(node, location: :selector)
|
@@ -35,9 +60,20 @@ module RuboCop
|
|
35
60
|
|
36
61
|
private
|
37
62
|
|
63
|
+
def format_string?(node)
|
64
|
+
called_on_string?(node) && method_with_format_args?(node)
|
65
|
+
end
|
66
|
+
|
67
|
+
def invalid_format_string?(node)
|
68
|
+
string = if sprintf?(node) || format?(node)
|
69
|
+
node.first_argument.source
|
70
|
+
else
|
71
|
+
node.receiver.source
|
72
|
+
end
|
73
|
+
!RuboCop::Cop::Utils::FormatString.new(string).valid?
|
74
|
+
end
|
75
|
+
|
38
76
|
def offending_node?(node)
|
39
|
-
return false unless called_on_string?(node)
|
40
|
-
return false unless method_with_format_args?(node)
|
41
77
|
return false if splat_args?(node)
|
42
78
|
|
43
79
|
num_of_format_args, num_of_expected_fields = count_matches(node)
|
@@ -30,6 +30,19 @@ module RuboCop
|
|
30
30
|
add_offense(node)
|
31
31
|
end
|
32
32
|
|
33
|
+
def autocorrect(node)
|
34
|
+
lambda do |corrector|
|
35
|
+
starting_token, ending_token = if node.source.include?('"')
|
36
|
+
['%{', '}']
|
37
|
+
else
|
38
|
+
['"', '"']
|
39
|
+
end
|
40
|
+
|
41
|
+
corrector.replace(node.loc.begin, starting_token)
|
42
|
+
corrector.replace(node.loc.end, ending_token)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
33
46
|
def heredoc?(node)
|
34
47
|
node.loc.is_a?(Parser::Source::Map::Heredoc) ||
|
35
48
|
(node.parent && heredoc?(node.parent))
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# Do not mix named captures and numbered captures in a Regexp literal
|
7
|
+
# because numbered capture is ignored if they're mixed.
|
8
|
+
# Replace numbered captures with non-capturing groupings or
|
9
|
+
# named captures.
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# /(?<foo>FOO)(BAR)/
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# /(?<foo>FOO)(?<bar>BAR)/
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# /(?<foo>FOO)(?:BAR)/
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# /(FOO)(BAR)/
|
22
|
+
#
|
23
|
+
class MixedRegexpCaptureTypes < Cop
|
24
|
+
MSG = 'Do not mix named captures and numbered captures ' \
|
25
|
+
'in a Regexp literal.'
|
26
|
+
|
27
|
+
def on_regexp(node)
|
28
|
+
return if contain_non_literal?(node)
|
29
|
+
|
30
|
+
begin
|
31
|
+
tree = Regexp::Parser.parse(node.content)
|
32
|
+
# Returns if a regular expression that cannot be processed by regexp_parser gem.
|
33
|
+
# https://github.com/rubocop-hq/rubocop/issues/8083
|
34
|
+
rescue Regexp::Scanner::ScannerError
|
35
|
+
return
|
36
|
+
end
|
37
|
+
|
38
|
+
return unless named_capture?(tree)
|
39
|
+
return unless numbered_capture?(tree)
|
40
|
+
|
41
|
+
add_offense(node)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def contain_non_literal?(node)
|
47
|
+
if node.respond_to?(:type) && (node.variable? || node.send_type? || node.const_type?)
|
48
|
+
return true
|
49
|
+
end
|
50
|
+
return false unless node.respond_to?(:children)
|
51
|
+
|
52
|
+
node.children.any? { |child| contain_non_literal?(child) }
|
53
|
+
end
|
54
|
+
|
55
|
+
def named_capture?(tree)
|
56
|
+
tree.each_expression.any? do |e|
|
57
|
+
e.instance_of?(Regexp::Expression::Group::Capture)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def numbered_capture?(tree)
|
62
|
+
tree.each_expression.any? do |e|
|
63
|
+
e.instance_of?(Regexp::Expression::Group::Named)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -96,7 +96,7 @@ module RuboCop
|
|
96
96
|
PATTERN
|
97
97
|
|
98
98
|
def_node_matcher :class_or_module_or_struct_new_call?, <<~PATTERN
|
99
|
-
(block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
|
99
|
+
(block (send (const {nil? cbase} {:Class :Module :Struct}) :new ...) ...)
|
100
100
|
PATTERN
|
101
101
|
end
|
102
102
|
end
|
@@ -69,11 +69,11 @@ module RuboCop
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def_node_matcher :unsorted_dir_block?, <<~PATTERN
|
72
|
-
(send (const nil? :Dir) :glob ...)
|
72
|
+
(send (const {nil? cbase} :Dir) :glob ...)
|
73
73
|
PATTERN
|
74
74
|
|
75
75
|
def_node_matcher :unsorted_dir_each?, <<~PATTERN
|
76
|
-
(send (send (const nil? :Dir) {:[] :glob} ...) :each)
|
76
|
+
(send (send (const {nil? cbase} :Dir) {:[] :glob} ...) :each)
|
77
77
|
PATTERN
|
78
78
|
|
79
79
|
def_node_matcher :loop_variable, <<~PATTERN
|
@@ -6,13 +6,13 @@ module RuboCop
|
|
6
6
|
# This cop checks for non-local exits from iterators without a return
|
7
7
|
# value. It registers an offense under these conditions:
|
8
8
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
9
|
+
# * No value is returned,
|
10
|
+
# * the block is preceded by a method chain,
|
11
|
+
# * the block has arguments,
|
12
|
+
# * the method which receives the block is not `define_method`
|
13
|
+
# or `define_singleton_method`,
|
14
|
+
# * the return is not contained in an inner scope, e.g. a lambda or a
|
15
|
+
# method definition.
|
16
16
|
#
|
17
17
|
# @example
|
18
18
|
#
|
@@ -21,9 +21,7 @@ module RuboCop
|
|
21
21
|
MSG = '`(...)` interpreted as grouped expression.'
|
22
22
|
|
23
23
|
def on_send(node)
|
24
|
-
return
|
25
|
-
return if node.operator_method? || node.setter_method?
|
26
|
-
return if grouped_parentheses?(node)
|
24
|
+
return if valid_context?(node)
|
27
25
|
|
28
26
|
space_length = spaces_before_left_parenthesis(node)
|
29
27
|
return unless space_length.positive?
|
@@ -45,10 +43,27 @@ module RuboCop
|
|
45
43
|
|
46
44
|
private
|
47
45
|
|
48
|
-
def
|
46
|
+
def valid_context?(node)
|
47
|
+
unless node.arguments.one? && first_argument_starts_with_left_parenthesis?(node)
|
48
|
+
return true
|
49
|
+
end
|
50
|
+
|
51
|
+
node.operator_method? || node.setter_method? || chained_calls?(node) ||
|
52
|
+
operator_keyword?(node)
|
53
|
+
end
|
54
|
+
|
55
|
+
def first_argument_starts_with_left_parenthesis?(node)
|
56
|
+
node.first_argument.source.start_with?('(')
|
57
|
+
end
|
58
|
+
|
59
|
+
def chained_calls?(node)
|
49
60
|
first_argument = node.first_argument
|
61
|
+
first_argument.send_type? && (node.children.last&.children&.count || 0) > 1
|
62
|
+
end
|
50
63
|
|
51
|
-
|
64
|
+
def operator_keyword?(node)
|
65
|
+
first_argument = node.first_argument
|
66
|
+
first_argument.operator_keyword?
|
52
67
|
end
|
53
68
|
|
54
69
|
def spaces_before_left_parenthesis(node)
|
@@ -48,9 +48,7 @@ module RuboCop
|
|
48
48
|
match = range.source.match(TRAILING_QUOTE)
|
49
49
|
corrector.remove_trailing(range, match[0].length) if match
|
50
50
|
|
51
|
-
if LEADING_QUOTE.match?(range.source)
|
52
|
-
corrector.remove_leading(range, 1)
|
53
|
-
end
|
51
|
+
corrector.remove_leading(range, 1) if LEADING_QUOTE.match?(range.source)
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
@@ -64,7 +62,7 @@ module RuboCop
|
|
64
62
|
# To avoid likely false positives (e.g. a single ' or ")
|
65
63
|
next if literal.gsub(/[^[[:alnum:]]]/, '').empty?
|
66
64
|
|
67
|
-
QUOTES_AND_COMMAS.any? { |pat| literal
|
65
|
+
QUOTES_AND_COMMAS.any? { |pat| literal.match?(pat) }
|
68
66
|
end
|
69
67
|
end
|
70
68
|
end
|