rubocop 0.50.0 → 0.51.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 +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
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
MSG = 'Use `Integer` instead of `%s`.'.freeze
|
22
22
|
|
23
23
|
def_node_matcher :fixnum_or_bignum_const, <<-PATTERN
|
24
|
-
(:const {nil (:cbase)} ${:Fixnum :Bignum})
|
24
|
+
(:const {nil? (:cbase)} ${:Fixnum :Bignum})
|
25
25
|
PATTERN
|
26
26
|
|
27
27
|
def on_const(node)
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
|
30
30
|
return unless klass
|
31
31
|
|
32
|
-
add_offense(node, :
|
32
|
+
add_offense(node, message: format(MSG, klass))
|
33
33
|
end
|
34
34
|
|
35
35
|
def autocorrect(node)
|
@@ -166,8 +166,12 @@ module RuboCop
|
|
166
166
|
def add_offense_for_entire_comment(comment, cops)
|
167
167
|
location = comment.loc.expression
|
168
168
|
cop_list = cops.sort.map { |c| describe(c) }
|
169
|
-
|
170
|
-
|
169
|
+
|
170
|
+
add_offense(
|
171
|
+
[[location], location],
|
172
|
+
location: location,
|
173
|
+
message: "Unnecessary disabling of #{cop_list.join(', ')}."
|
174
|
+
)
|
171
175
|
end
|
172
176
|
|
173
177
|
def add_offense_for_some_cops(comment, cops)
|
@@ -176,8 +180,11 @@ module RuboCop
|
|
176
180
|
ranges = cop_ranges.map { |_, r| r }
|
177
181
|
|
178
182
|
cop_ranges.each do |cop, range|
|
179
|
-
add_offense(
|
180
|
-
|
183
|
+
add_offense(
|
184
|
+
[ranges, range],
|
185
|
+
location: range,
|
186
|
+
message: "Unnecessary disabling of #{describe(cop)}."
|
187
|
+
)
|
181
188
|
end
|
182
189
|
end
|
183
190
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# Checks for unnecessary `require` statement.
|
7
|
+
#
|
8
|
+
# The following features are unnecessary `require` statement because
|
9
|
+
# they are already loaded.
|
10
|
+
#
|
11
|
+
# ruby -ve 'p $LOADED_FEATURES.reject { |feature| %r|/| =~ feature }'
|
12
|
+
# ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-darwin13]
|
13
|
+
# ["enumerator.so", "rational.so", "complex.so", "thread.rb"]
|
14
|
+
#
|
15
|
+
# This cop targets Ruby 2.2 or higher containing these 4 features.
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# # bad
|
19
|
+
# require 'unloaded_feature'
|
20
|
+
# require 'thread'
|
21
|
+
#
|
22
|
+
# # good
|
23
|
+
# require 'unloaded_feature'
|
24
|
+
class UnneededRequireStatement < Cop
|
25
|
+
extend TargetRubyVersion
|
26
|
+
|
27
|
+
minimum_target_ruby_version 2.2
|
28
|
+
|
29
|
+
MSG = 'Remove unnecessary `require` statement.'.freeze
|
30
|
+
|
31
|
+
def_node_matcher :unnecessary_require_statement?, <<-PATTERN
|
32
|
+
(send nil? :require
|
33
|
+
(str {"enumerator" "rational" "complex" "thread"}))
|
34
|
+
PATTERN
|
35
|
+
|
36
|
+
def on_send(node)
|
37
|
+
return unless unnecessary_require_statement?(node)
|
38
|
+
add_offense(node)
|
39
|
+
end
|
40
|
+
|
41
|
+
def autocorrect(node)
|
42
|
+
lambda do |corrector|
|
43
|
+
range = range_with_surrounding_space(node.loc.expression, :right)
|
44
|
+
corrector.remove(range)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -56,7 +56,7 @@ module RuboCop
|
|
56
56
|
PERCENT_CAPITAL_W = '%W'.freeze
|
57
57
|
PERCENT_I = '%i'.freeze
|
58
58
|
PERCENT_CAPITAL_I = '%I'.freeze
|
59
|
-
ARRAY_NEW_PATTERN = '$(send (const nil :Array) :new ...)'.freeze
|
59
|
+
ARRAY_NEW_PATTERN = '$(send (const nil? :Array) :new ...)'.freeze
|
60
60
|
ASSIGNMENT_TYPES = %i[lvasgn ivasgn cvasgn gvasgn].freeze
|
61
61
|
|
62
62
|
def_node_matcher :literal_expansion?, <<-PATTERN
|
@@ -71,7 +71,7 @@ module RuboCop
|
|
71
71
|
|
72
72
|
if array_splat?(node) &&
|
73
73
|
(method_argument?(node) || part_of_an_array?(node))
|
74
|
-
add_offense(node, :
|
74
|
+
add_offense(node, message: ARRAY_PARAM_MSG)
|
75
75
|
else
|
76
76
|
add_offense(node)
|
77
77
|
end
|
@@ -45,7 +45,7 @@ module RuboCop
|
|
45
45
|
|
46
46
|
def_node_matcher :uri_escape_unescape?, <<-PATTERN
|
47
47
|
(send
|
48
|
-
(const ${nil cbase} :URI) ${:escape :encode :unescape :decode}
|
48
|
+
(const ${nil? cbase} :URI) ${:escape :encode :unescape :decode}
|
49
49
|
...)
|
50
50
|
PATTERN
|
51
51
|
|
@@ -65,7 +65,7 @@ module RuboCop
|
|
65
65
|
*replacement_methods
|
66
66
|
)
|
67
67
|
|
68
|
-
add_offense(node, :
|
68
|
+
add_offense(node, message: message)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -20,13 +20,13 @@ module RuboCop
|
|
20
20
|
|
21
21
|
def_node_matcher :uri_regexp_with_argument?, <<-PATTERN
|
22
22
|
(send
|
23
|
-
(const ${nil cbase} :URI) :regexp
|
23
|
+
(const ${nil? cbase} :URI) :regexp
|
24
24
|
(str $_))
|
25
25
|
PATTERN
|
26
26
|
|
27
27
|
def_node_matcher :uri_regexp_without_argument?, <<-PATTERN
|
28
28
|
(send
|
29
|
-
(const ${nil cbase} :URI) :regexp)
|
29
|
+
(const ${nil? cbase} :URI) :regexp)
|
30
30
|
PATTERN
|
31
31
|
|
32
32
|
def on_send(node)
|
@@ -65,7 +65,7 @@ module RuboCop
|
|
65
65
|
def register_offense(node, top_level: '', arg: '')
|
66
66
|
format = format(MSG, top_level: top_level, arg: arg)
|
67
67
|
|
68
|
-
add_offense(node, :selector, format)
|
68
|
+
add_offense(node, location: :selector, message: format)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -114,11 +114,11 @@ module RuboCop
|
|
114
114
|
private
|
115
115
|
|
116
116
|
def_node_matcher :static_method_definition?, <<-PATTERN
|
117
|
-
{def (send nil {:attr :attr_reader :attr_writer :attr_accessor} ...)}
|
117
|
+
{def (send nil? {:attr :attr_reader :attr_writer :attr_accessor} ...)}
|
118
118
|
PATTERN
|
119
119
|
|
120
120
|
def_node_matcher :dynamic_method_definition?, <<-PATTERN
|
121
|
-
{(send nil :define_method ...) (block (send nil :define_method ...) ...)}
|
121
|
+
{(send nil? :define_method ...) (block (send nil? :define_method ...) ...)}
|
122
122
|
PATTERN
|
123
123
|
|
124
124
|
def_node_matcher :class_or_instance_eval?, <<-PATTERN
|
@@ -126,7 +126,7 @@ module RuboCop
|
|
126
126
|
PATTERN
|
127
127
|
|
128
128
|
def_node_matcher :class_or_module_or_struct_new_call?, <<-PATTERN
|
129
|
-
(block (send (const nil {:Class :Module :Struct}) :new ...) ...)
|
129
|
+
(block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
|
130
130
|
PATTERN
|
131
131
|
|
132
132
|
def check_node(node)
|
@@ -135,14 +135,14 @@ module RuboCop
|
|
135
135
|
if node.begin_type?
|
136
136
|
check_scope(node)
|
137
137
|
elsif node.send_type? && node.access_modifier?
|
138
|
-
add_offense(node, :
|
138
|
+
add_offense(node, message: format(MSG, node.method_name))
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
142
|
def check_scope(node)
|
143
143
|
cur_vis, unused = check_child_nodes(node, nil, :public)
|
144
144
|
|
145
|
-
add_offense(unused, :
|
145
|
+
add_offense(unused, message: format(MSG, cur_vis)) if unused
|
146
146
|
end
|
147
147
|
|
148
148
|
def check_child_nodes(node, unused, cur_vis)
|
@@ -165,10 +165,10 @@ module RuboCop
|
|
165
165
|
def check_new_visibility(node, unused, new_vis, cur_vis)
|
166
166
|
# does this modifier just repeat the existing visibility?
|
167
167
|
if new_vis == cur_vis
|
168
|
-
add_offense(node, :
|
168
|
+
add_offense(node, message: format(MSG, cur_vis))
|
169
169
|
else
|
170
170
|
# was the previous modifier never applied to any defs?
|
171
|
-
add_offense(unused, :
|
171
|
+
add_offense(unused, message: format(MSG, cur_vis)) if unused
|
172
172
|
# once we have already warned about a certain modifier, don't
|
173
173
|
# warn again even if it is never applied to any method defs
|
174
174
|
unused = node
|
@@ -188,7 +188,7 @@ module RuboCop
|
|
188
188
|
matcher_name = "#{m}_method?".to_sym
|
189
189
|
unless respond_to?(matcher_name)
|
190
190
|
self.class.def_node_matcher matcher_name, <<-PATTERN
|
191
|
-
{def (send nil :#{m} ...)}
|
191
|
+
{def (send nil? :#{m} ...)}
|
192
192
|
PATTERN
|
193
193
|
end
|
194
194
|
|
@@ -212,7 +212,7 @@ module RuboCop
|
|
212
212
|
matcher_name = "#{m}_block?".to_sym
|
213
213
|
unless respond_to?(matcher_name)
|
214
214
|
self.class.def_node_matcher matcher_name, <<-PATTERN
|
215
|
-
(block (send {nil const} {:#{m}} ...) ...)
|
215
|
+
(block (send {nil? const} {:#{m}} ...) ...)
|
216
216
|
PATTERN
|
217
217
|
end
|
218
218
|
|
@@ -39,7 +39,11 @@ module RuboCop
|
|
39
39
|
variable_name, = *receiver
|
40
40
|
return unless tracker.contain_local_object?(variable_name)
|
41
41
|
|
42
|
-
add_offense(
|
42
|
+
add_offense(
|
43
|
+
receiver,
|
44
|
+
location: :name,
|
45
|
+
message: format(MSG, receiver.loc.name.source)
|
46
|
+
)
|
43
47
|
end
|
44
48
|
alias on_defs on_def
|
45
49
|
|
@@ -75,30 +75,35 @@ module RuboCop
|
|
75
75
|
def check_void_op(node)
|
76
76
|
return unless node.send_type? && OPERATORS.include?(node.method_name)
|
77
77
|
|
78
|
-
add_offense(node,
|
78
|
+
add_offense(node,
|
79
|
+
location: :selector,
|
80
|
+
message: format(OP_MSG, node.method_name))
|
79
81
|
end
|
80
82
|
|
81
83
|
def check_var(node)
|
82
84
|
return unless node.variable? || node.const_type?
|
83
|
-
|
85
|
+
|
86
|
+
add_offense(node,
|
87
|
+
location: :name,
|
88
|
+
message: format(VAR_MSG, node.loc.name.source))
|
84
89
|
end
|
85
90
|
|
86
91
|
def check_literal(node)
|
87
92
|
return if !node.literal? || node.xstr_type?
|
88
93
|
|
89
|
-
add_offense(node, :
|
94
|
+
add_offense(node, message: format(LIT_MSG, node.source))
|
90
95
|
end
|
91
96
|
|
92
97
|
def check_self(node)
|
93
98
|
return unless node.self_type?
|
94
99
|
|
95
|
-
add_offense(node, :
|
100
|
+
add_offense(node, message: SELF_MSG)
|
96
101
|
end
|
97
102
|
|
98
103
|
def check_defined(node)
|
99
104
|
return unless node.defined_type?
|
100
105
|
|
101
|
-
add_offense(node, :
|
106
|
+
add_offense(node, message: format(DEFINED_MSG, node.source))
|
102
107
|
end
|
103
108
|
|
104
109
|
def in_void_context?(node)
|
@@ -44,7 +44,10 @@ module RuboCop
|
|
44
44
|
|
45
45
|
def register_offense(loc, line)
|
46
46
|
message = format(MSG, line.length, max)
|
47
|
-
|
47
|
+
|
48
|
+
add_offense(nil, location: loc, message: message) do
|
49
|
+
self.max = line.length
|
50
|
+
end
|
48
51
|
end
|
49
52
|
|
50
53
|
def excess_range(uri_range, line, index)
|
@@ -5,8 +5,7 @@ module RuboCop
|
|
5
5
|
module Metrics
|
6
6
|
# This cop checks for methods with too many parameters.
|
7
7
|
# The maximum number of parameters is configurable.
|
8
|
-
#
|
9
|
-
# be excluded from the total count.
|
8
|
+
# Keyword arguments can optionally be excluded from the total count.
|
10
9
|
class ParameterLists < Cop
|
11
10
|
include ConfigurableMax
|
12
11
|
|
@@ -72,8 +72,9 @@ module RuboCop
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def incorrect_style_detected(styles, first, left_parenthesis)
|
75
|
-
|
76
|
-
|
75
|
+
msg = message(base_description(left_parenthesis))
|
76
|
+
|
77
|
+
add_offense(first, message: msg) do
|
77
78
|
ambiguous_style_detected(*styles)
|
78
79
|
end
|
79
80
|
end
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
# autocorrecting it. Two rewrites in the same area by the same
|
40
40
|
# cop can not be handled. The next iteration will find the
|
41
41
|
# offense again and correct it.
|
42
|
-
add_offense(nil, expr)
|
42
|
+
add_offense(nil, location: expr)
|
43
43
|
else
|
44
44
|
add_offense(current)
|
45
45
|
end
|
@@ -102,7 +102,7 @@ module RuboCop
|
|
102
102
|
|
103
103
|
offset = style == :empty_lines && msg.include?('end.') ? 2 : 1
|
104
104
|
range = source_range(processed_source.buffer, line + offset, 0)
|
105
|
-
add_offense([style, range], range, msg)
|
105
|
+
add_offense([style, range], location: range, message: msg)
|
106
106
|
end
|
107
107
|
|
108
108
|
def check_deferred_empty_line(body)
|
@@ -113,7 +113,12 @@ module RuboCop
|
|
113
113
|
return if processed_source[line].empty?
|
114
114
|
|
115
115
|
range = source_range(processed_source.buffer, line + 2, 0)
|
116
|
-
|
116
|
+
|
117
|
+
add_offense(
|
118
|
+
[:empty_lines, range],
|
119
|
+
location: range,
|
120
|
+
message: deferred_message(node)
|
121
|
+
)
|
117
122
|
end
|
118
123
|
|
119
124
|
def namespace?(body, with_one_child: false)
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
end_loc = node.loc.end
|
42
42
|
msg = format(MSG, end_loc.line, end_loc.column, align_with.source,
|
43
43
|
align_with.line, align_with.column)
|
44
|
-
add_offense(node, end_loc, msg)
|
44
|
+
add_offense(node, location: end_loc, message: msg)
|
45
45
|
end
|
46
46
|
|
47
47
|
def style_parameter_name
|
@@ -10,7 +10,7 @@ module RuboCop
|
|
10
10
|
PATTERN
|
11
11
|
|
12
12
|
base.def_node_matcher :class_new_definition, <<-PATTERN
|
13
|
-
[!^(casgn nil :#{base::SUPERCLASS} ...) (send (const nil :Class) :new #{base::BASE_PATTERN})]
|
13
|
+
[!^(casgn nil? :#{base::SUPERCLASS} ...) (send (const nil? :Class) :new #{base::BASE_PATTERN})]
|
14
14
|
PATTERN
|
15
15
|
end
|
16
16
|
|