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
@@ -24,7 +24,7 @@ module RuboCop
|
|
24
24
|
quote_styles = detect_quote_styles(node)
|
25
25
|
|
26
26
|
if quote_styles.size > 1
|
27
|
-
add_offense(node, :
|
27
|
+
add_offense(node, message: MSG_INCONSISTENT)
|
28
28
|
else
|
29
29
|
check_multiline_quote_style(node, quote_styles[0])
|
30
30
|
end
|
@@ -76,10 +76,11 @@ module RuboCop
|
|
76
76
|
range = node.source_range
|
77
77
|
children = node.children
|
78
78
|
if unexpected_single_quotes?(quote)
|
79
|
-
|
79
|
+
all_children_with_quotes = children.all? { |c| wrong_quotes?(c) }
|
80
|
+
add_offense(node, location: range) if all_children_with_quotes
|
80
81
|
elsif unexpected_double_quotes?(quote) &&
|
81
82
|
!accept_child_double_quotes?(children)
|
82
|
-
add_offense(node, range)
|
83
|
+
add_offense(node, location: range)
|
83
84
|
end
|
84
85
|
end
|
85
86
|
|
@@ -19,12 +19,12 @@ module RuboCop
|
|
19
19
|
_name, superclass, _body = *node
|
20
20
|
return unless struct_constructor?(superclass)
|
21
21
|
|
22
|
-
add_offense(node, superclass.source_range)
|
22
|
+
add_offense(node, location: superclass.source_range)
|
23
23
|
end
|
24
24
|
|
25
25
|
def_node_matcher :struct_constructor?, <<-PATTERN
|
26
|
-
{(send (const nil :Struct) :new ...)
|
27
|
-
(block (send (const nil :Struct) :new ...) ...)}
|
26
|
+
{(send (const nil? :Struct) :new ...)
|
27
|
+
(block (send (const nil? :Struct) :new ...) ...)}
|
28
28
|
PATTERN
|
29
29
|
end
|
30
30
|
end
|
@@ -7,8 +7,7 @@ module RuboCop
|
|
7
7
|
# using the %i() syntax.
|
8
8
|
#
|
9
9
|
# Alternatively, it checks for symbol arrays using the %i() syntax on
|
10
|
-
# projects which do not want to use that syntax
|
11
|
-
# support a version of Ruby lower than 2.0.
|
10
|
+
# projects which do not want to use that syntax.
|
12
11
|
#
|
13
12
|
# Configuration option: MinSize
|
14
13
|
# If set, arrays with fewer elements than this value will not trigger the
|
@@ -38,9 +37,6 @@ module RuboCop
|
|
38
37
|
include ConfigurableEnforcedStyle
|
39
38
|
include PercentLiteral
|
40
39
|
include PercentArray
|
41
|
-
extend TargetRubyVersion
|
42
|
-
|
43
|
-
minimum_target_ruby_version 2.0
|
44
40
|
|
45
41
|
PERCENT_MSG = 'Use `%i` or `%I` for an array of symbols.'.freeze
|
46
42
|
ARRAY_MSG = 'Use `[]` for an array of symbols.'.freeze
|
@@ -15,7 +15,7 @@ module RuboCop
|
|
15
15
|
MSG = 'Pass `&:%s` as an argument to `%s` instead of a block.'.freeze
|
16
16
|
SUPER_TYPES = %i[super zsuper].freeze
|
17
17
|
|
18
|
-
def_node_matcher :proc_node?, '(send (const nil :Proc) :new)'
|
18
|
+
def_node_matcher :proc_node?, '(send (const nil? :Proc) :new)'
|
19
19
|
def_node_matcher :symbol_proc?, <<-PATTERN
|
20
20
|
(block
|
21
21
|
${(send ...) (super ...) zsuper}
|
@@ -71,10 +71,10 @@ module RuboCop
|
|
71
71
|
range = range_between(block_start, block_end)
|
72
72
|
|
73
73
|
add_offense(node,
|
74
|
-
range,
|
75
|
-
format(MSG,
|
76
|
-
|
77
|
-
|
74
|
+
location: range,
|
75
|
+
message: format(MSG,
|
76
|
+
method_name,
|
77
|
+
block_method_name))
|
78
78
|
end
|
79
79
|
|
80
80
|
def autocorrect_method(corrector, node, args, method_name)
|
@@ -64,7 +64,7 @@ module RuboCop
|
|
64
64
|
def on_if(node)
|
65
65
|
return unless node.ternary? && !infinite_loop? && offense?(node)
|
66
66
|
|
67
|
-
add_offense(node, node.source_range)
|
67
|
+
add_offense(node, location: node.source_range)
|
68
68
|
end
|
69
69
|
|
70
70
|
private
|
@@ -169,7 +169,7 @@ module RuboCop
|
|
169
169
|
|
170
170
|
def_node_matcher :method_call_argument, <<-PATTERN
|
171
171
|
{(:defined? $...)
|
172
|
-
(send {_ nil} _ $(send nil _)...)}
|
172
|
+
(send {_ nil?} _ $(send nil? _)...)}
|
173
173
|
PATTERN
|
174
174
|
|
175
175
|
def correct_parenthesized(condition)
|
@@ -28,22 +28,22 @@ module RuboCop
|
|
28
28
|
UNDERSCORE = '_'.freeze
|
29
29
|
|
30
30
|
def on_masgn(node)
|
31
|
-
|
31
|
+
ranges = unneeded_ranges(node)
|
32
32
|
|
33
|
-
|
33
|
+
ranges.each do |range|
|
34
|
+
good_code = node.source
|
35
|
+
offset = range.begin_pos - node.source_range.begin_pos
|
36
|
+
good_code[offset, range.size] = ''
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
good_code[offset, range.size] = ''
|
38
|
-
|
39
|
-
add_offense(node, range, format(MSG, good_code))
|
38
|
+
add_offense(node, location: range, message: format(MSG, good_code))
|
39
|
+
end
|
40
40
|
end
|
41
41
|
|
42
42
|
def autocorrect(node)
|
43
|
-
|
43
|
+
ranges = unneeded_ranges(node)
|
44
44
|
|
45
45
|
lambda do |corrector|
|
46
|
-
corrector.remove(range) if range
|
46
|
+
ranges.each { |range| corrector.remove(range) if range }
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -60,6 +60,7 @@ module RuboCop
|
|
60
60
|
|
61
61
|
def find_first_possible_offense(variables)
|
62
62
|
variables.reduce(nil) do |offense, variable|
|
63
|
+
break offense unless %i[lvasgn splat].include?(variable.type)
|
63
64
|
var, = *variable
|
64
65
|
var, = *var
|
65
66
|
if allow_named_underscore_variables
|
@@ -89,35 +90,57 @@ module RuboCop
|
|
89
90
|
cop_config['AllowNamedUnderscoreVariables']
|
90
91
|
end
|
91
92
|
|
92
|
-
def
|
93
|
-
|
94
|
-
variables = *
|
93
|
+
def unneeded_ranges(node)
|
94
|
+
node.masgn_type? ? (mlhs_node, = *node) : mlhs_node = node
|
95
|
+
variables = *mlhs_node
|
96
|
+
|
97
|
+
main_offense = main_node_offense(node)
|
98
|
+
if main_offense.nil?
|
99
|
+
children_offenses(variables)
|
100
|
+
else
|
101
|
+
children_offenses(variables) << main_offense
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def main_node_offense(node)
|
106
|
+
node.masgn_type? ? (mlhs_node, right = *node) : mlhs_node = node
|
107
|
+
|
108
|
+
variables = *mlhs_node
|
95
109
|
first_offense = find_first_offense(variables)
|
96
110
|
|
97
111
|
return unless first_offense
|
98
112
|
|
99
113
|
if unused_variables_only?(first_offense, variables)
|
100
|
-
return
|
114
|
+
return unused_range(node.type, mlhs_node, right)
|
101
115
|
end
|
102
116
|
|
103
|
-
if Util.parentheses?(
|
104
|
-
return range_for_parentheses(first_offense,
|
117
|
+
if Util.parentheses?(mlhs_node)
|
118
|
+
return range_for_parentheses(first_offense, mlhs_node)
|
105
119
|
end
|
106
120
|
|
107
|
-
range_between(
|
108
|
-
|
109
|
-
|
110
|
-
|
121
|
+
range_between(first_offense.source_range.begin_pos,
|
122
|
+
node.loc.operator.begin_pos)
|
123
|
+
end
|
124
|
+
|
125
|
+
def children_offenses(variables)
|
126
|
+
variables.select(&:mlhs_type?).flat_map { |v| unneeded_ranges(v) }
|
111
127
|
end
|
112
128
|
|
113
129
|
def unused_variables_only?(offense, variables)
|
114
130
|
offense.source_range == variables.first.source_range
|
115
131
|
end
|
116
132
|
|
117
|
-
def
|
118
|
-
|
119
|
-
|
120
|
-
|
133
|
+
def unused_range(node_type, mlhs_node, right)
|
134
|
+
start_range = mlhs_node.source_range.begin_pos
|
135
|
+
|
136
|
+
end_range = case node_type
|
137
|
+
when :masgn
|
138
|
+
right.source_range.begin_pos
|
139
|
+
when :mlhs
|
140
|
+
mlhs_node.source_range.end_pos
|
141
|
+
end
|
142
|
+
|
143
|
+
range_between(start_range, end_range)
|
121
144
|
end
|
122
145
|
|
123
146
|
def range_for_parentheses(offense, left)
|
@@ -5,11 +5,9 @@ module RuboCop
|
|
5
5
|
module Style
|
6
6
|
# This cop checks for variable interpolation (like "#@ivar").
|
7
7
|
class VariableInterpolation < Cop
|
8
|
-
# rubocop:disable Lint/InterpolationCheck
|
9
8
|
MSG = 'Replace interpolated variable `%s` ' \
|
10
9
|
'with expression `#{%s}`.'.freeze
|
11
10
|
|
12
|
-
# rubocop:enable Lint/InterpolationCheck
|
13
11
|
def on_dstr(node)
|
14
12
|
check_for_interpolation(node)
|
15
13
|
end
|
@@ -33,7 +33,8 @@ module RuboCop
|
|
33
33
|
def check(node)
|
34
34
|
return unless node.multiline? && single_line_as_modifier?(node)
|
35
35
|
|
36
|
-
add_offense(node, :keyword,
|
36
|
+
add_offense(node, location: :keyword,
|
37
|
+
message: format(MSG, node.keyword))
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -11,8 +11,8 @@ module RuboCop
|
|
11
11
|
#
|
12
12
|
# Configuration option: MinSize
|
13
13
|
# If set, arrays with fewer elements than this value will not trigger the
|
14
|
-
# cop. For example, a `MinSize of `3` will not enforce a style on an
|
15
|
-
# of 2 or fewer elements.
|
14
|
+
# cop. For example, a `MinSize` of `3` will not enforce a style on an
|
15
|
+
# array of 2 or fewer elements.
|
16
16
|
#
|
17
17
|
# @example
|
18
18
|
# EnforcedStyle: percent (default)
|
@@ -42,8 +42,8 @@ module RuboCop
|
|
42
42
|
|
43
43
|
return unless zero_length_predicate
|
44
44
|
|
45
|
-
add_offense(node,
|
46
|
-
format(ZERO_MSG, *zero_length_predicate))
|
45
|
+
add_offense(node,
|
46
|
+
message: format(ZERO_MSG, *zero_length_predicate))
|
47
47
|
end
|
48
48
|
|
49
49
|
def check_nonzero_length_predicate(node)
|
@@ -51,8 +51,8 @@ module RuboCop
|
|
51
51
|
|
52
52
|
return unless nonzero_length_predicate
|
53
53
|
|
54
|
-
add_offense(node,
|
55
|
-
format(NONZERO_MSG, *nonzero_length_predicate))
|
54
|
+
add_offense(node,
|
55
|
+
message: format(NONZERO_MSG, *nonzero_length_predicate))
|
56
56
|
end
|
57
57
|
|
58
58
|
def_node_matcher :zero_length_predicate, <<-PATTERN
|
data/lib/rubocop/cop/util.rb
CHANGED
@@ -295,7 +295,7 @@ module RuboCop
|
|
295
295
|
end
|
296
296
|
|
297
297
|
def compatible_external_encoding_for?(src)
|
298
|
-
src = src.dup if RUBY_VERSION < '2.3'
|
298
|
+
src = src.dup if RUBY_VERSION < '2.3' || RUBY_ENGINE == 'jruby'
|
299
299
|
src.force_encoding(Encoding.default_external).valid_encoding?
|
300
300
|
end
|
301
301
|
|
@@ -304,17 +304,6 @@ module RuboCop
|
|
304
304
|
.sub(/^Enforced/, 'Supported')
|
305
305
|
.sub('Style', 'Styles')
|
306
306
|
end
|
307
|
-
|
308
|
-
def scrub_string(string)
|
309
|
-
if string.respond_to?(:scrub)
|
310
|
-
string.scrub
|
311
|
-
else
|
312
|
-
string
|
313
|
-
.encode('UTF-16BE', 'UTF-8',
|
314
|
-
invalid: :replace, undef: :replace, replace: '?')
|
315
|
-
.encode('UTF-8')
|
316
|
-
end
|
317
|
-
end
|
318
307
|
end
|
319
308
|
end
|
320
309
|
end
|
data/lib/rubocop/node_pattern.rb
CHANGED
@@ -116,7 +116,7 @@ module RuboCop
|
|
116
116
|
PREDICATE = /\A#{IDENTIFIER}+\?\(?\Z/
|
117
117
|
WILDCARD = /\A_#{IDENTIFIER}*\Z/
|
118
118
|
FUNCALL = /\A\##{METHOD_NAME}/
|
119
|
-
LITERAL = /\A(?:#{SYMBOL}|#{NUMBER}|#{STRING}
|
119
|
+
LITERAL = /\A(?:#{SYMBOL}|#{NUMBER}|#{STRING})\Z/
|
120
120
|
PARAM = /\A#{PARAM_NUMBER}\Z/
|
121
121
|
CLOSING = /\A(?:\)|\}|\])\Z/
|
122
122
|
|
data/lib/rubocop/options.rb
CHANGED
@@ -100,6 +100,7 @@ module RuboCop
|
|
100
100
|
end
|
101
101
|
|
102
102
|
option(opts, '--force-exclusion')
|
103
|
+
option(opts, '--ignore-parent-exclusion')
|
103
104
|
|
104
105
|
option(opts, '--force-default-config')
|
105
106
|
|
@@ -303,6 +304,9 @@ module RuboCop
|
|
303
304
|
force_exclusion: ['Force excluding files specified in the',
|
304
305
|
'configuration `Exclude` even if they are',
|
305
306
|
'explicitly passed as arguments.'],
|
307
|
+
ignore_parent_exclusion:
|
308
|
+
['Prevent from inheriting AllCops/Exclude from',
|
309
|
+
'parent folders.'],
|
306
310
|
force_default_config: ['Use default configuration even if configuration',
|
307
311
|
'files are present in the directory tree.'],
|
308
312
|
format: ['Choose an output formatter. This option',
|
@@ -107,15 +107,9 @@ module RuboCop
|
|
107
107
|
[ast, comments, tokens]
|
108
108
|
end
|
109
109
|
|
110
|
-
# rubocop:disable Metrics/MethodLength
|
110
|
+
# rubocop:disable Metrics/MethodLength
|
111
111
|
def parser_class(ruby_version)
|
112
112
|
case ruby_version
|
113
|
-
when 1.9
|
114
|
-
require 'parser/ruby19'
|
115
|
-
Parser::Ruby19
|
116
|
-
when 2.0
|
117
|
-
require 'parser/ruby20'
|
118
|
-
Parser::Ruby20
|
119
113
|
when 2.1
|
120
114
|
require 'parser/ruby21'
|
121
115
|
Parser::Ruby21
|
@@ -132,7 +126,7 @@ module RuboCop
|
|
132
126
|
raise ArgumentError, "Unknown Ruby version: #{ruby_version.inspect}"
|
133
127
|
end
|
134
128
|
end
|
135
|
-
# rubocop:enable Metrics/MethodLength
|
129
|
+
# rubocop:enable Metrics/MethodLength
|
136
130
|
|
137
131
|
def create_parser(ruby_version)
|
138
132
|
builder = RuboCop::AST::Builder.new
|
data/lib/rubocop/rake_task.rb
CHANGED
@@ -17,25 +17,21 @@ module RuboCop
|
|
17
17
|
attr_accessor :requires
|
18
18
|
attr_accessor :options
|
19
19
|
|
20
|
-
def initialize(*args, &task_block)
|
21
|
-
setup_ivars(
|
20
|
+
def initialize(name = :rubocop, *args, &task_block)
|
21
|
+
setup_ivars(name)
|
22
22
|
|
23
23
|
desc 'Run RuboCop' unless ::Rake.application.last_description
|
24
24
|
|
25
25
|
task(name, *args) do |_, task_args|
|
26
|
-
RakeFileUtils.
|
26
|
+
RakeFileUtils.verbose(verbose) do
|
27
27
|
yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
|
28
|
-
|
28
|
+
run_cli(verbose, full_options)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
setup_subtasks(name, *args, &task_block)
|
33
33
|
end
|
34
34
|
|
35
|
-
def run_main_task(verbose)
|
36
|
-
run_cli(verbose, full_options)
|
37
|
-
end
|
38
|
-
|
39
35
|
private
|
40
36
|
|
41
37
|
def run_cli(verbose, options)
|
@@ -50,19 +46,14 @@ module RuboCop
|
|
50
46
|
end
|
51
47
|
|
52
48
|
def full_options
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
result.concat(patterns)
|
58
|
-
end
|
49
|
+
formatters.map { |f| ['--format', f] }.flatten
|
50
|
+
.concat(requires.map { |r| ['--require', r] }.flatten)
|
51
|
+
.concat(options.flatten)
|
52
|
+
.concat(patterns)
|
59
53
|
end
|
60
54
|
|
61
|
-
def setup_ivars(
|
62
|
-
|
63
|
-
require 'rubocop/options'
|
64
|
-
|
65
|
-
@name = args.shift || :rubocop
|
55
|
+
def setup_ivars(name)
|
56
|
+
@name = name
|
66
57
|
@verbose = true
|
67
58
|
@fail_on_error = true
|
68
59
|
@patterns = []
|
@@ -72,13 +63,15 @@ module RuboCop
|
|
72
63
|
end
|
73
64
|
|
74
65
|
def setup_subtasks(name, *args, &task_block)
|
75
|
-
namespace
|
66
|
+
namespace(name) do
|
76
67
|
desc 'Auto-correct RuboCop offenses'
|
77
68
|
|
78
69
|
task(:auto_correct, *args) do |_, task_args|
|
79
|
-
|
80
|
-
|
81
|
-
|
70
|
+
RakeFileUtils.verbose(verbose) do
|
71
|
+
yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
|
72
|
+
options = full_options.unshift('--auto-correct')
|
73
|
+
run_cli(verbose, options)
|
74
|
+
end
|
82
75
|
end
|
83
76
|
end
|
84
77
|
end
|