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
@@ -10,36 +10,49 @@ module RuboCop
|
|
10
10
|
# @example
|
11
11
|
#
|
12
12
|
# # bad
|
13
|
-
# add_offense(node, :expression)
|
13
|
+
# add_offense(node, location: :expression)
|
14
14
|
#
|
15
15
|
# # good
|
16
16
|
# add_offense(node)
|
17
|
-
# add_offense(node, :selector)
|
18
|
-
# add_offense(node, :expression, 'message')
|
17
|
+
# add_offense(node, location: :selector)
|
19
18
|
#
|
20
19
|
class RedundantLocationArgument < Cop
|
21
20
|
MSG = 'Redundant location argument to `#add_offense`.'.freeze
|
22
21
|
|
23
|
-
def_node_matcher :
|
24
|
-
(send nil :add_offense _
|
22
|
+
def_node_matcher :add_offense_kwargs, <<-PATTERN
|
23
|
+
(send nil? :add_offense _ $hash)
|
24
|
+
PATTERN
|
25
|
+
|
26
|
+
def_node_matcher :redundant_location_argument?, <<-PATTERN
|
27
|
+
(pair (sym :location) (sym :expression))
|
25
28
|
PATTERN
|
26
29
|
|
27
30
|
def on_send(node)
|
28
|
-
|
29
|
-
add_offense(node.last_argument)
|
30
|
-
end
|
31
|
+
redundant_location_argument(node) { |argument| add_offense(argument) }
|
31
32
|
end
|
32
33
|
|
33
34
|
def autocorrect(node)
|
34
|
-
|
35
|
-
|
36
|
-
range = range_between(
|
37
|
-
first.loc.expression.end_pos,
|
38
|
-
second.loc.expression.end_pos
|
39
|
-
)
|
35
|
+
range = offending_range(node)
|
40
36
|
|
41
37
|
->(corrector) { corrector.remove(range) }
|
42
38
|
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def redundant_location_argument(node)
|
43
|
+
add_offense_kwargs(node) do |kwargs|
|
44
|
+
result =
|
45
|
+
kwargs.pairs.find { |arg| redundant_location_argument?(arg) }
|
46
|
+
|
47
|
+
yield result if result
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def offending_range(node)
|
52
|
+
with_space = range_with_surrounding_space(node.loc.expression)
|
53
|
+
|
54
|
+
range_with_surrounding_comma(with_space, :left)
|
55
|
+
end
|
43
56
|
end
|
44
57
|
end
|
45
58
|
end
|
@@ -10,39 +10,61 @@ module RuboCop
|
|
10
10
|
# @example
|
11
11
|
#
|
12
12
|
# # bad
|
13
|
-
# add_offense(node, :
|
14
|
-
# add_offense(node, :
|
15
|
-
# add_offense(node, :
|
13
|
+
# add_offense(node, message: MSG)
|
14
|
+
# add_offense(node, message: message)
|
15
|
+
# add_offense(node, message: message(node))
|
16
16
|
#
|
17
17
|
# # good
|
18
|
-
# add_offense(node
|
19
|
-
# add_offense(node, :
|
20
|
-
# add_offense(node, :
|
18
|
+
# add_offense(node)
|
19
|
+
# add_offense(node, message: CUSTOM_MSG)
|
20
|
+
# add_offense(node, message: message(other_node))
|
21
21
|
#
|
22
22
|
class RedundantMessageArgument < Cop
|
23
23
|
MSG = 'Redundant message argument to `#add_offense`.'.freeze
|
24
24
|
|
25
25
|
def_node_matcher :node_type_check, <<-PATTERN
|
26
|
-
(send nil :add_offense
|
27
|
-
{(const nil :MSG) (send nil :message) (send nil :message _offender)})
|
26
|
+
(send nil? :add_offense $_node $hash)
|
28
27
|
PATTERN
|
29
28
|
|
29
|
+
def_node_matcher :redundant_message_argument, <<-PATTERN
|
30
|
+
(pair
|
31
|
+
(sym :message)
|
32
|
+
${(const nil? :MSG) (send nil? :message) (send nil? :message _)})
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
def_node_matcher :message_method_call, '(send nil? :message $_node)'
|
36
|
+
|
30
37
|
def on_send(node)
|
31
|
-
node_type_check(node) do
|
32
|
-
|
38
|
+
node_type_check(node) do |node_arg, kwargs|
|
39
|
+
find_offending_argument(node_arg, kwargs) do |pair|
|
40
|
+
add_offense(pair)
|
41
|
+
end
|
33
42
|
end
|
34
43
|
end
|
35
44
|
|
36
45
|
def autocorrect(node)
|
37
|
-
|
38
|
-
arguments = parent.arguments
|
39
|
-
range =
|
40
|
-
Parser::Source::Range.new(parent.source_range.source_buffer,
|
41
|
-
arguments[-2].loc.expression.end_pos,
|
42
|
-
arguments.last.loc.expression.end_pos)
|
46
|
+
range = offending_range(node)
|
43
47
|
|
44
48
|
->(corrector) { corrector.remove(range) }
|
45
49
|
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def offending_range(node)
|
54
|
+
with_space = range_with_surrounding_space(node.loc.expression)
|
55
|
+
|
56
|
+
range_with_surrounding_comma(with_space, :left)
|
57
|
+
end
|
58
|
+
|
59
|
+
def find_offending_argument(searched_node, kwargs)
|
60
|
+
kwargs.pairs.each do |pair|
|
61
|
+
redundant_message_argument(pair) do |message_argument|
|
62
|
+
node = message_method_call(message_argument)
|
63
|
+
|
64
|
+
yield pair if !node || node == searched_node
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
46
68
|
end
|
47
69
|
end
|
48
70
|
end
|
@@ -17,11 +17,11 @@ module RuboCop
|
|
17
17
|
MSG = 'Do not specify cop behavior using `described_class::MSG`.'.freeze
|
18
18
|
|
19
19
|
def_node_search :described_class_msg, <<-PATTERN
|
20
|
-
(const (send nil :described_class) :MSG)
|
20
|
+
(const (send nil? :described_class) :MSG)
|
21
21
|
PATTERN
|
22
22
|
|
23
23
|
def_node_matcher :rspec_expectation_on_msg?, <<-PATTERN
|
24
|
-
(send (send nil :expect #contains_described_class_msg?) :to ...)
|
24
|
+
(send (send nil? :expect #contains_described_class_msg?) :to ...)
|
25
25
|
PATTERN
|
26
26
|
|
27
27
|
def investigate(_processed_source)
|
@@ -109,7 +109,7 @@ module RuboCop
|
|
109
109
|
when_column = when_node.loc.keyword.column
|
110
110
|
base_column = base_column(when_node.parent, alternative_style)
|
111
111
|
|
112
|
-
add_offense(when_node, :keyword, message(style)) do
|
112
|
+
add_offense(when_node, location: :keyword, message: message(style)) do
|
113
113
|
if when_column == base_column
|
114
114
|
opposite_style_detected
|
115
115
|
else
|
@@ -60,7 +60,7 @@ module RuboCop
|
|
60
60
|
left_paren = node.loc.begin
|
61
61
|
msg = correct_column == left_paren.column ? MSG_ALIGN : MSG_INDENT
|
62
62
|
|
63
|
-
add_offense(right_paren, right_paren, msg)
|
63
|
+
add_offense(right_paren, location: right_paren, message: msg)
|
64
64
|
end
|
65
65
|
|
66
66
|
def expected_column(node, elements)
|
@@ -33,8 +33,10 @@ module RuboCop
|
|
33
33
|
return if column == correct_comment_indentation
|
34
34
|
end
|
35
35
|
|
36
|
-
add_offense(
|
37
|
-
|
36
|
+
add_offense(
|
37
|
+
comment,
|
38
|
+
message: format(MSG, column, correct_comment_indentation)
|
39
|
+
)
|
38
40
|
end
|
39
41
|
|
40
42
|
def own_line_comment?(comment)
|
@@ -113,8 +113,11 @@ module RuboCop
|
|
113
113
|
@column_delta = effective_column(base_range) - else_range.column
|
114
114
|
return if @column_delta.zero?
|
115
115
|
|
116
|
-
add_offense(
|
117
|
-
|
116
|
+
add_offense(
|
117
|
+
else_range,
|
118
|
+
location: else_range,
|
119
|
+
message: format(MSG, else_range.source, base_range.source[/^\S*/])
|
120
|
+
)
|
118
121
|
end
|
119
122
|
end
|
120
123
|
end
|
@@ -23,7 +23,7 @@ module RuboCop
|
|
23
23
|
|
24
24
|
range =
|
25
25
|
source_range(processed_source.buffer, index + 1, 0, line.length)
|
26
|
-
add_offense(nil, range, msg)
|
26
|
+
add_offense(nil, location: range, message: msg)
|
27
27
|
# Usually there will be carriage return characters on all or none
|
28
28
|
# of the lines in a file, so we report only one offense.
|
29
29
|
break
|
@@ -87,7 +87,7 @@ module RuboCop
|
|
87
87
|
message = format(MSG_UNALIGNED_ASGN, 'following')
|
88
88
|
end
|
89
89
|
return if aligned_assignment?(token.pos, assignment_line)
|
90
|
-
add_offense(token.pos, token.pos, message)
|
90
|
+
add_offense(token.pos, location: token.pos, message: message)
|
91
91
|
end
|
92
92
|
|
93
93
|
def should_aligned_with_preceding_line?(token)
|
@@ -108,7 +108,7 @@ module RuboCop
|
|
108
108
|
next if ignored_range?(ast, range.begin_pos)
|
109
109
|
next if unary_plus_non_offense?(range)
|
110
110
|
|
111
|
-
add_offense(range, range, MSG_UNNECESSARY)
|
111
|
+
add_offense(range, location: range, message: MSG_UNNECESSARY)
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
@@ -90,7 +90,7 @@ module RuboCop
|
|
90
90
|
'Indent the right bracket the same as the start of the line' \
|
91
91
|
' where the left bracket is.'
|
92
92
|
end
|
93
|
-
add_offense(right_bracket, right_bracket, msg)
|
93
|
+
add_offense(right_bracket, location: right_bracket, message: msg)
|
94
94
|
end
|
95
95
|
|
96
96
|
# Returns the description of what the correct indentation is based on.
|
@@ -96,7 +96,7 @@ module RuboCop
|
|
96
96
|
'Indent the right brace the same as the start of the line ' \
|
97
97
|
'where the left brace is.'
|
98
98
|
end
|
99
|
-
add_offense(right_brace, right_brace, msg)
|
99
|
+
add_offense(right_brace, location: right_brace, message: msg)
|
100
100
|
end
|
101
101
|
|
102
102
|
def separator_style?(first_pair)
|
@@ -57,7 +57,7 @@ module RuboCop
|
|
57
57
|
return unless body_indent_level.zero?
|
58
58
|
end
|
59
59
|
|
60
|
-
add_offense(node, :heredoc_body)
|
60
|
+
add_offense(node, location: :heredoc_body)
|
61
61
|
end
|
62
62
|
|
63
63
|
def autocorrect(node)
|
@@ -160,7 +160,7 @@ module RuboCop
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def heredoc_body(node)
|
163
|
-
|
163
|
+
node.loc.heredoc_body.source.scrub
|
164
164
|
end
|
165
165
|
end
|
166
166
|
end
|
@@ -51,6 +51,8 @@ module RuboCop
|
|
51
51
|
include CheckAssignment
|
52
52
|
include IgnoredPattern
|
53
53
|
|
54
|
+
MSG = 'Use %d (not %d) spaces for%s indentation.'.freeze
|
55
|
+
|
54
56
|
SPECIAL_MODIFIERS = %w[private protected].freeze
|
55
57
|
|
56
58
|
def on_rescue(node)
|
@@ -236,11 +238,11 @@ module RuboCop
|
|
236
238
|
body_node
|
237
239
|
end
|
238
240
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
241
|
+
name = style == 'normal' ? '' : " #{style}"
|
242
|
+
msg = format(MSG, configured_indentation_width, indentation, name)
|
243
|
+
|
244
|
+
add_offense(node, location: offending_range(body_node, indentation),
|
245
|
+
message: msg)
|
244
246
|
end
|
245
247
|
|
246
248
|
# Returns true if the given node is within another node that has
|
@@ -9,8 +9,9 @@ module RuboCop
|
|
9
9
|
MSG = 'Indentation of first line in file detected.'.freeze
|
10
10
|
|
11
11
|
def investigate(_processed_source)
|
12
|
-
|
13
|
-
|
12
|
+
space_before(first_token) do |space|
|
13
|
+
add_offense(space, location: first_token.pos)
|
14
|
+
end
|
14
15
|
end
|
15
16
|
|
16
17
|
def autocorrect(range)
|
@@ -56,13 +56,13 @@ module RuboCop
|
|
56
56
|
def check_new_line_offense(node, rhs)
|
57
57
|
return unless node.loc.operator.line == rhs.loc.line
|
58
58
|
|
59
|
-
add_offense(node, :
|
59
|
+
add_offense(node, message: NEW_LINE_OFFENSE)
|
60
60
|
end
|
61
61
|
|
62
62
|
def check_same_line_offense(node, rhs)
|
63
63
|
return unless node.loc.operator.line != rhs.loc.line
|
64
64
|
|
65
|
-
add_offense(node, :
|
65
|
+
add_offense(node, message: SAME_LINE_OFFENSE)
|
66
66
|
end
|
67
67
|
|
68
68
|
def autocorrect(node)
|
@@ -57,7 +57,9 @@ module RuboCop
|
|
57
57
|
return if end_loc.column == kw_loc.column
|
58
58
|
return if end_loc.line == kw_loc.line
|
59
59
|
|
60
|
-
add_offense(node,
|
60
|
+
add_offense(node,
|
61
|
+
location: kw_loc,
|
62
|
+
message: format_message(kw_loc, end_loc))
|
61
63
|
end
|
62
64
|
|
63
65
|
def format_message(kw_loc, end_loc)
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
|
22
22
|
colon = node.loc.operator
|
23
23
|
|
24
|
-
add_offense(colon, colon) unless followed_by_space?(colon)
|
24
|
+
add_offense(colon, location: colon) unless followed_by_space?(colon)
|
25
25
|
end
|
26
26
|
|
27
27
|
def on_kwoptarg(node)
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
# optional keyword argument's name, so must construct one.
|
30
30
|
colon = node.loc.name.end.resize(1)
|
31
31
|
|
32
|
-
add_offense(colon, colon) unless followed_by_space?(colon)
|
32
|
+
add_offense(colon, location: colon) unless followed_by_space?(colon)
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|
@@ -113,14 +113,15 @@ module RuboCop
|
|
113
113
|
def check_space(space_begin_pos, space_end_pos, range, msg)
|
114
114
|
return if space_begin_pos != space_end_pos
|
115
115
|
|
116
|
-
add_offense(range, range, "Space #{msg} missing.")
|
116
|
+
add_offense(range, location: range, message: "Space #{msg} missing.")
|
117
117
|
end
|
118
118
|
|
119
119
|
def check_no_space(space_begin_pos, space_end_pos, msg)
|
120
120
|
return if space_begin_pos >= space_end_pos
|
121
121
|
|
122
122
|
range = range_between(space_begin_pos, space_end_pos)
|
123
|
-
add_offense(range, range,
|
123
|
+
add_offense(range, location: range,
|
124
|
+
message: "#{msg} block parameter detected.")
|
124
125
|
end
|
125
126
|
|
126
127
|
def autocorrect(range)
|
@@ -33,7 +33,7 @@ module RuboCop
|
|
33
33
|
def incorrect_style_detected(arg, value, space_on_both_sides,
|
34
34
|
no_surrounding_space)
|
35
35
|
range = range_between(arg.pos.end_pos, value.pos.begin_pos)
|
36
|
-
add_offense(range, range) do
|
36
|
+
add_offense(range, location: range) do
|
37
37
|
if style == :space && no_surrounding_space ||
|
38
38
|
style == :no_space && space_on_both_sides
|
39
39
|
opposite_style_detected
|