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
@@ -45,7 +45,7 @@ module RuboCop
|
|
45
45
|
MSG = 'Use safe navigation (`&.`) instead of `%s`.'.freeze
|
46
46
|
|
47
47
|
def_node_matcher :try_call, <<-PATTERN
|
48
|
-
(send !nil ${:try :try!} $_ ...)
|
48
|
+
(send !nil? ${:try :try!} $_ ...)
|
49
49
|
PATTERN
|
50
50
|
|
51
51
|
minimum_target_ruby_version 2.3
|
@@ -56,7 +56,7 @@ module RuboCop
|
|
56
56
|
return unless method_to_try.sym_type?
|
57
57
|
method, = *method_to_try
|
58
58
|
return unless method =~ /\w+[=!?]?/
|
59
|
-
add_offense(node, :
|
59
|
+
add_offense(node, message: format(MSG, try_method))
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -70,11 +70,11 @@ module RuboCop
|
|
70
70
|
return unless expected_signature?(node)
|
71
71
|
return if persisted_referenced?(assignment)
|
72
72
|
|
73
|
-
add_offense(node, :selector,
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
add_offense(node, location: :selector,
|
74
|
+
message: format(CREATE_MSG,
|
75
|
+
"#{node.method_name}!",
|
76
|
+
node.method_name.to_s,
|
77
|
+
node.method_name.to_s))
|
78
78
|
end
|
79
79
|
|
80
80
|
def on_send(node)
|
@@ -84,10 +84,10 @@ module RuboCop
|
|
84
84
|
return if check_used_in_conditional(node)
|
85
85
|
return if last_call_of_method?(node)
|
86
86
|
|
87
|
-
add_offense(node, :selector,
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
add_offense(node, location: :selector,
|
88
|
+
message: format(MSG,
|
89
|
+
"#{node.method_name}!",
|
90
|
+
node.method_name.to_s))
|
91
91
|
end
|
92
92
|
|
93
93
|
def autocorrect(node)
|
@@ -121,9 +121,9 @@ module RuboCop
|
|
121
121
|
return false unless conditional?(node)
|
122
122
|
|
123
123
|
unless MODIFY_PERSIST_METHODS.include?(node.method_name)
|
124
|
-
add_offense(node, :selector,
|
125
|
-
|
126
|
-
|
124
|
+
add_offense(node, location: :selector,
|
125
|
+
message: format(CREATE_CONDITIONAL_MSG,
|
126
|
+
node.method_name.to_s))
|
127
127
|
end
|
128
128
|
|
129
129
|
true
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
class ScopeArgs < Cop
|
17
17
|
MSG = 'Use `lambda`/`proc` instead of a plain method call.'.freeze
|
18
18
|
|
19
|
-
def_node_matcher :scope?, '(send nil :scope _ $send)'
|
19
|
+
def_node_matcher :scope?, '(send nil? :scope _ $send)'
|
20
20
|
|
21
21
|
def on_send(node)
|
22
22
|
scope?(node) do |second_arg|
|
@@ -38,7 +38,7 @@ module RuboCop
|
|
38
38
|
update_counters].freeze
|
39
39
|
|
40
40
|
def_node_matcher :good_touch?, <<-PATTERN
|
41
|
-
(send (const nil :FileUtils) :touch ...)
|
41
|
+
(send (const nil? :FileUtils) :touch ...)
|
42
42
|
PATTERN
|
43
43
|
|
44
44
|
def on_send(node)
|
@@ -52,7 +52,7 @@ module RuboCop
|
|
52
52
|
|
53
53
|
return if good_touch?(node)
|
54
54
|
|
55
|
-
add_offense(node, :selector)
|
55
|
+
add_offense(node, location: :selector)
|
56
56
|
end
|
57
57
|
|
58
58
|
private
|
@@ -74,7 +74,7 @@ module RuboCop
|
|
74
74
|
|
75
75
|
message = build_message(klass, method_name, node)
|
76
76
|
|
77
|
-
add_offense(node, :selector, message)
|
77
|
+
add_offense(node, location: :selector, message: message)
|
78
78
|
end
|
79
79
|
|
80
80
|
def build_message(klass, method_name, node)
|
@@ -148,7 +148,8 @@ module RuboCop
|
|
148
148
|
|
149
149
|
return if node.arguments?
|
150
150
|
|
151
|
-
add_offense(selector_node,
|
151
|
+
add_offense(selector_node,
|
152
|
+
location: :selector, message: MSG_LOCALTIME)
|
152
153
|
end
|
153
154
|
|
154
155
|
def danger_chain?(chain)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rails
|
6
|
+
# This cop checks that environments called with `Rails.env` predicates
|
7
|
+
# exist.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# Rails.env.proudction?
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# Rails.env.production?
|
15
|
+
class UnknownEnv < Cop
|
16
|
+
include NameSimilarity
|
17
|
+
|
18
|
+
MSG = 'Unknown environment `%<name>s`.'.freeze
|
19
|
+
MSG_SIMILAR = 'Unknown environment `%<name>s`. ' \
|
20
|
+
'Did you mean `%<similar>s`?'.freeze
|
21
|
+
|
22
|
+
def_node_matcher :unknown_environment?, <<-PATTERN
|
23
|
+
(send
|
24
|
+
(send
|
25
|
+
{(const nil? :Rails) (const (cbase) :Rails)}
|
26
|
+
:env)
|
27
|
+
$#unknown_env_name?)
|
28
|
+
PATTERN
|
29
|
+
|
30
|
+
def on_send(node)
|
31
|
+
unknown_environment?(node) do |name|
|
32
|
+
add_offense(node, location: :selector, message: message(name))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def collect_variable_like_names(_scope)
|
39
|
+
environments.map { |env| env + '?' }
|
40
|
+
end
|
41
|
+
|
42
|
+
def message(name)
|
43
|
+
similar = find_similar_name(name.to_s, [])
|
44
|
+
if similar
|
45
|
+
format(MSG_SIMILAR, name: name, similar: similar)
|
46
|
+
else
|
47
|
+
format(MSG, name: name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def unknown_env_name?(name)
|
52
|
+
name = name.to_s
|
53
|
+
name.end_with?('?') &&
|
54
|
+
!environments.include?(name[0..-2])
|
55
|
+
end
|
56
|
+
|
57
|
+
def environments
|
58
|
+
cop_config['Environments']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/rubocop/cop/registry.rb
CHANGED
@@ -156,7 +156,8 @@ module RuboCop
|
|
156
156
|
|
157
157
|
def resolve_badge(given_badge, real_badge, source_path)
|
158
158
|
unless given_badge.match?(real_badge)
|
159
|
-
|
159
|
+
path = PathUtil.smart_path(source_path)
|
160
|
+
warn "#{path}: #{given_badge} has the wrong namespace - " \
|
160
161
|
"should be #{real_badge.department}"
|
161
162
|
end
|
162
163
|
|
@@ -15,13 +15,13 @@ module RuboCop
|
|
15
15
|
MSG = 'The use of `eval` is a serious security risk.'.freeze
|
16
16
|
|
17
17
|
def_node_matcher :eval?, <<-PATTERN
|
18
|
-
(send {nil (send nil :binding)} :eval $!str ...)
|
18
|
+
(send {nil? (send nil? :binding)} :eval $!str ...)
|
19
19
|
PATTERN
|
20
20
|
|
21
21
|
def on_send(node)
|
22
22
|
eval?(node) do |code|
|
23
23
|
return if code.dstr_type? && code.recursive_literal?
|
24
|
-
add_offense(node, :selector)
|
24
|
+
add_offense(node, location: :selector)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -26,12 +26,12 @@ module RuboCop
|
|
26
26
|
MSG = 'Prefer `JSON.parse` over `JSON.%s`.'.freeze
|
27
27
|
|
28
28
|
def_node_matcher :json_load, <<-PATTERN
|
29
|
-
(send (const {nil cbase} :JSON) ${:load :restore} ...)
|
29
|
+
(send (const {nil? cbase} :JSON) ${:load :restore} ...)
|
30
30
|
PATTERN
|
31
31
|
|
32
32
|
def on_send(node)
|
33
33
|
json_load(node) do |method|
|
34
|
-
add_offense(node, :selector, format(MSG, method))
|
34
|
+
add_offense(node, location: :selector, message: format(MSG, method))
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -22,13 +22,13 @@ module RuboCop
|
|
22
22
|
MSG = 'Avoid using `Marshal.%s`.'.freeze
|
23
23
|
|
24
24
|
def_node_matcher :marshal_load, <<-PATTERN
|
25
|
-
(send (const {nil cbase} :Marshal) ${:load :restore}
|
26
|
-
!(send (const {nil cbase} :Marshal) :dump ...))
|
25
|
+
(send (const {nil? cbase} :Marshal) ${:load :restore}
|
26
|
+
!(send (const {nil? cbase} :Marshal) :dump ...))
|
27
27
|
PATTERN
|
28
28
|
|
29
29
|
def on_send(node)
|
30
30
|
marshal_load(node) do |method|
|
31
|
-
add_offense(node, :selector, format(MSG, method))
|
31
|
+
add_offense(node, location: :selector, message: format(MSG, method))
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -19,12 +19,12 @@ module RuboCop
|
|
19
19
|
MSG = 'Prefer using `YAML.safe_load` over `YAML.load`.'.freeze
|
20
20
|
|
21
21
|
def_node_matcher :yaml_load, <<-PATTERN
|
22
|
-
(send (const {nil cbase} :YAML) :load ...)
|
22
|
+
(send (const {nil? cbase} :YAML) :load ...)
|
23
23
|
PATTERN
|
24
24
|
|
25
25
|
def on_send(node)
|
26
26
|
yaml_load(node) do
|
27
|
-
add_offense(node, :selector)
|
27
|
+
add_offense(node, location: :selector)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -39,14 +39,14 @@ module RuboCop
|
|
39
39
|
return unless style == :prefer_alias && alias_keyword_possible?(node)
|
40
40
|
|
41
41
|
msg = format(MSG_ALIAS_METHOD, lexical_scope_type(node))
|
42
|
-
add_offense(node, :selector, msg)
|
42
|
+
add_offense(node, location: :selector, message: msg)
|
43
43
|
end
|
44
44
|
|
45
45
|
def on_alias(node)
|
46
46
|
return unless alias_method_possible?(node)
|
47
47
|
|
48
48
|
if scope_type(node) == :dynamic || style == :prefer_alias_method
|
49
|
-
add_offense(node, :keyword, MSG_ALIAS)
|
49
|
+
add_offense(node, location: :keyword, message: MSG_ALIAS)
|
50
50
|
elsif node.children.none? { |arg| bareword?(arg) }
|
51
51
|
add_offense_for_args(node)
|
52
52
|
end
|
@@ -79,7 +79,7 @@ module RuboCop
|
|
79
79
|
arg_ranges = node.children.map(&:source_range)
|
80
80
|
msg = format(MSG_SYMBOL_ARGS, preferred_args,
|
81
81
|
existing_args)
|
82
|
-
add_offense(node, arg_ranges.reduce(&:join), msg)
|
82
|
+
add_offense(node, location: arg_ranges.reduce(&:join), message: msg)
|
83
83
|
end
|
84
84
|
|
85
85
|
# In this expression, will `self` be the same as the innermost enclosing
|
@@ -14,7 +14,7 @@ module RuboCop
|
|
14
14
|
def_node_matcher :join_candidate?, '(send $array :* $str)'
|
15
15
|
|
16
16
|
def on_send(node)
|
17
|
-
join_candidate?(node) { add_offense(node, :selector) }
|
17
|
+
join_candidate?(node) { add_offense(node, location: :selector) }
|
18
18
|
end
|
19
19
|
|
20
20
|
def autocorrect(node)
|
@@ -11,7 +11,7 @@ module RuboCop
|
|
11
11
|
def investigate(processed_source)
|
12
12
|
processed_source.comments.each do |comment|
|
13
13
|
unless comment.text.ascii_only?
|
14
|
-
add_offense(comment, first_offense_range(comment))
|
14
|
+
add_offense(comment, location: first_offense_range(comment))
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -32,8 +32,8 @@ module RuboCop
|
|
32
32
|
next if node.parent && node.parent.block_type?
|
33
33
|
next if node.block_argument?
|
34
34
|
|
35
|
-
add_offense(node,
|
36
|
-
format(MSG, target_class, target_method))
|
35
|
+
add_offense(node,
|
36
|
+
message: format(MSG, target_class, target_method))
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -10,35 +10,38 @@ module RuboCop
|
|
10
10
|
# * The `braces` style enforces braces around all method
|
11
11
|
# parameters that are hashes.
|
12
12
|
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
13
|
+
# ```
|
14
|
+
# # bad
|
15
|
+
# some_method(x, y, a: 1, b: 2)
|
16
16
|
#
|
17
|
-
#
|
18
|
-
#
|
17
|
+
# # good
|
18
|
+
# some_method(x, y, {a: 1, b: 2})
|
19
|
+
# ```
|
19
20
|
#
|
20
21
|
# * The `no_braces` style checks that the last parameter doesn't
|
21
22
|
# have braces around it.
|
22
23
|
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
24
|
+
# ```
|
25
|
+
# # bad
|
26
|
+
# some_method(x, y, {a: 1, b: 2})
|
26
27
|
#
|
27
|
-
#
|
28
|
-
#
|
28
|
+
# # good
|
29
|
+
# some_method(x, y, a: 1, b: 2)
|
30
|
+
# ```
|
29
31
|
#
|
30
32
|
# * The `context_dependent` style checks that the last parameter
|
31
33
|
# doesn't have braces around it, but requires braces if the
|
32
34
|
# second to last parameter is also a hash literal.
|
33
35
|
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
36
|
+
# ```
|
37
|
+
# # bad
|
38
|
+
# some_method(x, y, {a: 1, b: 2})
|
39
|
+
# some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
|
38
40
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
41
|
+
# # good
|
42
|
+
# some_method(x, y, a: 1, b: 2)
|
43
|
+
# some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
|
44
|
+
# ```
|
42
45
|
class BracesAroundHashParameters < Cop
|
43
46
|
include ConfigurableEnforcedStyle
|
44
47
|
|
@@ -78,8 +81,8 @@ module RuboCop
|
|
78
81
|
end
|
79
82
|
|
80
83
|
def add_arg_offense(arg, type)
|
81
|
-
add_offense(arg.parent, arg.source_range,
|
82
|
-
|
84
|
+
add_offense(arg.parent, location: arg.source_range,
|
85
|
+
message: format(MSG, type.to_s.capitalize))
|
83
86
|
end
|
84
87
|
|
85
88
|
# We let AutocorrectUnlessChangingAST#autocorrect work with the send
|