rubocop 0.47.1 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +28 -16
- data/config/default.yml +203 -115
- data/config/disabled.yml +0 -5
- data/config/enabled.yml +92 -8
- data/lib/rubocop.rb +24 -1
- data/lib/rubocop/ast/builder.rb +7 -2
- data/lib/rubocop/ast/node.rb +23 -20
- data/lib/rubocop/ast/node/and_node.rb +37 -0
- data/lib/rubocop/ast/node/array_node.rb +4 -1
- data/lib/rubocop/ast/node/case_node.rb +1 -0
- data/lib/rubocop/ast/node/ensure_node.rb +25 -0
- data/lib/rubocop/ast/node/hash_node.rb +10 -3
- data/lib/rubocop/ast/node/if_node.rb +2 -0
- data/lib/rubocop/ast/node/mixin/binary_operator_node.rb +23 -0
- data/lib/rubocop/ast/node/mixin/predicate_operator_node.rb +35 -0
- data/lib/rubocop/ast/node/or_node.rb +37 -0
- data/lib/rubocop/ast/node/resbody_node.rb +25 -0
- data/lib/rubocop/ast/node/send_node.rb +190 -0
- data/lib/rubocop/ast/node/when_node.rb +1 -1
- data/lib/rubocop/ast/traversal.rb +15 -15
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +39 -15
- data/lib/rubocop/config_loader.rb +34 -13
- data/lib/rubocop/cop/bundler/ordered_gems.rb +23 -4
- data/lib/rubocop/cop/commissioner.rb +4 -0
- data/lib/rubocop/cop/cop.rb +5 -0
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +53 -0
- data/lib/rubocop/cop/lint/debugger.rb +8 -1
- data/lib/rubocop/cop/lint/def_end_alignment.rb +2 -1
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +2 -4
- data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -1
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +3 -1
- data/lib/rubocop/cop/lint/empty_ensure.rb +6 -2
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +20 -18
- data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -3
- data/lib/rubocop/cop/lint/literal_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/multiple_compare.rb +5 -3
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +26 -18
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +7 -8
- data/lib/rubocop/cop/lint/require_parentheses.rb +7 -13
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +7 -3
- data/lib/rubocop/cop/lint/shadowed_exception.rb +2 -6
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +7 -8
- data/lib/rubocop/cop/lint/unneeded_disable.rb +35 -11
- data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +5 -2
- data/lib/rubocop/cop/lint/unused_block_argument.rb +6 -6
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -1
- data/lib/rubocop/cop/lint/useless_comparison.rb +5 -4
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/message_annotator.rb +7 -3
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/block_nesting.rb +4 -4
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +2 -2
- data/lib/rubocop/cop/metrics/line_length.rb +2 -9
- data/lib/rubocop/cop/metrics/parameter_lists.rb +4 -3
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +2 -2
- data/lib/rubocop/cop/mixin/access_modifier_node.rb +1 -1
- data/lib/rubocop/cop/mixin/array_hash_indentation.rb +2 -2
- data/lib/rubocop/cop/mixin/check_assignment.rb +6 -6
- data/lib/rubocop/cop/mixin/duplication.rb +1 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +27 -0
- data/lib/rubocop/cop/mixin/method_preference.rb +2 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +17 -29
- data/lib/rubocop/cop/mixin/on_method_def.rb +3 -3
- data/lib/rubocop/cop/mixin/percent_literal.rb +27 -0
- data/lib/rubocop/cop/mixin/rescue_node.rb +21 -0
- data/lib/rubocop/cop/mixin/safe_mode.rb +1 -1
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -1
- data/lib/rubocop/cop/mixin/target_rails_version.rb +16 -0
- data/lib/rubocop/cop/mixin/unused_argument.rb +1 -1
- data/lib/rubocop/cop/offense.rb +3 -3
- data/lib/rubocop/cop/performance/casecmp.rb +1 -1
- data/lib/rubocop/cop/performance/detect.rb +2 -1
- data/lib/rubocop/cop/performance/double_start_end_with.rb +35 -1
- data/lib/rubocop/cop/performance/end_with.rb +3 -1
- data/lib/rubocop/cop/performance/flat_map.rb +6 -6
- data/lib/rubocop/cop/performance/lstrip_rstrip.rb +2 -2
- data/lib/rubocop/cop/performance/range_include.rb +3 -1
- data/lib/rubocop/cop/performance/redundant_match.rb +6 -5
- data/lib/rubocop/cop/performance/regexp_match.rb +10 -3
- data/lib/rubocop/cop/performance/reverse_each.rb +2 -1
- data/lib/rubocop/cop/performance/size.rb +6 -11
- data/lib/rubocop/cop/performance/start_with.rb +3 -1
- data/lib/rubocop/cop/performance/string_replacement.rb +13 -18
- data/lib/rubocop/cop/performance/times_map.rb +4 -4
- data/lib/rubocop/cop/rails/action_filter.rb +42 -42
- data/lib/rubocop/cop/rails/active_support_aliases.rb +68 -0
- data/lib/rubocop/cop/rails/blank.rb +131 -0
- data/lib/rubocop/cop/rails/date.rb +25 -28
- data/lib/rubocop/cop/rails/delegate_allow_blank.rb +5 -7
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +7 -3
- data/lib/rubocop/cop/rails/exit.rb +9 -9
- data/lib/rubocop/cop/rails/file_path.rb +5 -14
- data/lib/rubocop/cop/rails/find_by.rb +8 -10
- data/lib/rubocop/cop/rails/find_each.rb +6 -9
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -0
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +15 -7
- data/lib/rubocop/cop/rails/output.rb +3 -5
- data/lib/rubocop/cop/rails/output_safety.rb +4 -8
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +25 -24
- data/lib/rubocop/cop/rails/present.rb +137 -0
- data/lib/rubocop/cop/rails/read_write_attribute.rb +9 -18
- data/lib/rubocop/cop/rails/relative_date_constant.rb +53 -0
- data/lib/rubocop/cop/rails/request_referer.rb +7 -4
- data/lib/rubocop/cop/rails/reversible_migration.rb +1 -2
- data/lib/rubocop/cop/rails/safe_navigation.rb +2 -1
- data/lib/rubocop/cop/rails/save_bang.rb +10 -10
- data/lib/rubocop/cop/rails/skips_model_validations.rb +23 -6
- data/lib/rubocop/cop/rails/time_zone.rb +20 -18
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +3 -2
- data/lib/rubocop/cop/rails/validation.rb +8 -11
- data/lib/rubocop/cop/registry.rb +3 -3
- data/lib/rubocop/cop/security/json_load.rb +1 -1
- data/lib/rubocop/cop/security/marshal_load.rb +5 -1
- data/lib/rubocop/cop/security/yaml_load.rb +3 -3
- data/lib/rubocop/cop/severity.rb +1 -1
- data/lib/rubocop/cop/style/alias.rb +5 -5
- data/lib/rubocop/cop/style/align_hash.rb +1 -1
- data/lib/rubocop/cop/style/align_parameters.rb +5 -5
- data/lib/rubocop/cop/style/and_or.rb +16 -31
- data/lib/rubocop/cop/style/attr.rb +14 -8
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +8 -11
- data/lib/rubocop/cop/style/block_delimiters.rb +11 -13
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +19 -23
- data/lib/rubocop/cop/style/case_indentation.rb +2 -0
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/class_check.rb +5 -7
- data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +5 -4
- data/lib/rubocop/cop/style/collection_methods.rb +8 -8
- data/lib/rubocop/cop/style/colon_method_call.rb +2 -9
- data/lib/rubocop/cop/style/conditional_assignment.rb +38 -45
- data/lib/rubocop/cop/style/constant_name.rb +1 -1
- data/lib/rubocop/cop/style/documentation_method.rb +1 -0
- data/lib/rubocop/cop/style/dot_position.rb +3 -7
- data/lib/rubocop/cop/style/double_negation.rb +2 -1
- data/lib/rubocop/cop/style/each_with_object.rb +1 -1
- data/lib/rubocop/cop/style/empty_else.rb +2 -2
- data/lib/rubocop/cop/style/empty_line_after_magic_comment.rb +63 -0
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +74 -4
- data/lib/rubocop/cop/style/empty_lines_around_begin_body.rb +42 -0
- data/lib/rubocop/cop/style/empty_lines_around_exception_handling_keywords.rb +127 -0
- data/lib/rubocop/cop/style/empty_literal.rb +17 -9
- data/lib/rubocop/cop/style/end_of_line.rb +25 -3
- data/lib/rubocop/cop/style/file_name.rb +1 -1
- data/lib/rubocop/cop/style/first_method_argument_line_break.rb +1 -1
- data/lib/rubocop/cop/style/first_parameter_indentation.rb +17 -19
- data/lib/rubocop/cop/style/for.rb +2 -4
- data/lib/rubocop/cop/style/format_string.rb +5 -4
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +27 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +2 -2
- data/lib/rubocop/cop/style/indent_assignment.rb +2 -2
- data/lib/rubocop/cop/style/indent_hash.rb +2 -1
- data/lib/rubocop/cop/style/indent_heredoc.rb +173 -0
- data/lib/rubocop/cop/style/indentation_width.rb +61 -29
- data/lib/rubocop/cop/style/inverse_methods.rb +130 -0
- data/lib/rubocop/cop/style/lambda_call.rb +15 -11
- data/lib/rubocop/cop/style/line_end_concatenation.rb +4 -4
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +26 -14
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +6 -16
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +4 -1
- data/lib/rubocop/cop/style/missing_else.rb +4 -3
- data/lib/rubocop/cop/style/mixin_grouping.rb +97 -0
- data/lib/rubocop/cop/style/multiline_memoization.rb +38 -5
- data/lib/rubocop/cop/style/multiline_method_call_brace_layout.rb +2 -3
- data/lib/rubocop/cop/style/multiline_method_call_indentation.rb +38 -19
- data/lib/rubocop/cop/style/mutable_constant.rb +5 -1
- data/lib/rubocop/cop/style/negated_if.rb +73 -1
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +21 -19
- data/lib/rubocop/cop/style/next.rb +5 -5
- data/lib/rubocop/cop/style/non_nil_check.rb +7 -10
- data/lib/rubocop/cop/style/not.rb +3 -4
- data/lib/rubocop/cop/style/numeric_literals.rb +25 -3
- data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -2
- data/lib/rubocop/cop/style/op_method.rb +2 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +6 -3
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +52 -6
- data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +9 -9
- data/lib/rubocop/cop/style/raise_args.rb +28 -24
- data/lib/rubocop/cop/style/redundant_freeze.rb +5 -7
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -3
- data/lib/rubocop/cop/style/redundant_self.rb +17 -35
- data/lib/rubocop/cop/style/rescue_modifier.rb +2 -14
- data/lib/rubocop/cop/style/self_assignment.rb +3 -3
- data/lib/rubocop/cop/style/send.rb +4 -5
- data/lib/rubocop/cop/style/space_after_not.rb +7 -8
- data/lib/rubocop/cop/style/space_around_keyword.rb +8 -9
- data/lib/rubocop/cop/style/space_around_operators.rb +19 -15
- data/lib/rubocop/cop/style/space_before_first_arg.rb +17 -14
- data/lib/rubocop/cop/style/space_inside_brackets.rb +1 -1
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +3 -3
- data/lib/rubocop/cop/style/space_inside_parens.rb +1 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +14 -14
- data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +2 -1
- data/lib/rubocop/cop/style/string_literals.rb +1 -1
- data/lib/rubocop/cop/style/string_methods.rb +10 -5
- data/lib/rubocop/cop/style/struct_inheritance.rb +4 -15
- data/lib/rubocop/cop/style/symbol_array.rb +31 -35
- data/lib/rubocop/cop/style/symbol_proc.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +41 -13
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +6 -9
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +4 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +1 -2
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +12 -34
- data/lib/rubocop/cop/style/zero_length_predicate.rb +11 -4
- data/lib/rubocop/cop/team.rb +4 -1
- data/lib/rubocop/cop/util.rb +33 -26
- data/lib/rubocop/cop/variable_force.rb +13 -13
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -8
- data/lib/rubocop/cop/variable_force/branch.rb +318 -0
- data/lib/rubocop/cop/variable_force/branchable.rb +21 -0
- data/lib/rubocop/cop/variable_force/reference.rb +1 -3
- data/lib/rubocop/cop/variable_force/scope.rb +36 -20
- data/lib/rubocop/cop/variable_force/variable.rb +9 -8
- data/lib/rubocop/formatter/colorizable.rb +10 -10
- data/lib/rubocop/formatter/formatter_set.rb +1 -1
- data/lib/rubocop/formatter/html_formatter.rb +2 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +4 -2
- data/lib/rubocop/magic_comment.rb +20 -6
- data/lib/rubocop/options.rb +1 -1
- data/lib/rubocop/platform.rb +11 -0
- data/lib/rubocop/processed_source.rb +1 -1
- data/lib/rubocop/remote_config.rb +18 -6
- data/lib/rubocop/result_cache.rb +8 -8
- data/lib/rubocop/rspec/cop_helper.rb +2 -0
- data/lib/rubocop/rspec/shared_contexts.rb +20 -0
- data/lib/rubocop/rspec/shared_examples.rb +1 -1
- data/lib/rubocop/runner.rb +2 -2
- data/lib/rubocop/target_finder.rb +64 -6
- data/lib/rubocop/version.rb +2 -4
- metadata +27 -4
- data/lib/rubocop/cop/variable_force/locatable.rb +0 -200
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
class VariableForce
|
6
|
+
# Mix-in module for classes which own a node and need branch information
|
7
|
+
# of the node. The user classes must implement #node and #scope.
|
8
|
+
module Branchable
|
9
|
+
def branch
|
10
|
+
return @branch if instance_variable_defined?(:@branch)
|
11
|
+
@branch = Branch.of(node, scope: scope)
|
12
|
+
end
|
13
|
+
|
14
|
+
def run_exclusively_with?(other)
|
15
|
+
return false if !branch || !other.branch
|
16
|
+
branch.exclusive_with?(other.branch)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
class VariableForce
|
6
6
|
# This class represents each reference of a variable.
|
7
7
|
class Reference
|
8
|
-
include
|
8
|
+
include Branchable
|
9
9
|
|
10
10
|
VARIABLE_REFERENCE_TYPES = (
|
11
11
|
[VARIABLE_REFERENCE_TYPE] +
|
@@ -24,8 +24,6 @@ module RuboCop
|
|
24
24
|
|
25
25
|
@node = node
|
26
26
|
@scope = scope
|
27
|
-
|
28
|
-
super
|
29
27
|
end
|
30
28
|
|
31
29
|
# There's an implicit variable reference by the zero-arity `super`:
|
@@ -15,14 +15,18 @@ module RuboCop
|
|
15
15
|
block: 0..0
|
16
16
|
}.freeze
|
17
17
|
|
18
|
-
attr_reader :node, :variables
|
18
|
+
attr_reader :node, :variables, :naked_top_level
|
19
|
+
alias naked_top_level? naked_top_level
|
19
20
|
|
20
21
|
def initialize(node)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
unless SCOPE_TYPES.include?(node.type)
|
23
|
+
# Accept any node type for top level scope
|
24
|
+
if node.parent
|
25
|
+
raise ArgumentError,
|
26
|
+
"Node type must be any of #{SCOPE_TYPES}, " \
|
27
|
+
"passed #{node.type}"
|
28
|
+
end
|
29
|
+
@naked_top_level = true
|
26
30
|
end
|
27
31
|
@node = node
|
28
32
|
@variables = {}
|
@@ -41,37 +45,43 @@ module RuboCop
|
|
41
45
|
end
|
42
46
|
|
43
47
|
def body_node
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
if naked_top_level?
|
49
|
+
node
|
50
|
+
else
|
51
|
+
child_index = case node.type
|
52
|
+
when :module, :sclass then 1
|
53
|
+
when :def, :class, :block then 2
|
54
|
+
when :defs then 3
|
55
|
+
end
|
49
56
|
|
50
|
-
|
57
|
+
node.children[child_index]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def include?(target_node)
|
62
|
+
!belong_to_outer_scope?(target_node) &&
|
63
|
+
!belong_to_inner_scope?(target_node)
|
51
64
|
end
|
52
65
|
|
53
66
|
def each_node(&block)
|
54
67
|
return to_enum(__method__) unless block_given?
|
68
|
+
yield node if naked_top_level?
|
55
69
|
scan_node(node, &block)
|
56
70
|
end
|
57
71
|
|
58
72
|
private
|
59
73
|
|
60
74
|
def scan_node(node, &block)
|
61
|
-
yield node unless node.parent
|
62
|
-
|
63
75
|
node.each_child_node do |child_node|
|
64
|
-
next
|
76
|
+
next unless include?(child_node)
|
65
77
|
yield child_node
|
66
78
|
scan_node(child_node, &block)
|
67
79
|
end
|
68
80
|
end
|
69
81
|
|
70
|
-
def belong_to_another_scope?(node)
|
71
|
-
belong_to_outer_scope?(node) || belong_to_inner_scope?(node)
|
72
|
-
end
|
73
|
-
|
74
82
|
def belong_to_outer_scope?(target_node)
|
83
|
+
return true if !naked_top_level? && target_node.equal?(node)
|
84
|
+
return true if ancestor_node?(target_node)
|
75
85
|
return false unless target_node.parent.equal?(node)
|
76
86
|
indices = OUTER_SCOPE_CHILD_INDICES[target_node.parent.type]
|
77
87
|
return false unless indices
|
@@ -79,12 +89,18 @@ module RuboCop
|
|
79
89
|
end
|
80
90
|
|
81
91
|
def belong_to_inner_scope?(target_node)
|
82
|
-
return false if target_node.parent.equal?(node)
|
92
|
+
return false if !target_node.parent || target_node.parent.equal?(node)
|
83
93
|
return false unless SCOPE_TYPES.include?(target_node.parent.type)
|
84
94
|
indices = OUTER_SCOPE_CHILD_INDICES[target_node.parent.type]
|
85
95
|
return true unless indices
|
86
96
|
!indices.include?(target_node.sibling_index)
|
87
97
|
end
|
98
|
+
|
99
|
+
def ancestor_node?(target_node)
|
100
|
+
node.each_ancestor.any? do |ancestor_node|
|
101
|
+
ancestor_node.equal?(target_node)
|
102
|
+
end
|
103
|
+
end
|
88
104
|
end
|
89
105
|
end
|
90
106
|
end
|
@@ -41,19 +41,20 @@ module RuboCop
|
|
41
41
|
def reference!(node)
|
42
42
|
reference = Reference.new(node, @scope)
|
43
43
|
@references << reference
|
44
|
-
|
44
|
+
consumed_branches = Set.new
|
45
45
|
|
46
46
|
@assignments.reverse_each do |assignment|
|
47
|
-
next if
|
47
|
+
next if consumed_branches.include?(assignment.branch)
|
48
48
|
|
49
49
|
unless assignment.run_exclusively_with?(reference)
|
50
50
|
assignment.reference!
|
51
51
|
end
|
52
52
|
|
53
|
-
break
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
break if !assignment.branch || assignment.branch == reference.branch
|
54
|
+
|
55
|
+
unless assignment.branch.may_run_incompletely?
|
56
|
+
consumed_branches << assignment.branch
|
57
|
+
end
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
@@ -82,7 +83,7 @@ module RuboCop
|
|
82
83
|
end
|
83
84
|
|
84
85
|
def method_argument?
|
85
|
-
argument? &&
|
86
|
+
argument? && %i(def defs).include?(@scope.node.type)
|
86
87
|
end
|
87
88
|
|
88
89
|
def block_argument?
|
@@ -90,7 +91,7 @@ module RuboCop
|
|
90
91
|
end
|
91
92
|
|
92
93
|
def keyword_argument?
|
93
|
-
|
94
|
+
%i(kwarg kwoptarg).include?(@declaration_node.type)
|
94
95
|
end
|
95
96
|
|
96
97
|
def explicit_block_local_variable?
|
@@ -22,16 +22,16 @@ module RuboCop
|
|
22
22
|
rainbow.wrap(string).color(*args)
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
%i(
|
26
|
+
black
|
27
|
+
red
|
28
|
+
green
|
29
|
+
yellow
|
30
|
+
blue
|
31
|
+
magenta
|
32
|
+
cyan
|
33
|
+
white
|
34
|
+
).each do |color|
|
35
35
|
define_method(color) do |string|
|
36
36
|
colorize(string, color)
|
37
37
|
end
|
@@ -9,7 +9,8 @@ module RuboCop
|
|
9
9
|
# Offenses are displayed at compact form - just the
|
10
10
|
# location of the problem and the associated message.
|
11
11
|
class SimpleTextFormatter < BaseFormatter
|
12
|
-
include Colorizable
|
12
|
+
include Colorizable
|
13
|
+
include PathUtil
|
13
14
|
|
14
15
|
COLOR_FOR_SEVERITY = {
|
15
16
|
refactor: :yellow,
|
@@ -90,7 +91,8 @@ module RuboCop
|
|
90
91
|
|
91
92
|
# A helper class for building the report summary text.
|
92
93
|
class Report
|
93
|
-
include Colorizable
|
94
|
+
include Colorizable
|
95
|
+
include TextUtil
|
94
96
|
|
95
97
|
def initialize(file_count, offense_count, correction_count, rainbow)
|
96
98
|
@file_count = file_count
|
@@ -26,6 +26,10 @@ module RuboCop
|
|
26
26
|
@comment = comment
|
27
27
|
end
|
28
28
|
|
29
|
+
def any?
|
30
|
+
frozen_string_literal_specified? || encoding_specified?
|
31
|
+
end
|
32
|
+
|
29
33
|
# Does the magic comment enable the frozen string literal feature.
|
30
34
|
#
|
31
35
|
# Test whether the frozen string literal value is `true`. Cannot
|
@@ -42,7 +46,7 @@ module RuboCop
|
|
42
46
|
#
|
43
47
|
# @return [Boolean]
|
44
48
|
def frozen_string_literal_specified?
|
45
|
-
|
49
|
+
specified?(frozen_string_literal)
|
46
50
|
end
|
47
51
|
|
48
52
|
# Expose the `frozen_string_literal` value coerced to a boolean if possible.
|
@@ -61,8 +65,16 @@ module RuboCop
|
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
68
|
+
def encoding_specified?
|
69
|
+
specified?(encoding)
|
70
|
+
end
|
71
|
+
|
64
72
|
private
|
65
73
|
|
74
|
+
def specified?(value)
|
75
|
+
!value.nil?
|
76
|
+
end
|
77
|
+
|
66
78
|
# Match the entire comment string with a pattern and take the first capture.
|
67
79
|
#
|
68
80
|
# @param pattern [Regexp]
|
@@ -109,11 +121,10 @@ module RuboCop
|
|
109
121
|
#
|
110
122
|
# @example Emacs style comment
|
111
123
|
# comment = RuboCop::MagicComment.parse(
|
112
|
-
# '# -*- encoding: ASCII-8BIT
|
124
|
+
# '# -*- encoding: ASCII-8BIT -*-'
|
113
125
|
# )
|
114
126
|
#
|
115
|
-
# comment.encoding
|
116
|
-
# comment.frozen_string_literal # => true
|
127
|
+
# comment.encoding # => 'ascii-8bit'
|
117
128
|
#
|
118
129
|
# @see https://www.gnu.org/software/emacs/manual/html_node/emacs/Specify-Coding.html
|
119
130
|
# @see https://git.io/vMCXh Emacs handling in Ruby's parse.y
|
@@ -179,7 +190,7 @@ module RuboCop
|
|
179
190
|
class SimpleComment < MagicComment
|
180
191
|
# Match `encoding` or `coding`
|
181
192
|
def encoding
|
182
|
-
extract(/\b(?:en)?coding: (#{TOKEN})/)
|
193
|
+
extract(/\b(?:en)?coding: (#{TOKEN})/i)
|
183
194
|
end
|
184
195
|
|
185
196
|
private
|
@@ -188,8 +199,11 @@ module RuboCop
|
|
188
199
|
#
|
189
200
|
# The `frozen_string_literal` magic comment only works if it
|
190
201
|
# is the only text in the comment.
|
202
|
+
#
|
203
|
+
# Case-insensitive and dashes/underscores are acceptable.
|
204
|
+
# @see https://git.io/vM7Mg
|
191
205
|
def extract_frozen_string_literal
|
192
|
-
extract(
|
206
|
+
extract(/\A#\s*frozen[_-]string[_-]literal:\s*(#{TOKEN})\s*\z/i)
|
193
207
|
end
|
194
208
|
end
|
195
209
|
end
|
data/lib/rubocop/options.rb
CHANGED
@@ -6,7 +6,7 @@ require 'shellwords'
|
|
6
6
|
module RuboCop
|
7
7
|
# This class handles command line options.
|
8
8
|
class Options
|
9
|
-
EXITING_OPTIONS =
|
9
|
+
EXITING_OPTIONS = %i(version verbose_version show_cops).freeze
|
10
10
|
DEFAULT_MAXIMUM_EXCLUSION_ITEMS = 15
|
11
11
|
|
12
12
|
def initialize
|
@@ -70,7 +70,7 @@ module RuboCop
|
|
70
70
|
|
71
71
|
def valid_syntax?
|
72
72
|
return false if @parser_error
|
73
|
-
@diagnostics.none? { |d|
|
73
|
+
@diagnostics.none? { |d| %i(error fatal).include?(d.level) }
|
74
74
|
end
|
75
75
|
|
76
76
|
# Raw source checksum for tracking infinite loops.
|
@@ -27,17 +27,29 @@ module RuboCop
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def request
|
31
|
-
|
32
|
-
http.use_ssl = true if @uri.instance_of? URI::HTTPS
|
30
|
+
def request(uri = @uri, limit = 10, &block)
|
31
|
+
raise ArgumentError, 'HTTP redirect too deep' if limit.zero?
|
33
32
|
|
34
|
-
|
33
|
+
http = Net::HTTP.new(uri.hostname, uri.port)
|
34
|
+
http.use_ssl = true if uri.instance_of? URI::HTTPS
|
35
|
+
|
36
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
35
37
|
if cache_path_exists?
|
36
38
|
request['If-Modified-Since'] = File.stat(cache_path).mtime.rfc2822
|
37
39
|
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
+
handle_response(http.request(request), limit, &block)
|
42
|
+
end
|
43
|
+
|
44
|
+
def handle_response(response, limit, &block)
|
45
|
+
case response
|
46
|
+
when Net::HTTPSuccess
|
47
|
+
yield response
|
48
|
+
when Net::HTTPRedirection
|
49
|
+
request(URI.parse(response['location']), limit - 1, &block)
|
50
|
+
else
|
51
|
+
response.error!
|
52
|
+
end
|
41
53
|
end
|
42
54
|
|
43
55
|
def cache_path
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -8,8 +8,8 @@ require 'etc'
|
|
8
8
|
module RuboCop
|
9
9
|
# Provides functionality for caching rubocop runs.
|
10
10
|
class ResultCache
|
11
|
-
NON_CHANGING =
|
12
|
-
|
11
|
+
NON_CHANGING = %i(color format formatters out debug fail_level
|
12
|
+
cache fail_fast stdin).freeze
|
13
13
|
|
14
14
|
# Remove old files so that the cache doesn't grow too big. When the
|
15
15
|
# threshold MaxFilesInCache has been exceeded, the oldest 50% of all the
|
@@ -44,20 +44,20 @@ module RuboCop
|
|
44
44
|
puts "Removing the #{remove_count} oldest files from #{cache_root}"
|
45
45
|
end
|
46
46
|
sorted = files.sort_by { |path| File.mtime(path) }
|
47
|
-
remove_files(sorted, dirs, remove_count
|
47
|
+
remove_files(sorted, dirs, remove_count)
|
48
|
+
rescue Errno::ENOENT
|
49
|
+
# This can happen if parallel RuboCop invocations try to remove the
|
50
|
+
# same files. No problem.
|
51
|
+
puts $ERROR_INFO if verbose
|
48
52
|
end
|
49
53
|
|
50
|
-
def remove_files(files, dirs, remove_count
|
54
|
+
def remove_files(files, dirs, remove_count)
|
51
55
|
# Batch file deletions, deleting over 130,000+ files will crash
|
52
56
|
# File.delete.
|
53
57
|
files[0, remove_count].each_slice(10_000).each do |files_slice|
|
54
58
|
File.delete(*files_slice)
|
55
59
|
end
|
56
60
|
dirs.each { |dir| Dir.rmdir(dir) if Dir["#{dir}/*"].empty? }
|
57
|
-
rescue Errno::ENOENT
|
58
|
-
# This can happen if parallel RuboCop invocations try to remove the
|
59
|
-
# same files. No problem.
|
60
|
-
puts $ERROR_INFO if verbose
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|