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
@@ -12,10 +12,9 @@ module RuboCop
|
|
12
12
|
|
13
13
|
return unless complexity > max
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
max)) do
|
15
|
+
msg = format(self.class::MSG, node.method_name, complexity, max)
|
16
|
+
|
17
|
+
add_offense(node, location: :keyword, message: msg) do
|
19
18
|
self.max = complexity.ceil
|
20
19
|
end
|
21
20
|
end
|
@@ -72,7 +72,7 @@ module RuboCop
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def incorrect_style_detected(range, node, lhs, rhs)
|
75
|
-
add_offense(range, range, message(node, lhs, rhs)) do
|
75
|
+
add_offense(range, location: range, message: message(node, lhs, rhs)) do
|
76
76
|
if supported_styles.size > 2 ||
|
77
77
|
offending_range(node, lhs, rhs, alternative_style)
|
78
78
|
unrecognized_style_detected
|
@@ -64,24 +64,30 @@ module RuboCop
|
|
64
64
|
def check_new_line(node)
|
65
65
|
return unless closing_brace_on_same_line?(node)
|
66
66
|
|
67
|
-
add_offense(node,
|
67
|
+
add_offense(node,
|
68
|
+
location: :end,
|
69
|
+
message: self.class::ALWAYS_NEW_LINE_MESSAGE)
|
68
70
|
end
|
69
71
|
|
70
72
|
def check_same_line(node)
|
71
73
|
return if closing_brace_on_same_line?(node)
|
72
74
|
|
73
|
-
add_offense(node,
|
75
|
+
add_offense(node,
|
76
|
+
location: :end,
|
77
|
+
message: self.class::ALWAYS_SAME_LINE_MESSAGE)
|
74
78
|
end
|
75
79
|
|
76
80
|
def check_symmetrical(node)
|
77
81
|
if opening_brace_on_same_line?(node)
|
78
82
|
return if closing_brace_on_same_line?(node)
|
79
83
|
|
80
|
-
add_offense(node, :end,
|
84
|
+
add_offense(node, location: :end,
|
85
|
+
message: self.class::SAME_LINE_MESSAGE)
|
81
86
|
else
|
82
87
|
return unless closing_brace_on_same_line?(node)
|
83
88
|
|
84
|
-
add_offense(node, :end,
|
89
|
+
add_offense(node, location: :end,
|
90
|
+
message: self.class::NEW_LINE_MESSAGE)
|
85
91
|
end
|
86
92
|
end
|
87
93
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
# Common functionality for Bundler/OrderedGems and
|
6
|
+
# Gemspec/OrderedDependencies.
|
7
|
+
module OrderedGemNode
|
8
|
+
private
|
9
|
+
|
10
|
+
def case_insensitive_out_of_order?(string_a, string_b)
|
11
|
+
string_a.downcase < string_b.downcase
|
12
|
+
end
|
13
|
+
|
14
|
+
def consecutive_lines(previous, current)
|
15
|
+
first_line = get_source_range(current).first_line
|
16
|
+
previous.source_range.last_line == first_line - 1
|
17
|
+
end
|
18
|
+
|
19
|
+
def register_offense(previous, current)
|
20
|
+
message = format(self.class::MSG, gem_name(current), gem_name(previous))
|
21
|
+
add_offense(current, message: message)
|
22
|
+
end
|
23
|
+
|
24
|
+
def gem_name(declaration_node)
|
25
|
+
declaration_node.first_argument.str_content
|
26
|
+
end
|
27
|
+
|
28
|
+
def autocorrect(node)
|
29
|
+
previous = previous_declaration(node)
|
30
|
+
|
31
|
+
current_range = declaration_with_comment(node)
|
32
|
+
previous_range = declaration_with_comment(previous)
|
33
|
+
|
34
|
+
lambda do |corrector|
|
35
|
+
swap_range(corrector, current_range, previous_range)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def declaration_with_comment(node)
|
40
|
+
buffer = processed_source.buffer
|
41
|
+
begin_pos = get_source_range(node).begin_pos
|
42
|
+
end_line = buffer.line_for_position(node.loc.expression.end_pos)
|
43
|
+
end_pos = buffer.line_range(end_line).end_pos
|
44
|
+
Parser::Source::Range.new(buffer, begin_pos, end_pos)
|
45
|
+
end
|
46
|
+
|
47
|
+
def swap_range(corrector, range1, range2)
|
48
|
+
src1 = range1.source
|
49
|
+
src2 = range2.source
|
50
|
+
corrector.replace(range1, src2)
|
51
|
+
corrector.replace(range2, src1)
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_source_range(node)
|
55
|
+
unless cop_config['TreatCommentsAsGroupSeparators']
|
56
|
+
first_comment = processed_source.ast_with_comments[node].first
|
57
|
+
return first_comment.loc.expression unless first_comment.nil?
|
58
|
+
end
|
59
|
+
node.source_range
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -9,7 +9,8 @@ module RuboCop
|
|
9
9
|
|
10
10
|
def investigate(processed_source)
|
11
11
|
each_missing_space(processed_source.tokens) do |token|
|
12
|
-
add_offense(token, token.pos,
|
12
|
+
add_offense(token, location: token.pos,
|
13
|
+
message: format(MSG, kind(token)))
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
@@ -9,7 +9,8 @@ module RuboCop
|
|
9
9
|
|
10
10
|
def investigate(processed_source)
|
11
11
|
each_missing_space(processed_source.tokens) do |token, pos_before|
|
12
|
-
add_offense(pos_before, pos_before,
|
12
|
+
add_offense(pos_before, location: pos_before,
|
13
|
+
message: format(MSG, kind(token)))
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
@@ -11,7 +11,7 @@ module RuboCop
|
|
11
11
|
def investigate(processed_source)
|
12
12
|
@processed_source = processed_source
|
13
13
|
each_extraneous_space(processed_source.tokens) do |kind, range|
|
14
|
-
add_offense(range, range, format(MSG, kind))
|
14
|
+
add_offense(range, location: range, message: format(MSG, kind))
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -116,9 +116,9 @@ module RuboCop
|
|
116
116
|
def avoid_comma(kind, comma_begin_pos, extra_info)
|
117
117
|
range = range_between(comma_begin_pos, comma_begin_pos + 1)
|
118
118
|
article = kind =~ /array/ ? 'an' : 'a'
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
msg = format(MSG, 'Avoid', format(kind, article)) + "#{extra_info}."
|
120
|
+
|
121
|
+
add_offense(range, location: range, message: msg)
|
122
122
|
end
|
123
123
|
|
124
124
|
def put_comma(node, items, kind)
|
@@ -128,9 +128,9 @@ module RuboCop
|
|
128
128
|
return if last_item.block_pass_type?
|
129
129
|
|
130
130
|
range = autocorrect_range(last_item)
|
131
|
+
msg = format(MSG, 'Put a', format(kind, 'a multiline') + '.')
|
131
132
|
|
132
|
-
add_offense(range, range,
|
133
|
-
format(MSG, 'Put a', format(kind, 'a multiline') + '.'))
|
133
|
+
add_offense(range, location: range, message: msg)
|
134
134
|
end
|
135
135
|
|
136
136
|
def autocorrect_range(item)
|
@@ -5,6 +5,10 @@ module RuboCop
|
|
5
5
|
module Lint
|
6
6
|
# Common functionality for cops handling unused arguments.
|
7
7
|
module UnusedArgument
|
8
|
+
extend NodePattern::Macros
|
9
|
+
|
10
|
+
def_node_search :uses_var?, '(lvar %)'
|
11
|
+
|
8
12
|
def join_force?(force_class)
|
9
13
|
force_class == VariableForce
|
10
14
|
end
|
@@ -17,10 +21,11 @@ module RuboCop
|
|
17
21
|
|
18
22
|
def check_argument(variable)
|
19
23
|
return if variable.should_be_unused?
|
20
|
-
return if variable
|
24
|
+
return if variable_used?(variable)
|
21
25
|
|
22
26
|
message = message(variable)
|
23
|
-
add_offense(variable.declaration_node, :name,
|
27
|
+
add_offense(variable.declaration_node, location: :name,
|
28
|
+
message: message)
|
24
29
|
end
|
25
30
|
|
26
31
|
def autocorrect(node)
|
@@ -36,6 +41,42 @@ module RuboCop
|
|
36
41
|
->(corrector) { corrector.insert_before(node.loc.name, '_') }
|
37
42
|
end
|
38
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def variable_used?(variable)
|
48
|
+
return false unless variable.referenced?
|
49
|
+
|
50
|
+
assignment_without_usage =
|
51
|
+
find_assignment_without_variable_usage(variable)
|
52
|
+
|
53
|
+
# If variable is either not assigned or assigned with usages,
|
54
|
+
# then it's really used
|
55
|
+
return true unless assignment_without_usage
|
56
|
+
|
57
|
+
assignment_without_usage_pos =
|
58
|
+
assignment_without_usage.node.source_range.begin_pos
|
59
|
+
|
60
|
+
reference_positions =
|
61
|
+
variable.references.map { |var| var.node.source_range.begin_pos }
|
62
|
+
|
63
|
+
# Was variable referenced before it was reassigned?
|
64
|
+
reference_positions.any? { |pos| pos <= assignment_without_usage_pos }
|
65
|
+
end
|
66
|
+
|
67
|
+
# Find the first variable assignment, which doesn't reference the
|
68
|
+
# variable at the rhs.
|
69
|
+
def find_assignment_without_variable_usage(variable)
|
70
|
+
variable.assignments.find do |assignment|
|
71
|
+
# It's impossible to decide whether a branch is executed, so
|
72
|
+
# this case is ignored
|
73
|
+
next if assignment.branch
|
74
|
+
|
75
|
+
assignment_node = assignment.meta_assignment_node || assignment.node
|
76
|
+
|
77
|
+
!uses_var?(assignment_node, assignment.variable.name)
|
78
|
+
end
|
79
|
+
end
|
39
80
|
end
|
40
81
|
end
|
41
82
|
end
|
@@ -19,13 +19,14 @@ module RuboCop
|
|
19
19
|
# def attribute ...
|
20
20
|
class AccessorMethodName < Cop
|
21
21
|
def on_def(node)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
msg =
|
23
|
+
if bad_reader_name?(node)
|
24
|
+
'Do not prefix reader method names with `get_`.'
|
25
|
+
elsif bad_writer_name?(node)
|
26
|
+
'Do not prefix writer method names with `set_`.'
|
27
|
+
end
|
28
|
+
|
29
|
+
add_offense(node, location: :name, message: msg) if msg
|
29
30
|
end
|
30
31
|
alias on_defs on_def
|
31
32
|
|
@@ -10,7 +10,7 @@ module RuboCop
|
|
10
10
|
def investigate(processed_source)
|
11
11
|
processed_source.tokens.each do |token|
|
12
12
|
next unless token.type == :tIDENTIFIER && !token.text.ascii_only?
|
13
|
-
add_offense(token, first_offense_range(token))
|
13
|
+
add_offense(token, location: first_offense_range(token))
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -27,12 +27,11 @@ module RuboCop
|
|
27
27
|
include Heredoc
|
28
28
|
|
29
29
|
MSG = 'Use meaningful heredoc delimiters.'.freeze
|
30
|
-
OPENING_DELIMITER = /<<[~-]?'?(\w+)'?\b/
|
31
30
|
|
32
31
|
def on_heredoc(node)
|
33
32
|
return if meaningful_delimiters?(node)
|
34
33
|
|
35
|
-
add_offense(node, :heredoc_end)
|
34
|
+
add_offense(node, location: :heredoc_end)
|
36
35
|
end
|
37
36
|
|
38
37
|
private
|
@@ -40,6 +39,8 @@ module RuboCop
|
|
40
39
|
def meaningful_delimiters?(node)
|
41
40
|
delimiters = delimiters(node)
|
42
41
|
|
42
|
+
return false unless delimiters =~ /\w/
|
43
|
+
|
43
44
|
blacklisted_delimiters.none? do |blacklisted_delimiter|
|
44
45
|
delimiters =~ Regexp.new(blacklisted_delimiter)
|
45
46
|
end
|
@@ -18,16 +18,37 @@ module RuboCop
|
|
18
18
|
# # good
|
19
19
|
# def value? ...
|
20
20
|
class PredicateName < Cop
|
21
|
+
def_node_matcher :dynamic_method_define, <<-PATTERN
|
22
|
+
(send nil? #method_definition_macros
|
23
|
+
(sym $_)
|
24
|
+
...)
|
25
|
+
PATTERN
|
26
|
+
|
27
|
+
def on_send(node)
|
28
|
+
dynamic_method_define(node) do |method_name|
|
29
|
+
predicate_prefixes.each do |prefix|
|
30
|
+
next if allowed_method_name?(method_name.to_s, prefix)
|
31
|
+
|
32
|
+
add_offense(
|
33
|
+
node,
|
34
|
+
location: node.first_argument.loc.expression,
|
35
|
+
message: message(method_name,
|
36
|
+
expected_name(method_name.to_s, prefix))
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
21
42
|
def on_def(node)
|
22
43
|
predicate_prefixes.each do |prefix|
|
23
44
|
method_name = node.method_name.to_s
|
24
|
-
|
25
|
-
next if
|
26
|
-
|
45
|
+
|
46
|
+
next if allowed_method_name?(method_name, prefix)
|
47
|
+
|
27
48
|
add_offense(
|
28
49
|
node,
|
29
|
-
:name,
|
30
|
-
message(method_name, expected_name(method_name, prefix))
|
50
|
+
location: :name,
|
51
|
+
message: message(method_name, expected_name(method_name, prefix))
|
31
52
|
)
|
32
53
|
end
|
33
54
|
end
|
@@ -35,6 +56,12 @@ module RuboCop
|
|
35
56
|
|
36
57
|
private
|
37
58
|
|
59
|
+
def allowed_method_name?(method_name, prefix)
|
60
|
+
!method_name.start_with?(prefix) ||
|
61
|
+
method_name == expected_name(method_name, prefix) ||
|
62
|
+
predicate_whitelist.include?(method_name)
|
63
|
+
end
|
64
|
+
|
38
65
|
def expected_name(method_name, prefix)
|
39
66
|
new_name = if prefix_blacklist.include?(prefix)
|
40
67
|
method_name.sub(prefix, '')
|
@@ -60,6 +87,10 @@ module RuboCop
|
|
60
87
|
def predicate_whitelist
|
61
88
|
cop_config['NameWhitelist']
|
62
89
|
end
|
90
|
+
|
91
|
+
def method_definition_macros(macro_name)
|
92
|
+
cop_config['MethodDefinitionMacros'].include?(macro_name.to_s)
|
93
|
+
end
|
63
94
|
end
|
64
95
|
end
|
65
96
|
end
|