rubocop 0.75.1 → 0.80.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +4 -4
- data/config/default.yml +374 -335
- data/lib/rubocop.rb +53 -32
- data/lib/rubocop/ast/builder.rb +43 -41
- data/lib/rubocop/ast/node.rb +5 -13
- data/lib/rubocop/ast/node/block_node.rb +2 -0
- data/lib/rubocop/ast/node/def_node.rb +11 -0
- data/lib/rubocop/ast/node/forward_args_node.rb +18 -0
- data/lib/rubocop/ast/node/regexp_node.rb +2 -4
- data/lib/rubocop/ast/node/return_node.rb +24 -0
- data/lib/rubocop/ast/traversal.rb +20 -3
- data/lib/rubocop/cli.rb +11 -227
- data/lib/rubocop/cli/command.rb +21 -0
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
- data/lib/rubocop/cli/command/base.rb +33 -0
- data/lib/rubocop/cli/command/execute_runner.rb +76 -0
- data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
- data/lib/rubocop/cli/command/show_cops.rb +80 -0
- data/lib/rubocop/cli/command/version.rb +17 -0
- data/lib/rubocop/cli/environment.rb +21 -0
- data/lib/rubocop/comment_config.rb +8 -3
- data/lib/rubocop/config.rb +8 -1
- data/lib/rubocop/config_loader.rb +20 -20
- data/lib/rubocop/config_loader_resolver.rb +2 -1
- data/lib/rubocop/config_obsoletion.rb +73 -10
- data/lib/rubocop/config_validator.rb +77 -110
- data/lib/rubocop/cop/autocorrect_logic.rb +7 -4
- data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
- data/lib/rubocop/cop/commissioner.rb +15 -7
- data/lib/rubocop/cop/cop.rb +31 -6
- data/lib/rubocop/cop/corrector.rb +8 -7
- data/lib/rubocop/cop/correctors/space_corrector.rb +1 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/generator.rb +3 -4
- data/lib/rubocop/cop/generator/configuration_injector.rb +2 -2
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
- data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/{align_array.rb → array_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +1 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
- data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
- data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +14 -12
- data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +4 -4
- data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +4 -4
- data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
- data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +16 -8
- data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +5 -5
- data/lib/rubocop/cop/layout/leading_comment_space.rb +33 -2
- data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
- data/lib/rubocop/cop/{metrics → layout}/line_length.rb +68 -112
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +14 -5
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +0 -4
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/{align_parameters.rb → parameter_alignment.rb} +1 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
- data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +50 -7
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +8 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -9
- data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
- data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
- data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
- data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
- data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +26 -26
- data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +18 -15
- data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
- data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +6 -6
- data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +1 -1
- data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
- data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
- data/lib/rubocop/cop/lint/useless_setter_call.rb +5 -1
- data/lib/rubocop/cop/lint/void.rb +4 -4
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
- data/lib/rubocop/cop/migration/department_name.rb +30 -2
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +4 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +7 -7
- data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +172 -0
- data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
- data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
- data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
- data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -4
- data/lib/rubocop/cop/mixin/trailing_comma.rb +16 -18
- data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
- data/lib/rubocop/cop/naming/file_name.rb +12 -5
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +4 -4
- data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
- data/lib/rubocop/cop/offense.rb +11 -0
- data/lib/rubocop/cop/registry.rb +8 -3
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +10 -2
- data/lib/rubocop/cop/style/block_delimiters.rb +60 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- data/lib/rubocop/cop/style/copyright.rb +11 -7
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +2 -2
- data/lib/rubocop/cop/style/empty_method.rb +5 -5
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +1 -1
- data/lib/rubocop/cop/style/format_string.rb +10 -7
- data/lib/rubocop/cop/style/format_string_token.rb +2 -0
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +99 -11
- data/lib/rubocop/cop/style/guard_clause.rb +3 -2
- data/lib/rubocop/cop/style/hash_each_methods.rb +87 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
- data/lib/rubocop/cop/style/hash_transform_keys.rb +79 -0
- data/lib/rubocop/cop/style/hash_transform_values.rb +79 -0
- data/lib/rubocop/cop/style/if_unless_modifier.rb +45 -3
- data/lib/rubocop/cop/style/infinite_loop.rb +5 -4
- data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
- data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
- data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -205
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +169 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +6 -2
- data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +5 -5
- data/lib/rubocop/cop/style/next.rb +5 -5
- data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
- data/lib/rubocop/cop/style/numeric_literals.rb +7 -3
- data/lib/rubocop/cop/style/numeric_predicate.rb +4 -3
- data/lib/rubocop/cop/style/option_hash.rb +3 -3
- data/lib/rubocop/cop/style/or_assignment.rb +3 -2
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
- data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
- data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
- data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
- data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +27 -29
- data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +5 -5
- data/lib/rubocop/cop/style/safe_navigation.rb +13 -10
- data/lib/rubocop/cop/style/semicolon.rb +2 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
- data/lib/rubocop/cop/style/symbol_array.rb +2 -2
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +0 -22
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
- data/lib/rubocop/cop/team.rb +5 -0
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/utils/format_string.rb +10 -18
- data/lib/rubocop/cop/variable_force.rb +11 -6
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -3
- data/lib/rubocop/formatter/formatter_set.rb +1 -0
- data/lib/rubocop/formatter/json_formatter.rb +6 -5
- data/lib/rubocop/formatter/junit_formatter.rb +63 -0
- data/lib/rubocop/formatter/tap_formatter.rb +1 -3
- data/lib/rubocop/node_pattern.rb +100 -12
- data/lib/rubocop/options.rb +17 -11
- data/lib/rubocop/processed_source.rb +1 -1
- data/lib/rubocop/rake_task.rb +1 -0
- data/lib/rubocop/result_cache.rb +24 -8
- data/lib/rubocop/rspec/shared_contexts.rb +5 -0
- data/lib/rubocop/runner.rb +50 -29
- data/lib/rubocop/target_finder.rb +12 -6
- data/lib/rubocop/target_ruby.rb +151 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +69 -35
- data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -209
@@ -8,9 +8,9 @@ module RuboCop
|
|
8
8
|
# In Ruby 2.3 or newer, squiggly heredocs (`<<~`) should be used. If you
|
9
9
|
# use the older rubies, you should introduce some library to your project
|
10
10
|
# (e.g. ActiveSupport, Powerpack or Unindent).
|
11
|
-
# Note: When `
|
11
|
+
# Note: When `Layout/LineLength`'s `AllowHeredoc` is false (not default),
|
12
12
|
# this cop does not add any offenses for long here documents to
|
13
|
-
# avoid `
|
13
|
+
# avoid `Layout/LineLength`'s offenses.
|
14
14
|
#
|
15
15
|
# @example EnforcedStyle: squiggly (default)
|
16
16
|
# # bad
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
# something
|
50
50
|
# RUBY
|
51
51
|
#
|
52
|
-
class
|
52
|
+
class HeredocIndentation < Cop
|
53
53
|
include Heredoc
|
54
54
|
include ConfigurableEnforcedStyle
|
55
55
|
|
@@ -159,11 +159,11 @@ module RuboCop
|
|
159
159
|
end
|
160
160
|
|
161
161
|
def unlimited_heredoc_length?
|
162
|
-
config.for_cop('
|
162
|
+
config.for_cop('Layout/LineLength')['AllowHeredoc']
|
163
163
|
end
|
164
164
|
|
165
165
|
def max_line_length
|
166
|
-
config.for_cop('
|
166
|
+
config.for_cop('Layout/LineLength')['Max']
|
167
167
|
end
|
168
168
|
|
169
169
|
def correct_by_squiggly(node)
|
@@ -35,6 +35,20 @@ module RuboCop
|
|
35
35
|
# # Another line of comment
|
36
36
|
# #*
|
37
37
|
#
|
38
|
+
# @example AllowGemfileRubyComment: false (default)
|
39
|
+
#
|
40
|
+
# # bad
|
41
|
+
#
|
42
|
+
# #ruby=2.7.0
|
43
|
+
# #ruby-gemset=myproject
|
44
|
+
#
|
45
|
+
# @example AllowGemfileRubyComment: true
|
46
|
+
#
|
47
|
+
# # good
|
48
|
+
#
|
49
|
+
# #ruby=2.7.0
|
50
|
+
# #ruby-gemset=myproject
|
51
|
+
#
|
38
52
|
class LeadingCommentSpace < Cop
|
39
53
|
include RangeHelp
|
40
54
|
|
@@ -44,7 +58,8 @@ module RuboCop
|
|
44
58
|
processed_source.each_comment do |comment|
|
45
59
|
next unless comment.text =~ /\A#+[^#\s=:+-]/
|
46
60
|
next if comment.loc.line == 1 && allowed_on_first_line?(comment)
|
47
|
-
next if
|
61
|
+
next if doxygen_comment_style?(comment)
|
62
|
+
next if gemfile_ruby_comment?(comment)
|
48
63
|
|
49
64
|
add_offense(comment)
|
50
65
|
end
|
@@ -80,7 +95,23 @@ module RuboCop
|
|
80
95
|
end
|
81
96
|
|
82
97
|
def doxygen_comment_style?(comment)
|
83
|
-
comment.text.start_with?('#*')
|
98
|
+
allow_doxygen_comment? && comment.text.start_with?('#*')
|
99
|
+
end
|
100
|
+
|
101
|
+
def allow_gemfile_ruby_comment?
|
102
|
+
cop_config['AllowGemfileRubyComment']
|
103
|
+
end
|
104
|
+
|
105
|
+
def gemfile?
|
106
|
+
File.basename(processed_source.file_path).eql?('Gemfile')
|
107
|
+
end
|
108
|
+
|
109
|
+
def ruby_comment_in_gemfile?(comment)
|
110
|
+
gemfile? && comment.text.start_with?('#ruby')
|
111
|
+
end
|
112
|
+
|
113
|
+
def gemfile_ruby_comment?(comment)
|
114
|
+
allow_gemfile_ruby_comment? && ruby_comment_in_gemfile?(comment)
|
84
115
|
end
|
85
116
|
end
|
86
117
|
end
|
@@ -2,10 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'uri'
|
4
4
|
|
5
|
-
# rubocop:disable Metrics/ClassLength
|
6
5
|
module RuboCop
|
7
6
|
module Cop
|
8
|
-
module
|
7
|
+
module Layout
|
9
8
|
# This cop checks the length of lines in the source code.
|
10
9
|
# The maximum length is configurable.
|
11
10
|
# The tab size is configured in the `IndentationWidth`
|
@@ -20,19 +19,25 @@ module RuboCop
|
|
20
19
|
#
|
21
20
|
# If autocorrection is enabled, the following Layout cops
|
22
21
|
# are recommended to further format the broken lines.
|
22
|
+
# (Many of these are enabled by default.)
|
23
23
|
#
|
24
|
-
# -
|
25
|
-
# -
|
26
|
-
# -
|
24
|
+
# - ArgumentAlignment
|
25
|
+
# - BlockAlignment
|
26
|
+
# - BlockDelimiters
|
27
|
+
# - BlockEndNewline
|
27
28
|
# - ClosingParenthesisIndentation
|
28
|
-
# -
|
29
|
-
# -
|
30
|
-
# -
|
31
|
-
# -
|
29
|
+
# - FirstArgumentIndentation
|
30
|
+
# - FirstArrayElementIndentation
|
31
|
+
# - FirstHashElementIndentation
|
32
|
+
# - FirstParameterIndentation
|
33
|
+
# - HashAlignment
|
34
|
+
# - IndentationWidth
|
32
35
|
# - MultilineArrayLineBreaks
|
36
|
+
# - MultilineBlockLayout
|
33
37
|
# - MultilineHashBraceLayout
|
34
38
|
# - MultilineHashKeyLineBreaks
|
35
39
|
# - MultilineMethodArgumentLineBreaks
|
40
|
+
# - ParameterAlignment
|
36
41
|
#
|
37
42
|
# Together, these cops will pretty print hashes, arrays,
|
38
43
|
# method calls, etc. For example, let's say the max columns
|
@@ -58,9 +63,14 @@ module RuboCop
|
|
58
63
|
include ConfigurableMax
|
59
64
|
include IgnoredPattern
|
60
65
|
include RangeHelp
|
66
|
+
include LineLengthHelp
|
61
67
|
|
62
68
|
MSG = 'Line is too long. [%<length>d/%<max>d]'
|
63
69
|
|
70
|
+
def on_block(node)
|
71
|
+
check_for_breakable_block(node)
|
72
|
+
end
|
73
|
+
|
64
74
|
def on_potential_breakable_node(node)
|
65
75
|
check_for_breakable_node(node)
|
66
76
|
end
|
@@ -68,6 +78,10 @@ module RuboCop
|
|
68
78
|
alias on_hash on_potential_breakable_node
|
69
79
|
alias on_send on_potential_breakable_node
|
70
80
|
|
81
|
+
def investigate(processed_source)
|
82
|
+
check_for_breakable_semicolons(processed_source)
|
83
|
+
end
|
84
|
+
|
71
85
|
def investigate_post_walk(processed_source)
|
72
86
|
processed_source.lines.each_with_index do |line, line_index|
|
73
87
|
check_line(line, line_index)
|
@@ -89,29 +103,60 @@ module RuboCop
|
|
89
103
|
return if breakable_node.nil?
|
90
104
|
|
91
105
|
line_index = breakable_node.first_line - 1
|
92
|
-
|
106
|
+
range = breakable_node.source_range
|
107
|
+
|
108
|
+
existing = breakable_range_by_line_index[line_index]
|
109
|
+
return if existing
|
110
|
+
|
111
|
+
breakable_range_by_line_index[line_index] = range
|
93
112
|
end
|
94
113
|
|
95
|
-
def
|
96
|
-
|
114
|
+
def check_for_breakable_semicolons(processed_source)
|
115
|
+
tokens = processed_source.tokens.select { |t| t.type == :tSEMI }
|
116
|
+
tokens.reverse_each do |token|
|
117
|
+
range = breakable_range_after_semicolon(token)
|
118
|
+
breakable_range_by_line_index[range.line - 1] = range if range
|
119
|
+
end
|
97
120
|
end
|
98
121
|
|
99
|
-
def
|
100
|
-
|
122
|
+
def check_for_breakable_block(block_node)
|
123
|
+
return unless block_node.single_line?
|
124
|
+
|
125
|
+
line_index = block_node.loc.line - 1
|
126
|
+
range = breakable_block_range(block_node)
|
127
|
+
pos = range.begin_pos + 1
|
128
|
+
|
129
|
+
breakable_range_by_line_index[line_index] =
|
130
|
+
range_between(pos, pos + 1)
|
101
131
|
end
|
102
132
|
|
103
|
-
def
|
104
|
-
|
133
|
+
def breakable_block_range(block_node)
|
134
|
+
if block_node.arguments?
|
135
|
+
block_node.arguments.loc.end
|
136
|
+
else
|
137
|
+
block_node.loc.begin
|
138
|
+
end
|
105
139
|
end
|
106
140
|
|
107
|
-
def
|
108
|
-
|
141
|
+
def breakable_range_after_semicolon(semicolon_token)
|
142
|
+
range = semicolon_token.pos
|
143
|
+
end_pos = range.end_pos
|
144
|
+
next_range = range_between(end_pos, end_pos + 1)
|
145
|
+
return nil unless next_range.line == range.line
|
146
|
+
|
147
|
+
next_char = next_range.source
|
148
|
+
return nil if /[\r\n]/ =~ next_char
|
149
|
+
return nil if next_char == ';'
|
109
150
|
|
110
|
-
|
151
|
+
next_range
|
111
152
|
end
|
112
153
|
|
113
|
-
def
|
114
|
-
|
154
|
+
def breakable_range_by_line_index
|
155
|
+
@breakable_range_by_line_index ||= {}
|
156
|
+
end
|
157
|
+
|
158
|
+
def heredocs
|
159
|
+
@heredocs ||= extract_heredocs(processed_source.ast)
|
115
160
|
end
|
116
161
|
|
117
162
|
def highlight_start(line)
|
@@ -128,10 +173,7 @@ module RuboCop
|
|
128
173
|
return check_uri_line(line, line_index) if allow_uri?
|
129
174
|
|
130
175
|
register_offense(
|
131
|
-
|
132
|
-
processed_source.buffer, line_index,
|
133
|
-
highlight_start(line)...line_length(line)
|
134
|
-
),
|
176
|
+
excess_range(nil, line, line_index),
|
135
177
|
line,
|
136
178
|
line_index
|
137
179
|
)
|
@@ -150,33 +192,12 @@ module RuboCop
|
|
150
192
|
def register_offense(loc, line, line_index)
|
151
193
|
message = format(MSG, length: line_length(line), max: max)
|
152
194
|
|
153
|
-
breakable_range =
|
195
|
+
breakable_range = breakable_range_by_line_index[line_index]
|
154
196
|
add_offense(breakable_range, location: loc, message: message) do
|
155
197
|
self.max = line_length(line)
|
156
198
|
end
|
157
199
|
end
|
158
200
|
|
159
|
-
def breakable_range(line, line_index)
|
160
|
-
return if line_in_heredoc?(line_index + 1)
|
161
|
-
|
162
|
-
semicolon_range = breakable_semicolon_range(line, line_index)
|
163
|
-
return semicolon_range if semicolon_range
|
164
|
-
|
165
|
-
breakable_node = breakable_nodes_by_line_index[line_index]
|
166
|
-
return breakable_node.source_range if breakable_node
|
167
|
-
end
|
168
|
-
|
169
|
-
def breakable_semicolon_range(line, line_index)
|
170
|
-
semicolon_separated_parts = line.split(';')
|
171
|
-
return if semicolon_separated_parts.length <= 1
|
172
|
-
|
173
|
-
column = semicolon_separated_parts.first.length + 1
|
174
|
-
range = source_range(processed_source.buffer, line_index, column, 1)
|
175
|
-
return if processed_source.commented?(range)
|
176
|
-
|
177
|
-
range
|
178
|
-
end
|
179
|
-
|
180
201
|
def excess_range(uri_range, line, line_index)
|
181
202
|
excessive_position = if uri_range && uri_range.begin < max
|
182
203
|
uri_range.end
|
@@ -225,53 +246,6 @@ module RuboCop
|
|
225
246
|
end
|
226
247
|
end
|
227
248
|
|
228
|
-
def allow_uri?
|
229
|
-
cop_config['AllowURI']
|
230
|
-
end
|
231
|
-
|
232
|
-
def ignore_cop_directives?
|
233
|
-
cop_config['IgnoreCopDirectives']
|
234
|
-
end
|
235
|
-
|
236
|
-
def allowed_uri_position?(line, uri_range)
|
237
|
-
uri_range.begin < max &&
|
238
|
-
(uri_range.end == line_length(line) ||
|
239
|
-
uri_range.end == line_length(line) - 1)
|
240
|
-
end
|
241
|
-
|
242
|
-
def find_excessive_uri_range(line)
|
243
|
-
last_uri_match = match_uris(line).last
|
244
|
-
return nil unless last_uri_match
|
245
|
-
|
246
|
-
begin_position, end_position =
|
247
|
-
last_uri_match.offset(0).map do |pos|
|
248
|
-
pos + indentation_difference(line)
|
249
|
-
end
|
250
|
-
return nil if begin_position < max && end_position < max
|
251
|
-
|
252
|
-
begin_position...end_position
|
253
|
-
end
|
254
|
-
|
255
|
-
def match_uris(string)
|
256
|
-
matches = []
|
257
|
-
string.scan(uri_regexp) do
|
258
|
-
matches << $LAST_MATCH_INFO if valid_uri?($LAST_MATCH_INFO[0])
|
259
|
-
end
|
260
|
-
matches
|
261
|
-
end
|
262
|
-
|
263
|
-
def valid_uri?(uri_ish_string)
|
264
|
-
URI.parse(uri_ish_string)
|
265
|
-
true
|
266
|
-
rescue URI::InvalidURIError, NoMethodError
|
267
|
-
false
|
268
|
-
end
|
269
|
-
|
270
|
-
def uri_regexp
|
271
|
-
@uri_regexp ||=
|
272
|
-
URI::DEFAULT_PARSER.make_regexp(cop_config['URISchemes'])
|
273
|
-
end
|
274
|
-
|
275
249
|
def check_directive_line(line, line_index)
|
276
250
|
return if line_length_without_directive(line) <= max
|
277
251
|
|
@@ -287,23 +261,6 @@ module RuboCop
|
|
287
261
|
)
|
288
262
|
end
|
289
263
|
|
290
|
-
def directive_on_source_line?(line_index)
|
291
|
-
source_line_number = line_index + processed_source.buffer.first_line
|
292
|
-
comment =
|
293
|
-
processed_source
|
294
|
-
.comments
|
295
|
-
.detect { |e| e.location.line == source_line_number }
|
296
|
-
|
297
|
-
return false unless comment
|
298
|
-
|
299
|
-
comment.text.match(CommentConfig::COMMENT_DIRECTIVE_REGEXP)
|
300
|
-
end
|
301
|
-
|
302
|
-
def line_length_without_directive(line)
|
303
|
-
before_comment, = line.split(CommentConfig::COMMENT_DIRECTIVE_REGEXP)
|
304
|
-
before_comment.rstrip.length
|
305
|
-
end
|
306
|
-
|
307
264
|
def check_uri_line(line, line_index)
|
308
265
|
uri_range = find_excessive_uri_range(line)
|
309
266
|
return if uri_range && allowed_uri_position?(line, uri_range)
|
@@ -318,4 +275,3 @@ module RuboCop
|
|
318
275
|
end
|
319
276
|
end
|
320
277
|
end
|
321
|
-
# rubocop:enable Metrics/ClassLength
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
'on the same line as the assignment operator `=`.'
|
44
44
|
|
45
45
|
def check_assignment(node, rhs)
|
46
|
-
return if node.send_type?
|
46
|
+
return if node.send_type? && node.loc.operator&.source != '='
|
47
47
|
return unless rhs
|
48
48
|
return unless supported_types.include?(rhs.type)
|
49
49
|
return if rhs.first_line == rhs.last_line
|
@@ -97,7 +97,8 @@ module RuboCop
|
|
97
97
|
def line_break_necessary_in_args?(node)
|
98
98
|
needed_length = node.source_range.column +
|
99
99
|
node.source.lines.first.length +
|
100
|
-
block_arg_string(node.arguments).length +
|
100
|
+
block_arg_string(node, node.arguments).length +
|
101
|
+
PIPE_SIZE
|
101
102
|
needed_length > max_line_length
|
102
103
|
end
|
103
104
|
|
@@ -115,7 +116,8 @@ module RuboCop
|
|
115
116
|
newlines: false
|
116
117
|
).end_pos
|
117
118
|
range = range_between(node.loc.begin.end.begin_pos, end_pos)
|
118
|
-
corrector.replace(range,
|
119
|
+
corrector.replace(range,
|
120
|
+
" |#{block_arg_string(node, node.arguments)}|")
|
119
121
|
end
|
120
122
|
|
121
123
|
def autocorrect_body(corrector, node, block_body)
|
@@ -131,14 +133,21 @@ module RuboCop
|
|
131
133
|
"\n #{' ' * block_start_col}")
|
132
134
|
end
|
133
135
|
|
134
|
-
def block_arg_string(args)
|
135
|
-
args.children.map do |arg|
|
136
|
+
def block_arg_string(node, args)
|
137
|
+
arg_string = args.children.map do |arg|
|
136
138
|
if arg.mlhs_type?
|
137
|
-
"(#{block_arg_string(arg)})"
|
139
|
+
"(#{block_arg_string(node, arg)})"
|
138
140
|
else
|
139
141
|
arg.source
|
140
142
|
end
|
141
143
|
end.join(', ')
|
144
|
+
arg_string += ',' if include_trailing_comma?(node.arguments)
|
145
|
+
arg_string
|
146
|
+
end
|
147
|
+
|
148
|
+
def include_trailing_comma?(args)
|
149
|
+
arg_count = args.each_descendant(:arg).to_a.size
|
150
|
+
arg_count == 1 && args.source.include?(',')
|
142
151
|
end
|
143
152
|
end
|
144
153
|
end
|
@@ -105,10 +105,6 @@ module RuboCop
|
|
105
105
|
ALWAYS_SAME_LINE_MESSAGE = 'Closing hash brace must be on the same ' \
|
106
106
|
'line as the last hash element.'
|
107
107
|
|
108
|
-
def self.autocorrect_incompatible_with
|
109
|
-
[Style::BracesAroundHashParameters]
|
110
|
-
end
|
111
|
-
|
112
108
|
def on_hash(node)
|
113
109
|
check_brace_layout(node)
|
114
110
|
end
|