rubocop 0.50.0 → 0.51.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -6
- data/config/default.yml +20 -11
- data/config/enabled.yml +44 -7
- data/lib/rubocop.rb +526 -514
- data/lib/rubocop/ast/node.rb +9 -9
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +2 -2
- data/lib/rubocop/ast/node/send_node.rb +4 -0
- data/lib/rubocop/cached_data.rb +1 -6
- data/lib/rubocop/cli.rb +7 -6
- data/lib/rubocop/config.rb +58 -22
- data/lib/rubocop/config_loader.rb +37 -21
- data/lib/rubocop/config_loader_resolver.rb +3 -2
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +5 -3
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +4 -2
- data/lib/rubocop/cop/bundler/ordered_gems.rb +2 -53
- data/lib/rubocop/cop/commissioner.rb +1 -4
- data/lib/rubocop/cop/cop.rb +50 -17
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +96 -0
- data/lib/rubocop/cop/generator.rb +8 -3
- data/lib/rubocop/cop/internal_affairs.rb +6 -5
- data/lib/rubocop/cop/internal_affairs/deprecated_positional_arguments.rb +81 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +21 -11
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +27 -14
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +38 -16
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -2
- data/lib/rubocop/cop/layout/block_end_newline.rb +1 -1
- data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +4 -2
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +5 -2
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
- data/lib/rubocop/cop/layout/end_of_line.rb +1 -1
- data/lib/rubocop/cop/layout/extra_spacing.rb +2 -2
- data/lib/rubocop/cop/layout/indent_array.rb +1 -1
- data/lib/rubocop/cop/layout/indent_hash.rb +1 -1
- data/lib/rubocop/cop/layout/indent_heredoc.rb +2 -2
- data/lib/rubocop/cop/layout/indentation_width.rb +7 -5
- data/lib/rubocop/cop/layout/initial_indentation.rb +3 -2
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +2 -2
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -1
- data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
- data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -2
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +4 -4
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +6 -2
- data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +5 -2
- data/lib/rubocop/cop/layout/space_inside_parens.rb +9 -0
- data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/layout/tab.rb +5 -2
- data/lib/rubocop/cop/layout/trailing_blank_lines.rb +4 -2
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +3 -14
- data/lib/rubocop/cop/lint/debugger.rb +7 -7
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
- data/lib/rubocop/cop/lint/duplicate_methods.rb +5 -3
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/empty_expression.rb +1 -1
- data/lib/rubocop/cop/lint/empty_when.rb +1 -1
- data/lib/rubocop/cop/lint/end_in_method.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +4 -3
- data/lib/rubocop/cop/lint/interpolation_check.rb +2 -1
- data/lib/rubocop/cop/lint/{literal_in_condition.rb → literal_as_condition.rb} +19 -5
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +2 -2
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +3 -2
- data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
- data/lib/rubocop/cop/lint/rand_one.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_object.rb +81 -0
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +29 -0
- data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +5 -3
- data/lib/rubocop/cop/lint/rescue_without_error_class.rb +6 -3
- data/lib/rubocop/cop/lint/return_in_void_context.rb +24 -13
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
- data/lib/rubocop/cop/lint/script_permission.rb +1 -1
- data/lib/rubocop/cop/lint/shadowed_exception.rb +37 -10
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/syntax.rb +8 -2
- data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +1 -1
- data/lib/rubocop/cop/lint/unified_integer.rb +2 -2
- data/lib/rubocop/cop/lint/unneeded_disable.rb +11 -4
- data/lib/rubocop/cop/lint/unneeded_require_statement.rb +50 -0
- data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +2 -2
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -1
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -2
- data/lib/rubocop/cop/lint/uri_regexp.rb +3 -3
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +9 -9
- data/lib/rubocop/cop/lint/useless_assignment.rb +1 -1
- data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +5 -1
- data/lib/rubocop/cop/lint/void.rb +10 -5
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
- data/lib/rubocop/cop/metrics/line_length.rb +4 -1
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -2
- data/lib/rubocop/cop/mixin/array_hash_indentation.rb +3 -2
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -1
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +7 -2
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +1 -1
- data/lib/rubocop/cop/mixin/heredoc.rb +1 -1
- data/lib/rubocop/cop/mixin/method_complexity.rb +3 -4
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +10 -4
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +63 -0
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +4 -1
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -1
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +2 -1
- data/lib/rubocop/cop/mixin/space_inside.rb +1 -1
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +5 -5
- data/lib/rubocop/cop/mixin/unused_argument.rb +43 -2
- data/lib/rubocop/cop/naming/accessor_method_name.rb +8 -7
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +1 -1
- data/lib/rubocop/cop/naming/file_name.rb +1 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +1 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +3 -2
- data/lib/rubocop/cop/naming/predicate_name.rb +36 -5
- data/lib/rubocop/cop/performance/caller.rb +2 -2
- data/lib/rubocop/cop/performance/case_when_splat.rb +1 -1
- data/lib/rubocop/cop/performance/casecmp.rb +1 -1
- data/lib/rubocop/cop/performance/compare_with_block.rb +6 -2
- data/lib/rubocop/cop/performance/count.rb +3 -1
- data/lib/rubocop/cop/performance/detect.rb +4 -4
- data/lib/rubocop/cop/performance/double_start_end_with.rb +6 -9
- data/lib/rubocop/cop/performance/end_with.rb +1 -1
- data/lib/rubocop/cop/performance/flat_map.rb +3 -1
- data/lib/rubocop/cop/performance/hash_each_methods.rb +13 -10
- data/lib/rubocop/cop/performance/lstrip_rstrip.rb +3 -1
- data/lib/rubocop/cop/performance/range_include.rb +1 -1
- data/lib/rubocop/cop/performance/redundant_block_call.rb +1 -1
- data/lib/rubocop/cop/performance/redundant_match.rb +6 -5
- data/lib/rubocop/cop/performance/redundant_merge.rb +1 -1
- data/lib/rubocop/cop/performance/redundant_sort_by.rb +4 -1
- data/lib/rubocop/cop/performance/regexp_match.rb +4 -4
- data/lib/rubocop/cop/performance/reverse_each.rb +1 -1
- data/lib/rubocop/cop/performance/sample.rb +1 -1
- data/lib/rubocop/cop/performance/size.rb +1 -1
- data/lib/rubocop/cop/performance/start_with.rb +1 -1
- data/lib/rubocop/cop/performance/string_replacement.rb +2 -2
- data/lib/rubocop/cop/performance/times_map.rb +3 -3
- data/lib/rubocop/cop/performance/unfreeze_string.rb +2 -2
- data/lib/rubocop/cop/performance/uri_default_parser.rb +2 -2
- data/lib/rubocop/cop/rails/action_filter.rb +1 -1
- data/lib/rubocop/cop/rails/active_support_aliases.rb +1 -2
- data/lib/rubocop/cop/rails/application_job.rb +1 -1
- data/lib/rubocop/cop/rails/application_record.rb +1 -1
- data/lib/rubocop/cop/rails/blank.rb +20 -17
- data/lib/rubocop/cop/rails/date.rb +7 -6
- data/lib/rubocop/cop/rails/delegate.rb +1 -1
- data/lib/rubocop/cop/rails/delegate_allow_blank.rb +1 -1
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +2 -2
- data/lib/rubocop/cop/rails/enum_uniqueness.rb +2 -2
- data/lib/rubocop/cop/rails/exit.rb +1 -1
- data/lib/rubocop/cop/rails/file_path.rb +6 -8
- data/lib/rubocop/cop/rails/find_by.rb +2 -1
- data/lib/rubocop/cop/rails/find_each.rb +1 -1
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +35 -11
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +3 -2
- data/lib/rubocop/cop/rails/not_null_column.rb +5 -5
- data/lib/rubocop/cop/rails/output.rb +2 -2
- data/lib/rubocop/cop/rails/output_safety.rb +2 -1
- data/lib/rubocop/cop/rails/present.rb +14 -17
- data/lib/rubocop/cop/rails/read_write_attribute.rb +3 -3
- data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
- data/lib/rubocop/cop/rails/request_referer.rb +2 -2
- data/lib/rubocop/cop/rails/reversible_migration.rb +21 -19
- data/lib/rubocop/cop/rails/safe_navigation.rb +2 -2
- data/lib/rubocop/cop/rails/save_bang.rb +12 -12
- data/lib/rubocop/cop/rails/scope_args.rb +1 -1
- data/lib/rubocop/cop/rails/skips_model_validations.rb +2 -2
- data/lib/rubocop/cop/rails/time_zone.rb +3 -2
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +3 -1
- data/lib/rubocop/cop/rails/unknown_env.rb +63 -0
- data/lib/rubocop/cop/rails/validation.rb +1 -1
- data/lib/rubocop/cop/registry.rb +2 -1
- data/lib/rubocop/cop/security/eval.rb +2 -2
- data/lib/rubocop/cop/security/json_load.rb +2 -2
- data/lib/rubocop/cop/security/marshal_load.rb +3 -3
- data/lib/rubocop/cop/security/yaml_load.rb +2 -2
- data/lib/rubocop/cop/style/alias.rb +3 -3
- data/lib/rubocop/cop/style/and_or.rb +1 -1
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -1
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +2 -2
- data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
- data/lib/rubocop/cop/style/begin_block.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +22 -19
- data/lib/rubocop/cop/style/case_equality.rb +1 -1
- data/lib/rubocop/cop/style/class_and_module_children.rb +2 -2
- data/lib/rubocop/cop/style/class_check.rb +1 -1
- data/lib/rubocop/cop/style/class_methods.rb +2 -1
- data/lib/rubocop/cop/style/class_vars.rb +1 -1
- data/lib/rubocop/cop/style/collection_methods.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
- data/lib/rubocop/cop/style/comment_annotation.rb +5 -2
- data/lib/rubocop/cop/style/commented_keyword.rb +81 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
- data/lib/rubocop/cop/style/copyright.rb +1 -1
- data/lib/rubocop/cop/style/date_time.rb +44 -0
- data/lib/rubocop/cop/style/def_with_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/dir.rb +2 -6
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +1 -1
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
- data/lib/rubocop/cop/style/each_with_object.rb +2 -1
- data/lib/rubocop/cop/style/empty_case_condition.rb +1 -1
- data/lib/rubocop/cop/style/empty_else.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +9 -9
- data/lib/rubocop/cop/style/encoding.rb +7 -51
- data/lib/rubocop/cop/style/end_block.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/for.rb +6 -2
- data/lib/rubocop/cop/style/format_string.rb +4 -3
- data/lib/rubocop/cop/style/format_string_token.rb +2 -1
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -3
- data/lib/rubocop/cop/style/global_vars.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +2 -2
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -3
- data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -1
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +2 -1
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +2 -2
- data/lib/rubocop/cop/style/infinite_loop.rb +2 -2
- data/lib/rubocop/cop/style/inverse_methods.rb +4 -6
- data/lib/rubocop/cop/style/lambda.rb +3 -3
- data/lib/rubocop/cop/style/line_end_concatenation.rb +1 -1
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -1
- data/lib/rubocop/cop/style/method_def_parentheses.rb +4 -2
- data/lib/rubocop/cop/style/min_max.rb +2 -1
- data/lib/rubocop/cop/style/mixin_usage.rb +73 -0
- data/lib/rubocop/cop/style/module_function.rb +2 -2
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
- data/lib/rubocop/cop/style/multiline_if_then.rb +2 -1
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/nested_modifier.rb +1 -1
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +3 -1
- data/lib/rubocop/cop/style/next.rb +2 -1
- data/lib/rubocop/cop/style/nil_comparison.rb +2 -2
- data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +2 -2
- data/lib/rubocop/cop/style/option_hash.rb +0 -11
- data/lib/rubocop/cop/style/or_assignment.rb +1 -1
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +4 -4
- data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +1 -1
- data/lib/rubocop/cop/style/regexp_literal.rb +2 -2
- data/lib/rubocop/cop/style/return_nil.rb +2 -7
- data/lib/rubocop/cop/style/safe_navigation.rb +27 -30
- data/lib/rubocop/cop/style/self_assignment.rb +2 -2
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/send.rb +1 -1
- data/lib/rubocop/cop/style/signal_exception.rb +4 -3
- data/lib/rubocop/cop/style/stderr_puts.rb +52 -0
- data/lib/rubocop/cop/style/string_literals.rb +4 -3
- data/lib/rubocop/cop/style/string_methods.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +3 -3
- data/lib/rubocop/cop/style/symbol_array.rb +1 -5
- data/lib/rubocop/cop/style/symbol_proc.rb +5 -5
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +46 -23
- data/lib/rubocop/cop/style/trivial_accessors.rb +3 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +0 -2
- data/lib/rubocop/cop/style/when_then.rb +1 -1
- data/lib/rubocop/cop/style/while_until_do.rb +2 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +2 -1
- data/lib/rubocop/cop/style/word_array.rb +2 -2
- data/lib/rubocop/cop/style/zero_length_predicate.rb +4 -4
- data/lib/rubocop/cop/util.rb +1 -12
- data/lib/rubocop/formatter/html_formatter.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +2 -2
- data/lib/rubocop/node_pattern.rb +1 -1
- data/lib/rubocop/options.rb +4 -0
- data/lib/rubocop/processed_source.rb +2 -8
- data/lib/rubocop/rake_task.rb +16 -23
- data/lib/rubocop/remote_config.rb +8 -0
- data/lib/rubocop/rspec/shared_contexts.rb +0 -8
- data/lib/rubocop/rspec/support.rb +5 -5
- data/lib/rubocop/version.rb +1 -1
- metadata +40 -30
- data/lib/rubocop/cop/lint/invalid_character_literal.rb +0 -41
@@ -26,8 +26,8 @@ module RuboCop
|
|
26
26
|
|
27
27
|
def_node_matcher :slow_caller?, <<-PATTERN
|
28
28
|
{
|
29
|
-
(send nil {:caller :caller_locations})
|
30
|
-
(send nil {:caller :caller_locations} int)
|
29
|
+
(send nil? {:caller :caller_locations})
|
30
|
+
(send nil? {:caller :caller_locations} int)
|
31
31
|
}
|
32
32
|
PATTERN
|
33
33
|
|
@@ -68,7 +68,7 @@ module RuboCop
|
|
68
68
|
range = condition.parent.loc.keyword.join(condition.source_range)
|
69
69
|
variable, = *condition
|
70
70
|
message = variable.array_type? ? ARRAY_MSG : MSG
|
71
|
-
add_offense(condition.parent, range, message)
|
71
|
+
add_offense(condition.parent, location: range, message: message)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -40,7 +40,7 @@ module RuboCop
|
|
40
40
|
|
41
41
|
inefficient_comparison(node) do |range, is_other_part, *methods|
|
42
42
|
ignore_node(node) if is_other_part
|
43
|
-
add_offense(node, range, format(MSG, *methods))
|
43
|
+
add_offense(node, location: range, message: format(MSG, *methods))
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -46,8 +46,12 @@ module RuboCop
|
|
46
46
|
replaceable_body?(body, var_a, var_b) do |method, args_a, args_b|
|
47
47
|
return unless slow_compare?(method, args_a, args_b)
|
48
48
|
range = compare_range(send, node)
|
49
|
-
|
50
|
-
|
49
|
+
|
50
|
+
add_offense(
|
51
|
+
node,
|
52
|
+
location: range,
|
53
|
+
message: message(send, method, var_a, var_b, args_a)
|
54
|
+
)
|
51
55
|
end
|
52
56
|
end
|
53
57
|
end
|
@@ -84,10 +84,10 @@ module RuboCop
|
|
84
84
|
range = receiver.loc.selector.join(node.loc.selector)
|
85
85
|
|
86
86
|
message = second_method == :last ? REVERSE_MSG : MSG
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
formatted_message = format(message, preferred_method, first_method,
|
88
|
+
second_method)
|
89
|
+
|
90
|
+
add_offense(node, location: range, message: formatted_message)
|
91
91
|
end
|
92
92
|
|
93
93
|
def preferred_method
|
@@ -68,15 +68,12 @@ module RuboCop
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def add_offense_for_double_call(node, receiver, method, combined_args)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
combined_args: combined_args,
|
78
|
-
original_code: node.source
|
79
|
-
))
|
71
|
+
msg = format(MSG, receiver: receiver.source,
|
72
|
+
method: method,
|
73
|
+
combined_args: combined_args,
|
74
|
+
original_code: node.source)
|
75
|
+
|
76
|
+
add_offense(node, message: msg)
|
80
77
|
end
|
81
78
|
|
82
79
|
def check_for_active_support_aliases?
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
SINGLE_QUOTE = "'".freeze
|
20
20
|
|
21
21
|
def_node_matcher :redundant_regex?, <<-PATTERN
|
22
|
-
{(send $!nil {:match :=~} (regexp (str $#literal_at_end?) (regopt)))
|
22
|
+
{(send $!nil? {:match :=~} (regexp (str $#literal_at_end?) (regopt)))
|
23
23
|
(send (regexp (str $#literal_at_end?) (regopt)) {:match :=~} $_)}
|
24
24
|
PATTERN
|
25
25
|
|
@@ -65,7 +65,9 @@ module RuboCop
|
|
65
65
|
range = range_between(map_node.loc.selector.begin_pos,
|
66
66
|
node.loc.expression.end_pos)
|
67
67
|
|
68
|
-
add_offense(node,
|
68
|
+
add_offense(node,
|
69
|
+
location: range,
|
70
|
+
message: format(message, first_method, flatten))
|
69
71
|
end
|
70
72
|
end
|
71
73
|
end
|
@@ -3,7 +3,11 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Performance
|
6
|
-
# This cop checks for uses of `each_key`
|
6
|
+
# This cop checks for uses of `each_key` and `each_value` Hash methods.
|
7
|
+
#
|
8
|
+
# Note: If you have an array of two-element arrays, you can put
|
9
|
+
# parentheses around the block arguments to indicate that you're not
|
10
|
+
# working with a hash, and supress RuboCop offenses.
|
7
11
|
#
|
8
12
|
# @example
|
9
13
|
# # bad
|
@@ -21,7 +25,7 @@ module RuboCop
|
|
21
25
|
MSG = 'Use `%s` instead of `%s`.'.freeze
|
22
26
|
|
23
27
|
def_node_matcher :plain_each, <<-PATTERN
|
24
|
-
(block $(send _ :each) (args (arg $_k) (arg $_v)) ...)
|
28
|
+
(block $(send !(send _ :to_a) :each) (args (arg $_k) (arg $_v)) ...)
|
25
29
|
PATTERN
|
26
30
|
|
27
31
|
def_node_matcher :kv_each, <<-PATTERN
|
@@ -39,21 +43,20 @@ module RuboCop
|
|
39
43
|
plain_each(node) do |target, k, v|
|
40
44
|
return if @args[k] && @args[v]
|
41
45
|
used = @args[k] ? :key : :value
|
46
|
+
|
42
47
|
add_offense(
|
43
|
-
target,
|
44
|
-
|
45
|
-
|
48
|
+
target,
|
49
|
+
location: plain_range(target),
|
50
|
+
message: format(message, "each_#{used}", :each)
|
46
51
|
)
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
50
55
|
def register_kv_offense(node)
|
51
56
|
kv_each(node) do |target, method|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
"#{method}.each")
|
56
|
-
)
|
57
|
+
msg = format(message, "each_#{method[0..-2]}", "#{method}.each")
|
58
|
+
|
59
|
+
add_offense(target, location: kv_range(target), message: msg)
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
@@ -25,7 +25,9 @@ module RuboCop
|
|
25
25
|
lstrip_rstrip(node) do |first_send, method_one, method_two|
|
26
26
|
range = range_between(first_send.loc.selector.begin_pos,
|
27
27
|
node.source_range.end_pos)
|
28
|
-
add_offense(node,
|
28
|
+
add_offense(node,
|
29
|
+
location: range,
|
30
|
+
message: format(MSG, method_one, method_two))
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
@@ -3,8 +3,9 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Performance
|
6
|
-
# This cop identifies use of `Regexp#match` or `String#match
|
7
|
-
#
|
6
|
+
# This cop identifies the use of `Regexp#match` or `String#match`, which
|
7
|
+
# returns `#<MatchData>`/`nil`. The return value of `=~` is an integral
|
8
|
+
# index/`nil` and is more performant.
|
8
9
|
#
|
9
10
|
# @example
|
10
11
|
# @bad
|
@@ -14,8 +15,8 @@ module RuboCop
|
|
14
15
|
# end
|
15
16
|
#
|
16
17
|
# @good
|
17
|
-
# method(str
|
18
|
-
# return regex
|
18
|
+
# method(str =~ /regex/)
|
19
|
+
# return value unless regex =~ 'str'
|
19
20
|
class RedundantMatch < Cop
|
20
21
|
MSG = 'Use `=~` in places where the `MatchData` returned by ' \
|
21
22
|
'`#match` will not be used.'.freeze
|
@@ -24,7 +25,7 @@ module RuboCop
|
|
24
25
|
# a string or regexp literal on one side or the other
|
25
26
|
def_node_matcher :match_call?, <<-PATTERN
|
26
27
|
{(send {str regexp} :match _)
|
27
|
-
(send !nil :match {str regexp})}
|
28
|
+
(send !nil? :match {str regexp})}
|
28
29
|
PATTERN
|
29
30
|
|
30
31
|
def_node_matcher :only_truthiness_matters?, <<-PATTERN
|
@@ -15,7 +15,7 @@ module RuboCop
|
|
15
15
|
MSG = 'Use `%s` instead of `%s`.'.freeze
|
16
16
|
|
17
17
|
def_node_matcher :redundant_merge_candidate, <<-PATTERN
|
18
|
-
(send $!nil :merge! [(hash $...) !kwsplat_type?])
|
18
|
+
(send $!nil? :merge! [(hash $...) !kwsplat_type?])
|
19
19
|
PATTERN
|
20
20
|
|
21
21
|
def_node_matcher :modifier_flow_control?, <<-PATTERN
|
@@ -25,7 +25,10 @@ module RuboCop
|
|
25
25
|
def on_block(node)
|
26
26
|
redundant_sort_by(node) do |send, var_name|
|
27
27
|
range = sort_by_range(send, node)
|
28
|
-
|
28
|
+
|
29
|
+
add_offense(node,
|
30
|
+
location: range,
|
31
|
+
message: format(MSG, var_name, var_name))
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
@@ -74,11 +74,11 @@ module RuboCop
|
|
74
74
|
PATTERN
|
75
75
|
|
76
76
|
def_node_matcher :match_operator?, <<-PATTERN
|
77
|
-
(send !nil :=~ !nil)
|
77
|
+
(send !nil? :=~ !nil?)
|
78
78
|
PATTERN
|
79
79
|
|
80
80
|
def_node_matcher :match_threequals?, <<-PATTERN
|
81
|
-
(send (regexp (str _) {(regopt) (regopt _)}) :=== !nil)
|
81
|
+
(send (regexp (str _) {(regopt) (regopt _)}) :=== !nil?)
|
82
82
|
PATTERN
|
83
83
|
|
84
84
|
def match_with_lvasgn?(node)
|
@@ -101,8 +101,8 @@ module RuboCop
|
|
101
101
|
|
102
102
|
def_node_search :last_matches, <<-PATTERN
|
103
103
|
{
|
104
|
-
(send (const nil :Regexp) :last_match)
|
105
|
-
(send (const nil :Regexp) :last_match _)
|
104
|
+
(send (const nil? :Regexp) :last_match)
|
105
|
+
(send (const nil? :Regexp) :last_match _)
|
106
106
|
({back_ref nth_ref} _)
|
107
107
|
(gvar #match_gvar?)
|
108
108
|
}
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
SINGLE_QUOTE = "'".freeze
|
20
20
|
|
21
21
|
def_node_matcher :redundant_regex?, <<-PATTERN
|
22
|
-
{(send $!nil {:match :=~} (regexp (str $#literal_at_start?) (regopt)))
|
22
|
+
{(send $!nil? {:match :=~} (regexp (str $#literal_at_start?) (regopt)))
|
23
23
|
(send (regexp (str $#literal_at_start?) (regopt)) {:match :=~} $_)}
|
24
24
|
PATTERN
|
25
25
|
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
|
29
29
|
def_node_matcher :string_replacement?, <<-PATTERN
|
30
30
|
(send _ {:gsub :gsub!}
|
31
|
-
${regexp str (send (const nil :Regexp) {:new :compile} _)}
|
31
|
+
${regexp str (send (const nil? :Regexp) {:new :compile} _)}
|
32
32
|
$str)
|
33
33
|
PATTERN
|
34
34
|
|
@@ -101,7 +101,7 @@ module RuboCop
|
|
101
101
|
second_source, = *second_param
|
102
102
|
message = message(node, first_source, second_source)
|
103
103
|
|
104
|
-
add_offense(node, range(node), message)
|
104
|
+
add_offense(node, location: range(node), message: message)
|
105
105
|
end
|
106
106
|
|
107
107
|
def first_source(first_param)
|
@@ -35,7 +35,7 @@ module RuboCop
|
|
35
35
|
|
36
36
|
def check(node)
|
37
37
|
times_map_call(node) do |map_or_collect, count|
|
38
|
-
add_offense(node, :
|
38
|
+
add_offense(node, message: message(map_or_collect, count))
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -51,8 +51,8 @@ module RuboCop
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def_node_matcher :times_map_call, <<-PATTERN
|
54
|
-
{(block $(send (send $!nil :times) {:map :collect}) ...)
|
55
|
-
$(send (send $!nil :times) {:map :collect} (block_pass ...))}
|
54
|
+
{(block $(send (send $!nil? :times) {:map :collect}) ...)
|
55
|
+
$(send (send $!nil? :times) {:map :collect} (block_pass ...))}
|
56
56
|
PATTERN
|
57
57
|
|
58
58
|
def autocorrect(node)
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
def_node_matcher :uri_parser_new?, <<-PATTERN
|
21
21
|
(send
|
22
22
|
(const
|
23
|
-
(const ${nil cbase} :URI) :Parser) :new)
|
23
|
+
(const ${nil? cbase} :URI) :Parser) :new)
|
24
24
|
PATTERN
|
25
25
|
|
26
26
|
def on_send(node)
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
double_colon = captured_value ? '::' : ''
|
29
29
|
message = format(MSG, double_colon, double_colon)
|
30
30
|
|
31
|
-
add_offense(node, :
|
31
|
+
add_offense(node, message: message)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -23,7 +23,7 @@ module RuboCop
|
|
23
23
|
|
24
24
|
MSG = 'Jobs should subclass `ApplicationJob`.'.freeze
|
25
25
|
SUPERCLASS = 'ApplicationJob'.freeze
|
26
|
-
BASE_PATTERN = '(const (const nil :ActiveJob) :Base)'.freeze
|
26
|
+
BASE_PATTERN = '(const (const nil? :ActiveJob) :Base)'.freeze
|
27
27
|
|
28
28
|
include RuboCop::Cop::EnforceSuperclass
|
29
29
|
end
|
@@ -23,7 +23,7 @@ module RuboCop
|
|
23
23
|
|
24
24
|
MSG = 'Models should subclass `ApplicationRecord`.'.freeze
|
25
25
|
SUPERCLASS = 'ApplicationRecord'.freeze
|
26
|
-
BASE_PATTERN = '(const (const nil :ActiveRecord) :Base)'.freeze
|
26
|
+
BASE_PATTERN = '(const (const nil? :ActiveRecord) :Base)'.freeze
|
27
27
|
|
28
28
|
include RuboCop::Cop::EnforceSuperclass
|
29
29
|
end
|
@@ -38,17 +38,21 @@ module RuboCop
|
|
38
38
|
# something
|
39
39
|
# end
|
40
40
|
class Blank < Cop
|
41
|
-
MSG_NIL_OR_EMPTY = 'Use `%s
|
41
|
+
MSG_NIL_OR_EMPTY = 'Use `%s` instead of `%s`.'.freeze
|
42
42
|
MSG_NOT_PRESENT = 'Use `%s` instead of `%s`.'.freeze
|
43
|
-
MSG_UNLESS_PRESENT = 'Use `if %s
|
43
|
+
MSG_UNLESS_PRESENT = 'Use `if %s` instead of `%s`.'.freeze
|
44
44
|
|
45
|
+
# `(send nil $_)` is not actually a valid match for an offense. Nodes
|
46
|
+
# that have a single method call on the left hand side
|
47
|
+
# (`bar || foo.empty?`) will blow up when checking
|
48
|
+
# `(send (:nil) :== $_)`.
|
45
49
|
def_node_matcher :nil_or_empty?, <<-PATTERN
|
46
50
|
(or
|
47
51
|
{
|
48
52
|
(send $_ :!)
|
49
53
|
(send $_ :nil?)
|
50
|
-
(send $_ :==
|
51
|
-
(send
|
54
|
+
(send $_ :== nil)
|
55
|
+
(send nil :== $_)
|
52
56
|
}
|
53
57
|
{
|
54
58
|
(send $_ :empty?)
|
@@ -60,7 +64,7 @@ module RuboCop
|
|
60
64
|
def_node_matcher :not_present?, '(send (send $_ :present?) :!)'
|
61
65
|
|
62
66
|
def_node_matcher :unless_present?, <<-PATTERN
|
63
|
-
(:if $(send $_ :present?) {nil (...)} ...)
|
67
|
+
(:if $(send $_ :present?) {nil? (...)} ...)
|
64
68
|
PATTERN
|
65
69
|
|
66
70
|
def on_send(node)
|
@@ -68,23 +72,22 @@ module RuboCop
|
|
68
72
|
|
69
73
|
not_present?(node) do |receiver|
|
70
74
|
add_offense(node,
|
71
|
-
:
|
72
|
-
|
73
|
-
|
74
|
-
node.source))
|
75
|
+
message: format(MSG_NOT_PRESENT,
|
76
|
+
replacement(receiver),
|
77
|
+
node.source))
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
78
81
|
def on_or(node)
|
79
82
|
return unless cop_config['NilOrEmpty']
|
80
|
-
return unless node.lhs.receiver && node.rhs.receiver
|
81
83
|
|
82
84
|
nil_or_empty?(node) do |variable1, variable2|
|
83
85
|
return unless variable1 == variable2
|
84
86
|
|
85
87
|
add_offense(node,
|
86
|
-
:
|
87
|
-
|
88
|
+
message: format(MSG_NIL_OR_EMPTY,
|
89
|
+
replacement(variable1),
|
90
|
+
node.source))
|
88
91
|
end
|
89
92
|
end
|
90
93
|
|
@@ -96,10 +99,10 @@ module RuboCop
|
|
96
99
|
range = unless_condition(node, method_call)
|
97
100
|
|
98
101
|
add_offense(node,
|
99
|
-
range,
|
100
|
-
format(MSG_UNLESS_PRESENT,
|
101
|
-
|
102
|
-
|
102
|
+
location: range,
|
103
|
+
message: format(MSG_UNLESS_PRESENT,
|
104
|
+
replacement(receiver),
|
105
|
+
range.source))
|
103
106
|
end
|
104
107
|
end
|
105
108
|
|
@@ -107,7 +110,7 @@ module RuboCop
|
|
107
110
|
lambda do |corrector|
|
108
111
|
method_call, variable1 = unless_present?(node)
|
109
112
|
|
110
|
-
if method_call
|
113
|
+
if method_call
|
111
114
|
corrector.replace(node.loc.keyword, 'if')
|
112
115
|
range = method_call.loc.expression
|
113
116
|
else
|