rubocop 0.90.0 → 0.93.1
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 -2
- data/config/default.yml +79 -3
- data/lib/rubocop.rb +20 -5
- data/lib/rubocop/cached_data.rb +2 -1
- data/lib/rubocop/cli/command/execute_runner.rb +8 -0
- data/lib/rubocop/comment_config.rb +9 -5
- data/lib/rubocop/config_loader.rb +3 -3
- data/lib/rubocop/config_regeneration.rb +33 -0
- data/lib/rubocop/config_store.rb +3 -3
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +5 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -0
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +10 -10
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -0
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/begin_end_alignment.rb +77 -0
- data/lib/rubocop/cop/layout/case_indentation.rb +4 -7
- data/lib/rubocop/cop/layout/class_structure.rb +1 -1
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +6 -9
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +2 -2
- data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +4 -12
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +13 -8
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +2 -2
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -2
- data/lib/rubocop/cop/layout/end_alignment.rb +5 -10
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +26 -4
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +4 -13
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -7
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +0 -4
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +6 -21
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +3 -8
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +2 -2
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +2 -0
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +2 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +18 -1
- data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -2
- data/lib/rubocop/cop/lint/boolean_symbol.rb +3 -0
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +74 -0
- data/lib/rubocop/cop/lint/debugger.rb +2 -3
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -3
- data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -4
- data/lib/rubocop/cop/lint/duplicate_require.rb +7 -2
- data/lib/rubocop/cop/lint/duplicate_rescue_exception.rb +2 -4
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
- data/lib/rubocop/cop/lint/empty_file.rb +1 -4
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +2 -0
- data/lib/rubocop/cop/lint/float_comparison.rb +2 -2
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +2 -2
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +37 -0
- data/lib/rubocop/cop/lint/identity_comparison.rb +51 -0
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +2 -5
- data/lib/rubocop/cop/lint/inherit_exception.rb +2 -2
- data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -0
- data/lib/rubocop/cop/lint/multiple_comparison.rb +3 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +1 -0
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +1 -2
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +1 -0
- data/lib/rubocop/cop/lint/rand_one.rb +2 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +22 -12
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +14 -4
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +78 -0
- data/lib/rubocop/cop/lint/rescue_type.rb +0 -1
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +3 -1
- data/lib/rubocop/cop/lint/shadowed_exception.rb +6 -6
- data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
- data/lib/rubocop/cop/lint/to_json.rb +16 -5
- data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -6
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +3 -1
- data/lib/rubocop/cop/lint/uri_regexp.rb +2 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +3 -9
- data/lib/rubocop/cop/lint/useless_method_definition.rb +20 -27
- data/lib/rubocop/cop/lint/useless_times.rb +106 -0
- data/lib/rubocop/cop/metrics/block_length.rb +3 -1
- data/lib/rubocop/cop/metrics/class_length.rb +14 -6
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +25 -16
- data/lib/rubocop/cop/mixin/comments_help.rb +3 -9
- data/lib/rubocop/cop/mixin/configurable_naming.rb +2 -2
- data/lib/rubocop/cop/mixin/configurable_numbering.rb +3 -3
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +9 -0
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +10 -2
- data/lib/rubocop/cop/mixin/rescue_node.rb +1 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -3
- data/lib/rubocop/cop/mixin/visibility_help.rb +4 -16
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/file_name.rb +1 -1
- data/lib/rubocop/cop/offense.rb +15 -2
- data/lib/rubocop/cop/security/eval.rb +1 -0
- data/lib/rubocop/cop/security/json_load.rb +1 -0
- data/lib/rubocop/cop/security/marshal_load.rb +1 -0
- data/lib/rubocop/cop/security/open.rb +1 -0
- data/lib/rubocop/cop/security/yaml_load.rb +1 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +7 -11
- data/lib/rubocop/cop/style/accessor_grouping.rb +3 -0
- data/lib/rubocop/cop/style/alias.rb +2 -0
- data/lib/rubocop/cop/style/array_coercion.rb +4 -0
- data/lib/rubocop/cop/style/array_join.rb +1 -0
- data/lib/rubocop/cop/style/attr.rb +1 -0
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +2 -0
- data/lib/rubocop/cop/style/case_equality.rb +3 -0
- data/lib/rubocop/cop/style/case_like_if.rb +20 -4
- data/lib/rubocop/cop/style/class_and_module_children.rb +2 -0
- data/lib/rubocop/cop/style/class_check.rb +6 -9
- data/lib/rubocop/cop/style/class_equality_comparison.rb +64 -0
- data/lib/rubocop/cop/style/class_methods_definitions.rb +42 -16
- data/lib/rubocop/cop/style/class_vars.rb +1 -2
- data/lib/rubocop/cop/style/combinable_loops.rb +13 -11
- data/lib/rubocop/cop/style/comment_annotation.rb +6 -0
- data/lib/rubocop/cop/style/commented_keyword.rb +7 -8
- data/lib/rubocop/cop/style/conditional_assignment.rb +49 -60
- data/lib/rubocop/cop/style/date_time.rb +12 -1
- data/lib/rubocop/cop/style/dir.rb +1 -0
- data/lib/rubocop/cop/style/double_negation.rb +1 -0
- data/lib/rubocop/cop/style/empty_literal.rb +3 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -3
- data/lib/rubocop/cop/style/even_odd.rb +1 -0
- data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
- data/lib/rubocop/cop/style/explicit_block_argument.rb +7 -3
- data/lib/rubocop/cop/style/float_division.rb +2 -0
- data/lib/rubocop/cop/style/for.rb +0 -4
- data/lib/rubocop/cop/style/format_string.rb +1 -4
- data/lib/rubocop/cop/style/format_string_token.rb +1 -1
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +24 -5
- data/lib/rubocop/cop/style/hash_transform_keys.rb +5 -11
- data/lib/rubocop/cop/style/hash_transform_values.rb +5 -11
- data/lib/rubocop/cop/style/if_unless_modifier.rb +0 -4
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -6
- data/lib/rubocop/cop/style/lambda_call.rb +3 -1
- data/lib/rubocop/cop/style/method_def_parentheses.rb +0 -4
- data/lib/rubocop/cop/style/mixin_usage.rb +8 -27
- data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -2
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +14 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +1 -0
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +2 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +2 -0
- data/lib/rubocop/cop/style/non_nil_check.rb +2 -0
- data/lib/rubocop/cop/style/not.rb +1 -0
- data/lib/rubocop/cop/style/numeric_predicate.rb +1 -3
- data/lib/rubocop/cop/style/one_line_conditional.rb +3 -1
- data/lib/rubocop/cop/style/optional_boolean_parameter.rb +12 -1
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +2 -0
- data/lib/rubocop/cop/style/raise_args.rb +2 -3
- data/lib/rubocop/cop/style/random_with_offset.rb +4 -3
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -9
- data/lib/rubocop/cop/style/redundant_begin.rb +36 -8
- data/lib/rubocop/cop/style/redundant_condition.rb +5 -1
- data/lib/rubocop/cop/style/redundant_conditional.rb +4 -5
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -3
- data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -0
- data/lib/rubocop/cop/style/redundant_freeze.rb +2 -1
- data/lib/rubocop/cop/style/redundant_interpolation.rb +6 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +14 -6
- data/lib/rubocop/cop/style/redundant_percent_q.rb +9 -11
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +39 -24
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -15
- data/lib/rubocop/cop/style/redundant_return.rb +17 -17
- data/lib/rubocop/cop/style/redundant_self.rb +7 -9
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -2
- data/lib/rubocop/cop/style/redundant_sort.rb +12 -29
- data/lib/rubocop/cop/style/redundant_sort_by.rb +5 -9
- data/lib/rubocop/cop/style/rescue_standard_error.rb +20 -16
- data/lib/rubocop/cop/style/safe_navigation.rb +5 -0
- data/lib/rubocop/cop/style/sample.rb +2 -1
- data/lib/rubocop/cop/style/send.rb +2 -3
- data/lib/rubocop/cop/style/signal_exception.rb +2 -0
- data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
- data/lib/rubocop/cop/style/slicing_with_range.rb +2 -1
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -0
- data/lib/rubocop/cop/style/string_concatenation.rb +17 -3
- data/lib/rubocop/cop/style/strip.rb +1 -0
- data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -3
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +4 -3
- data/lib/rubocop/cop/style/unpack_first.rb +1 -0
- data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -5
- data/lib/rubocop/cop/util.rb +0 -1
- data/lib/rubocop/cop/variable_force/branch.rb +0 -4
- data/lib/rubocop/core_ext/string.rb +1 -1
- data/lib/rubocop/directive_comment.rb +32 -0
- data/lib/rubocop/ext/regexp_node.rb +23 -7
- data/lib/rubocop/formatter/disabled_config_formatter.rb +12 -5
- data/lib/rubocop/options.rb +37 -17
- data/lib/rubocop/result_cache.rb +38 -15
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +5 -5
- data/lib/rubocop/runner.rb +37 -18
- data/lib/rubocop/target_finder.rb +27 -26
- data/lib/rubocop/target_ruby.rb +1 -1
- data/lib/rubocop/version.rb +6 -1
- metadata +19 -18
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +0 -43
- data/lib/rubocop/cop/tokens_util.rb +0 -84
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
# Common functionality for handling Regexp literals.
|
6
|
-
module RegexpLiteralHelp
|
7
|
-
private
|
8
|
-
|
9
|
-
def freespace_mode_regexp?(node)
|
10
|
-
regopt = node.children.find(&:regopt_type?)
|
11
|
-
|
12
|
-
regopt.children.include?(:x)
|
13
|
-
end
|
14
|
-
|
15
|
-
def pattern_source(node)
|
16
|
-
freespace_mode = freespace_mode_regexp?(node)
|
17
|
-
|
18
|
-
node.children.reject(&:regopt_type?).map do |child|
|
19
|
-
source_with_comments_and_interpolations_blanked(child, freespace_mode)
|
20
|
-
end.join
|
21
|
-
end
|
22
|
-
|
23
|
-
def source_with_comments_and_interpolations_blanked(child, freespace_mode)
|
24
|
-
source = child.source
|
25
|
-
|
26
|
-
# We don't want to consider the contents of interpolations or free-space mode comments as
|
27
|
-
# part of the pattern source, but need to preserve their width, to allow offsets to
|
28
|
-
# correctly line up with the original source: spaces have no effect, and preserve width.
|
29
|
-
if child.begin_type?
|
30
|
-
replace_match_with_spaces(source, /.*/m) # replace all content
|
31
|
-
elsif freespace_mode
|
32
|
-
replace_match_with_spaces(source, /(?<!\\)#.*/) # replace any comments
|
33
|
-
else
|
34
|
-
source
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def replace_match_with_spaces(source, pattern)
|
39
|
-
source.sub(pattern) { ' ' * Regexp.last_match[0].length }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
# Common methods and behaviors for dealing with tokens.
|
5
|
-
module TokensUtil
|
6
|
-
module_function
|
7
|
-
|
8
|
-
# rubocop:disable Metrics/AbcSize
|
9
|
-
def tokens(node)
|
10
|
-
@tokens ||= {}
|
11
|
-
return @tokens[node.object_id] if @tokens[node.object_id]
|
12
|
-
|
13
|
-
@tokens[node.object_id] =
|
14
|
-
# The tokens list is always sorted by token position,
|
15
|
-
# except for cases when heredoc is passed as a method argument.
|
16
|
-
# In this case tokens are interleaved by heredoc contents' tokens.
|
17
|
-
# We can try a fast (binary) search, assuming the mentioned cases are rare,
|
18
|
-
# and fallback to linear search if failed.
|
19
|
-
if (tokens = fast_tokens(node))
|
20
|
-
tokens
|
21
|
-
else
|
22
|
-
begin_pos = node.source_range.begin_pos
|
23
|
-
end_pos = node.source_range.end_pos
|
24
|
-
|
25
|
-
processed_source.tokens.select do |token|
|
26
|
-
token.end_pos <= end_pos && token.begin_pos >= begin_pos
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
# rubocop:enable Metrics/AbcSize
|
31
|
-
|
32
|
-
def index_of_first_token(node)
|
33
|
-
index = fast_index_of_first_token(node)
|
34
|
-
return index if index
|
35
|
-
|
36
|
-
begin_pos = node.source_range.begin_pos
|
37
|
-
processed_source.tokens.index { |token| token.begin_pos == begin_pos }
|
38
|
-
end
|
39
|
-
|
40
|
-
def index_of_last_token(node)
|
41
|
-
index = fast_index_of_last_token(node)
|
42
|
-
return index if index
|
43
|
-
|
44
|
-
end_pos = node.source_range.end_pos
|
45
|
-
processed_source.tokens.index { |token| token.end_pos == end_pos }
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def fast_index_of_first_token(node)
|
51
|
-
begin_pos = node.source_range.begin_pos
|
52
|
-
tokens = processed_source.tokens
|
53
|
-
|
54
|
-
index = tokens.bsearch_index { |token| token.begin_pos >= begin_pos }
|
55
|
-
index if index && tokens[index].begin_pos == begin_pos
|
56
|
-
end
|
57
|
-
|
58
|
-
def fast_index_of_last_token(node)
|
59
|
-
end_pos = node.source_range.end_pos
|
60
|
-
tokens = processed_source.tokens
|
61
|
-
|
62
|
-
index = tokens.bsearch_index { |token| token.end_pos >= end_pos }
|
63
|
-
index if index && tokens[index].end_pos == end_pos
|
64
|
-
end
|
65
|
-
|
66
|
-
def fast_tokens(node)
|
67
|
-
begin_index = index_of_first_token(node)
|
68
|
-
end_index = index_of_last_token(node)
|
69
|
-
|
70
|
-
tokens = processed_source.tokens[begin_index..end_index]
|
71
|
-
tokens if sorted_tokens?(tokens)
|
72
|
-
end
|
73
|
-
|
74
|
-
def sorted_tokens?(tokens)
|
75
|
-
prev_begin_pos = -1
|
76
|
-
tokens.each do |token|
|
77
|
-
return false if token.begin_pos < prev_begin_pos
|
78
|
-
|
79
|
-
prev_begin_pos = token.begin_pos
|
80
|
-
end
|
81
|
-
true
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|