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
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
def on_send(node)
|
28
28
|
even_odd_candidate?(node) do |_base_number, method, arg|
|
29
29
|
replacement_method = replacement_method(arg, method)
|
30
|
-
add_offense(node, :
|
30
|
+
add_offense(node, message: format(MSG, replacement_method))
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -13,7 +13,9 @@ module RuboCop
|
|
13
13
|
|
14
14
|
def on_for(node)
|
15
15
|
if style == :each
|
16
|
-
|
16
|
+
msg = 'Prefer `each` over `for`.'
|
17
|
+
|
18
|
+
add_offense(node, location: :keyword, message: msg) do
|
17
19
|
opposite_style_detected
|
18
20
|
end
|
19
21
|
else
|
@@ -39,7 +41,9 @@ module RuboCop
|
|
39
41
|
def incorrect_style_detected(method)
|
40
42
|
end_pos = method.source_range.end_pos
|
41
43
|
range = range_between(end_pos - EACH_LENGTH, end_pos)
|
42
|
-
|
44
|
+
msg = 'Prefer `for` over `each`.'
|
45
|
+
|
46
|
+
add_offense(range, location: range, message: msg) do
|
43
47
|
opposite_style_detected
|
44
48
|
end
|
45
49
|
end
|
@@ -17,9 +17,9 @@ module RuboCop
|
|
17
17
|
|
18
18
|
def_node_matcher :formatter, <<-PATTERN
|
19
19
|
{
|
20
|
-
(send nil ${:sprintf :format} _ _ ...)
|
20
|
+
(send nil? ${:sprintf :format} _ _ ...)
|
21
21
|
(send {str dstr} $:% ... )
|
22
|
-
(send !nil $:% {array hash})
|
22
|
+
(send !nil? $:% {array hash})
|
23
23
|
}
|
24
24
|
PATTERN
|
25
25
|
|
@@ -29,7 +29,8 @@ module RuboCop
|
|
29
29
|
|
30
30
|
return if detected_style == style
|
31
31
|
|
32
|
-
add_offense(node, :selector,
|
32
|
+
add_offense(node, location: :selector,
|
33
|
+
message: message(detected_style))
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
@@ -79,7 +79,7 @@ module RuboCop
|
|
79
79
|
last_special_comment = last_special_comment(processed_source)
|
80
80
|
range = source_range(processed_source.buffer, 0, 0)
|
81
81
|
|
82
|
-
add_offense(last_special_comment, range)
|
82
|
+
add_offense(last_special_comment, location: range)
|
83
83
|
end
|
84
84
|
|
85
85
|
def unnecessary_comment_offense(processed_source)
|
@@ -87,8 +87,8 @@ module RuboCop
|
|
87
87
|
frozen_string_literal_comment(processed_source)
|
88
88
|
|
89
89
|
add_offense(frozen_string_literal_comment,
|
90
|
-
frozen_string_literal_comment.pos,
|
91
|
-
MSG_UNNECESSARY)
|
90
|
+
location: frozen_string_literal_comment.pos,
|
91
|
+
message: MSG_UNNECESSARY)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
@@ -57,7 +57,7 @@ module RuboCop
|
|
57
57
|
def on_if(node)
|
58
58
|
return if accepted_form?(node) || !contains_guard_clause?(node)
|
59
59
|
|
60
|
-
add_offense(node, :keyword)
|
60
|
+
add_offense(node, location: :keyword)
|
61
61
|
end
|
62
62
|
|
63
63
|
private
|
@@ -65,7 +65,7 @@ module RuboCop
|
|
65
65
|
def check_ending_if(node)
|
66
66
|
return if accepted_form?(node, true) || !min_body_length?(node)
|
67
67
|
|
68
|
-
add_offense(node, :keyword)
|
68
|
+
add_offense(node, location: :keyword)
|
69
69
|
end
|
70
70
|
|
71
71
|
def accepted_form?(node, ending = false)
|
@@ -164,9 +164,8 @@ module RuboCop
|
|
164
164
|
def check(pairs, delim, msg)
|
165
165
|
pairs.each do |pair|
|
166
166
|
if pair.delimiter == delim
|
167
|
-
|
168
|
-
|
169
|
-
msg) do
|
167
|
+
location = pair.source_range.begin.join(pair.loc.operator)
|
168
|
+
add_offense(pair, location: location, message: msg) do
|
170
169
|
opposite_style_detected
|
171
170
|
end
|
172
171
|
else
|
@@ -19,11 +19,11 @@ module RuboCop
|
|
19
19
|
'rather than just a message.'.freeze
|
20
20
|
|
21
21
|
def_node_matcher :implicit_runtime_error_raise_or_fail,
|
22
|
-
'(send nil ${:raise :fail} {str dstr})'
|
22
|
+
'(send nil? ${:raise :fail} {str dstr})'
|
23
23
|
|
24
24
|
def on_send(node)
|
25
25
|
implicit_runtime_error_raise_or_fail(node) do |method|
|
26
|
-
add_offense(node, :
|
26
|
+
add_offense(node, message: format(MSG, method))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -23,13 +23,13 @@ module RuboCop
|
|
23
23
|
def on_while(node)
|
24
24
|
return unless node.condition.truthy_literal?
|
25
25
|
|
26
|
-
add_offense(node, :keyword)
|
26
|
+
add_offense(node, location: :keyword)
|
27
27
|
end
|
28
28
|
|
29
29
|
def on_until(node)
|
30
30
|
return unless node.condition.falsey_literal?
|
31
31
|
|
32
|
-
add_offense(node, :keyword)
|
32
|
+
add_offense(node, location: :keyword)
|
33
33
|
end
|
34
34
|
|
35
35
|
alias on_while_post on_while
|
@@ -57,9 +57,8 @@ module RuboCop
|
|
57
57
|
return if negated?(node)
|
58
58
|
|
59
59
|
add_offense(node,
|
60
|
-
:
|
61
|
-
|
62
|
-
inverse: inverse_methods[method]))
|
60
|
+
message: format(MSG, method: method,
|
61
|
+
inverse: inverse_methods[method]))
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
@@ -73,9 +72,8 @@ module RuboCop
|
|
73
72
|
# can cause auto-correction to apply improper corrections.
|
74
73
|
ignore_node(block)
|
75
74
|
add_offense(node,
|
76
|
-
:
|
77
|
-
|
78
|
-
inverse: inverse_blocks[method]))
|
75
|
+
message: format(MSG, method: method,
|
76
|
+
inverse: inverse_blocks[method]))
|
79
77
|
end
|
80
78
|
end
|
81
79
|
|
@@ -70,7 +70,7 @@ module RuboCop
|
|
70
70
|
}
|
71
71
|
}.freeze
|
72
72
|
|
73
|
-
def_node_matcher :lambda_node?, '(block $(send nil :lambda) ...)'
|
73
|
+
def_node_matcher :lambda_node?, '(block $(send nil? :lambda) ...)'
|
74
74
|
|
75
75
|
def on_block(node)
|
76
76
|
return unless node.lambda?
|
@@ -80,8 +80,8 @@ module RuboCop
|
|
80
80
|
return unless offending_selector?(node, selector)
|
81
81
|
|
82
82
|
add_offense(node,
|
83
|
-
node.send_node.source_range,
|
84
|
-
message(node, selector))
|
83
|
+
location: node.send_node.source_range,
|
84
|
+
message: message(node, selector))
|
85
85
|
end
|
86
86
|
|
87
87
|
private
|
@@ -59,13 +59,15 @@ module RuboCop
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def missing_parentheses(node)
|
62
|
-
|
62
|
+
location = node.arguments.source_range
|
63
|
+
|
64
|
+
add_offense(node, location: location, message: MSG_MISSING) do
|
63
65
|
unexpected_style_detected(:require_no_parentheses)
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
67
69
|
def unwanted_parentheses(args)
|
68
|
-
add_offense(args, :
|
70
|
+
add_offense(args, message: MSG_PRESENT) do
|
69
71
|
unexpected_style_detected(:require_parentheses)
|
70
72
|
end
|
71
73
|
end
|
@@ -21,7 +21,8 @@ module RuboCop
|
|
21
21
|
min_max_candidate(node) do |receiver|
|
22
22
|
offender = offending_range(node)
|
23
23
|
|
24
|
-
add_offense(node,
|
24
|
+
add_offense(node, location: offender,
|
25
|
+
message: message(offender, receiver))
|
25
26
|
end
|
26
27
|
end
|
27
28
|
alias on_return on_array
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop checks that `include`, `extend` and `prepend` exists at
|
7
|
+
# the top level.
|
8
|
+
# Using these at the top level affects the behavior of `Object`.
|
9
|
+
# There will not be using `include`, `extend` and `prepend` at
|
10
|
+
# the top level. Let's use it inside `class` or `module`.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # bad
|
14
|
+
# include M
|
15
|
+
#
|
16
|
+
# class C
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# # bad
|
20
|
+
# extend M
|
21
|
+
#
|
22
|
+
# class C
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# prepend M
|
27
|
+
#
|
28
|
+
# class C
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# class C
|
33
|
+
# include M
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# # good
|
37
|
+
# class C
|
38
|
+
# extend M
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# # good
|
42
|
+
# class C
|
43
|
+
# prepend M
|
44
|
+
# end
|
45
|
+
class MixinUsage < Cop
|
46
|
+
MSG = '`%<statement>s` is used at the top level. Use inside `class` ' \
|
47
|
+
'or `module`.'.freeze
|
48
|
+
|
49
|
+
def_node_matcher :include_statement, <<-PATTERN
|
50
|
+
(send nil? ${:include :extend :prepend}
|
51
|
+
(const nil? _))
|
52
|
+
PATTERN
|
53
|
+
|
54
|
+
def on_send(node)
|
55
|
+
return unless (statement = include_statement(node))
|
56
|
+
return unless top_level_node?(node)
|
57
|
+
|
58
|
+
add_offense(node, message: format(MSG, statement: statement))
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def top_level_node?(node)
|
64
|
+
if node.parent.parent.nil?
|
65
|
+
node.sibling_index.zero?
|
66
|
+
else
|
67
|
+
top_level_node?(node.parent)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -32,8 +32,8 @@ module RuboCop
|
|
32
32
|
EXTEND_SELF_MSG =
|
33
33
|
'Use `extend self` instead of `module_function`.'.freeze
|
34
34
|
|
35
|
-
def_node_matcher :module_function_node?, '(send nil :module_function)'
|
36
|
-
def_node_matcher :extend_self_node?, '(send nil :extend self)'
|
35
|
+
def_node_matcher :module_function_node?, '(send nil? :module_function)'
|
36
|
+
def_node_matcher :extend_self_node?, '(send nil? :extend self)'
|
37
37
|
|
38
38
|
def on_module(node)
|
39
39
|
_name, body = *node
|
@@ -25,7 +25,7 @@ module RuboCop
|
|
25
25
|
range = range_between(receiver.loc.end.begin_pos,
|
26
26
|
node.send_node.source_range.end_pos)
|
27
27
|
|
28
|
-
add_offense(nil, range)
|
28
|
+
add_offense(nil, location: range)
|
29
29
|
|
30
30
|
# Done. If there are more blocks in the chain, they will be
|
31
31
|
# found by subsequent calls to on_block.
|
@@ -21,7 +21,9 @@ module RuboCop
|
|
21
21
|
node.each_child_node(:send) do |nested|
|
22
22
|
next if allowed_omission?(nested)
|
23
23
|
|
24
|
-
add_offense(nested,
|
24
|
+
add_offense(nested,
|
25
|
+
location: nested.source_range,
|
26
|
+
message: format(MSG, nested.source))
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|