rubocop 0.77.0 → 0.78.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +37 -25
- data/lib/rubocop.rb +5 -2
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +7 -7
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_obsoletion.rb +3 -3
- data/lib/rubocop/config_validator.rb +6 -4
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
- data/lib/rubocop/cop/cop.rb +3 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +4 -4
- data/lib/rubocop/cop/{metrics → layout}/line_length.rb +5 -78
- data/lib/rubocop/cop/layout/space_around_operators.rb +31 -6
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +4 -4
- data/lib/rubocop/cop/mixin/alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
- data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +6 -3
- data/lib/rubocop/cop/offense.rb +11 -0
- data/lib/rubocop/cop/style/attr.rb +8 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- data/lib/rubocop/cop/style/guard_clause.rb +3 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +38 -3
- data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
- data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/json_formatter.rb +6 -5
- data/lib/rubocop/node_pattern.rb +1 -1
- data/lib/rubocop/options.rb +8 -8
- data/lib/rubocop/result_cache.rb +2 -0
- data/lib/rubocop/runner.rb +5 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1c6769965ef19c24fed5115e5ee0e6949aef81f2d4f0c64a28e867b694b8f8b
|
4
|
+
data.tar.gz: 6785ee7c23edbb4b47414ca32a9cb7b7e24565c454c8e4a33f742b9a15de8e5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3e28e9ed24f5e757ce4c24f4ee4d079eb5e7ac1c6f50bd50fb512c5b4986d84ec19b0ba426a9b077ca734177a5e5139a50c12f5fe331216abee67bd6a2436b4
|
7
|
+
data.tar.gz: 2f2739072557a141d69a51037e38a0973bee53caf40d216610eaffd3a8f14409e64562ed71a49803ad8b11b71fedc51312657efaecb27189900c7b5c44b2cb8c
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
|
|
53
53
|
might want to use a conservative version lock in your `Gemfile`:
|
54
54
|
|
55
55
|
```rb
|
56
|
-
gem 'rubocop', '~> 0.
|
56
|
+
gem 'rubocop', '~> 0.78.0', require: false
|
57
57
|
```
|
58
58
|
|
59
59
|
## Quickstart
|
data/config/default.yml
CHANGED
@@ -59,6 +59,7 @@ AllCops:
|
|
59
59
|
- '**/Vagrantfile'
|
60
60
|
Exclude:
|
61
61
|
- 'node_modules/**/*'
|
62
|
+
- 'tmp/**/*'
|
62
63
|
- 'vendor/**/*'
|
63
64
|
- '.git/**/*'
|
64
65
|
# Default formatter will be used if no `-f/--format` option is given.
|
@@ -196,9 +197,10 @@ Gemspec/RequiredRubyVersion:
|
|
196
197
|
VersionAdded: '0.52'
|
197
198
|
Include:
|
198
199
|
- '**/*.gemspec'
|
199
|
-
|
200
|
+
|
200
201
|
Gemspec/RubyVersionGlobalsUsage:
|
201
202
|
Description: Checks usage of RUBY_VERSION in gemspec.
|
203
|
+
StyleGuide: '#no-ruby-version-in-the-gemspec'
|
202
204
|
Enabled: true
|
203
205
|
VersionAdded: '0.72'
|
204
206
|
Include:
|
@@ -799,6 +801,29 @@ Layout/LeadingEmptyLines:
|
|
799
801
|
VersionAdded: '0.57'
|
800
802
|
VersionChanged: '0.77'
|
801
803
|
|
804
|
+
Layout/LineLength:
|
805
|
+
Description: 'Limit lines to 80 characters.'
|
806
|
+
StyleGuide: '#80-character-limits'
|
807
|
+
Enabled: true
|
808
|
+
VersionAdded: '0.25'
|
809
|
+
VersionChanged: '0.78'
|
810
|
+
AutoCorrect: false
|
811
|
+
Max: 80
|
812
|
+
# To make it possible to copy or click on URIs in the code, we allow lines
|
813
|
+
# containing a URI to be longer than Max.
|
814
|
+
AllowHeredoc: true
|
815
|
+
AllowURI: true
|
816
|
+
URISchemes:
|
817
|
+
- http
|
818
|
+
- https
|
819
|
+
# The IgnoreCopDirectives option causes the LineLength rule to ignore cop
|
820
|
+
# directives like '# rubocop: enable ...' when calculating a line's length.
|
821
|
+
IgnoreCopDirectives: true
|
822
|
+
# The IgnoredPatterns option is a list of !ruby/regexp and/or string
|
823
|
+
# elements. Strings will be converted to Regexp objects. A line that matches
|
824
|
+
# any regular expression listed in this option will be ignored by LineLength.
|
825
|
+
IgnoredPatterns: []
|
826
|
+
|
802
827
|
Layout/MultilineArrayBraceLayout:
|
803
828
|
Description: >-
|
804
829
|
Checks that the closing brace in an array literal is
|
@@ -1042,6 +1067,10 @@ Layout/SpaceAroundOperators:
|
|
1042
1067
|
# with an operator on the previous or next line, not counting empty lines
|
1043
1068
|
# or comment lines.
|
1044
1069
|
AllowForAlignment: true
|
1070
|
+
EnforcedStyleForExponentOperator: no_space
|
1071
|
+
SupportedStylesForExponentOperator:
|
1072
|
+
- space
|
1073
|
+
- no_space
|
1045
1074
|
|
1046
1075
|
Layout/SpaceBeforeBlockBraces:
|
1047
1076
|
Description: >-
|
@@ -1471,6 +1500,12 @@ Lint/NextWithoutAccumulator:
|
|
1471
1500
|
Enabled: true
|
1472
1501
|
VersionAdded: '0.36'
|
1473
1502
|
|
1503
|
+
Lint/NonDeterministicRequireOrder:
|
1504
|
+
Description: 'Always sort arrays returned by Dir.glob when requiring files.'
|
1505
|
+
Enabled: true
|
1506
|
+
VersionAdded: '0.78'
|
1507
|
+
Safe: false
|
1508
|
+
|
1474
1509
|
Lint/NonLocalExitFromIterator:
|
1475
1510
|
Description: 'Do not use return in iterator to cause non-local exit.'
|
1476
1511
|
Enabled: true
|
@@ -1809,29 +1844,6 @@ Metrics/CyclomaticComplexity:
|
|
1809
1844
|
VersionAdded: '0.25'
|
1810
1845
|
Max: 6
|
1811
1846
|
|
1812
|
-
Metrics/LineLength:
|
1813
|
-
Description: 'Limit lines to 80 characters.'
|
1814
|
-
StyleGuide: '#80-character-limits'
|
1815
|
-
Enabled: true
|
1816
|
-
VersionAdded: '0.25'
|
1817
|
-
VersionChanged: '0.68'
|
1818
|
-
AutoCorrect: false
|
1819
|
-
Max: 80
|
1820
|
-
# To make it possible to copy or click on URIs in the code, we allow lines
|
1821
|
-
# containing a URI to be longer than Max.
|
1822
|
-
AllowHeredoc: true
|
1823
|
-
AllowURI: true
|
1824
|
-
URISchemes:
|
1825
|
-
- http
|
1826
|
-
- https
|
1827
|
-
# The IgnoreCopDirectives option causes the LineLength rule to ignore cop
|
1828
|
-
# directives like '# rubocop: enable ...' when calculating a line's length.
|
1829
|
-
IgnoreCopDirectives: true
|
1830
|
-
# The IgnoredPatterns option is a list of !ruby/regexp and/or string
|
1831
|
-
# elements. Strings will be converted to Regexp objects. A line that matches
|
1832
|
-
# any regular expression listed in this option will be ignored by LineLength.
|
1833
|
-
IgnoredPatterns: []
|
1834
|
-
|
1835
1847
|
Metrics/MethodLength:
|
1836
1848
|
Description: 'Avoid methods longer than 10 lines of code.'
|
1837
1849
|
StyleGuide: '#short-methods'
|
@@ -3842,7 +3854,7 @@ Style/TrivialAccessors:
|
|
3842
3854
|
# Commonly used in DSLs
|
3843
3855
|
AllowDSLWriters: false
|
3844
3856
|
IgnoreClassMethods: false
|
3845
|
-
|
3857
|
+
AllowedMethods:
|
3846
3858
|
- to_ary
|
3847
3859
|
- to_a
|
3848
3860
|
- to_c
|
data/lib/rubocop.rb
CHANGED
@@ -123,6 +123,7 @@ require_relative 'rubocop/cop/mixin/ignored_pattern'
|
|
123
123
|
require_relative 'rubocop/cop/mixin/ignored_methods'
|
124
124
|
require_relative 'rubocop/cop/mixin/integer_node'
|
125
125
|
require_relative 'rubocop/cop/mixin/interpolation'
|
126
|
+
require_relative 'rubocop/cop/mixin/line_length_help'
|
126
127
|
require_relative 'rubocop/cop/mixin/match_range'
|
127
128
|
require_relative 'rubocop/cop/mixin/method_complexity'
|
128
129
|
require_relative 'rubocop/cop/mixin/method_preference'
|
@@ -142,6 +143,7 @@ require_relative 'rubocop/cop/mixin/percent_array'
|
|
142
143
|
require_relative 'rubocop/cop/mixin/percent_literal'
|
143
144
|
require_relative 'rubocop/cop/mixin/preceding_following_alignment'
|
144
145
|
require_relative 'rubocop/cop/mixin/preferred_delimiters'
|
146
|
+
require_relative 'rubocop/cop/mixin/rational_literal'
|
145
147
|
require_relative 'rubocop/cop/mixin/rescue_node'
|
146
148
|
require_relative 'rubocop/cop/mixin/safe_assignment'
|
147
149
|
require_relative 'rubocop/cop/mixin/space_after_punctuation'
|
@@ -211,7 +213,7 @@ require_relative 'rubocop/cop/layout/empty_lines_around_arguments'
|
|
211
213
|
require_relative 'rubocop/cop/layout/empty_lines_around_begin_body'
|
212
214
|
require_relative 'rubocop/cop/layout/empty_lines_around_block_body'
|
213
215
|
require_relative 'rubocop/cop/layout/empty_lines_around_class_body'
|
214
|
-
require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable
|
216
|
+
require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable Layout/LineLength
|
215
217
|
require_relative 'rubocop/cop/layout/empty_lines_around_method_body'
|
216
218
|
require_relative 'rubocop/cop/layout/empty_lines_around_module_body'
|
217
219
|
require_relative 'rubocop/cop/layout/empty_lines'
|
@@ -234,6 +236,7 @@ require_relative 'rubocop/cop/layout/indentation_width'
|
|
234
236
|
require_relative 'rubocop/cop/layout/initial_indentation'
|
235
237
|
require_relative 'rubocop/cop/layout/leading_comment_space'
|
236
238
|
require_relative 'rubocop/cop/layout/leading_empty_lines'
|
239
|
+
require_relative 'rubocop/cop/layout/line_length'
|
237
240
|
require_relative 'rubocop/cop/layout/multiline_array_brace_layout'
|
238
241
|
require_relative 'rubocop/cop/layout/multiline_array_line_breaks'
|
239
242
|
require_relative 'rubocop/cop/layout/multiline_assignment_layout'
|
@@ -313,6 +316,7 @@ require_relative 'rubocop/cop/lint/multiple_comparison'
|
|
313
316
|
require_relative 'rubocop/cop/lint/nested_method_definition'
|
314
317
|
require_relative 'rubocop/cop/lint/nested_percent_literal'
|
315
318
|
require_relative 'rubocop/cop/lint/next_without_accumulator'
|
319
|
+
require_relative 'rubocop/cop/lint/non_deterministic_require_order'
|
316
320
|
require_relative 'rubocop/cop/lint/non_local_exit_from_iterator'
|
317
321
|
require_relative 'rubocop/cop/lint/number_conversion'
|
318
322
|
require_relative 'rubocop/cop/lint/ordered_magic_comments'
|
@@ -364,7 +368,6 @@ require_relative 'rubocop/cop/metrics/abc_size'
|
|
364
368
|
require_relative 'rubocop/cop/metrics/block_length'
|
365
369
|
require_relative 'rubocop/cop/metrics/block_nesting'
|
366
370
|
require_relative 'rubocop/cop/metrics/class_length'
|
367
|
-
require_relative 'rubocop/cop/metrics/line_length'
|
368
371
|
require_relative 'rubocop/cop/metrics/method_length'
|
369
372
|
require_relative 'rubocop/cop/metrics/module_length'
|
370
373
|
require_relative 'rubocop/cop/metrics/parameter_lists'
|
@@ -7,13 +7,13 @@ module RuboCop
|
|
7
7
|
class AutoGenerateConfig < Base
|
8
8
|
self.command_name = :auto_gen_config
|
9
9
|
|
10
|
-
PHASE_1 = 'Phase 1 of 2: run
|
10
|
+
PHASE_1 = 'Phase 1 of 2: run Layout/LineLength cop'
|
11
11
|
PHASE_2 = 'Phase 2 of 2: run all cops'
|
12
12
|
|
13
13
|
PHASE_1_OVERRIDDEN =
|
14
|
-
'(skipped because the default
|
14
|
+
'(skipped because the default Layout/LineLength:Max is overridden)'
|
15
15
|
PHASE_1_DISABLED =
|
16
|
-
'(skipped because
|
16
|
+
'(skipped because Layout/LineLength is disabled)'
|
17
17
|
|
18
18
|
def run
|
19
19
|
add_formatter
|
@@ -54,15 +54,15 @@ module RuboCop
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def line_length_cop(config)
|
57
|
-
config.for_cop('
|
57
|
+
config.for_cop('Layout/LineLength')
|
58
58
|
end
|
59
59
|
|
60
|
-
# Do an initial run with only
|
61
|
-
# depend on
|
60
|
+
# Do an initial run with only Layout/LineLength so that cops that
|
61
|
+
# depend on Layout/LineLength:Max get the correct value for that
|
62
62
|
# parameter.
|
63
63
|
def run_line_length_cop
|
64
64
|
puts Rainbow(PHASE_1).yellow
|
65
|
-
@options[:only] = ['
|
65
|
+
@options[:only] = ['Layout/LineLength']
|
66
66
|
execute_runner
|
67
67
|
@options.delete(:only)
|
68
68
|
@config_store = ConfigStore.new
|
data/lib/rubocop/config.rb
CHANGED
@@ -115,7 +115,7 @@ module RuboCop
|
|
115
115
|
relative_file_path = path_relative_to_config(file)
|
116
116
|
|
117
117
|
# Optimization to quickly decide if the given file is hidden (on the top
|
118
|
-
# level) and
|
118
|
+
# level) and cannot be matched by any pattern.
|
119
119
|
is_hidden = relative_file_path.start_with?('.') &&
|
120
120
|
!relative_file_path.start_with?('..')
|
121
121
|
return false if is_hidden && !possibly_include_hidden?
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
Style/VariableName Style/VariableNumber
|
49
49
|
Style/AccessorMethodName Style/AsciiIdentifiers],
|
50
50
|
'Layout' => %w[Lint/BlockAlignment Lint/EndAlignment
|
51
|
-
Lint/DefEndAlignment],
|
51
|
+
Lint/DefEndAlignment Metrics/LineLength],
|
52
52
|
'Lint' => 'Style/FlipFlop'
|
53
53
|
}.map do |new_department, old_names|
|
54
54
|
Array(old_names).map do |old_name|
|
@@ -114,13 +114,13 @@ module RuboCop
|
|
114
114
|
cops: 'Style/IfUnlessModifier',
|
115
115
|
parameters: 'MaxLineLength',
|
116
116
|
alternative: '`Style/IfUnlessModifier: MaxLineLength` has been ' \
|
117
|
-
'removed. Use `
|
117
|
+
'removed. Use `Layout/LineLength: Max` instead'
|
118
118
|
},
|
119
119
|
{
|
120
120
|
cops: 'Style/WhileUntilModifier',
|
121
121
|
parameters: 'MaxLineLength',
|
122
122
|
alternative: '`Style/WhileUntilModifier: MaxLineLength` has been ' \
|
123
|
-
'removed. Use `
|
123
|
+
'removed. Use `Layout/LineLength: Max` instead'
|
124
124
|
},
|
125
125
|
{
|
126
126
|
cops: 'AllCops',
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
|
42
42
|
@config_obsoletion.reject_obsolete_cops_and_parameters
|
43
43
|
|
44
|
-
|
44
|
+
alert_about_unrecognized_cops(invalid_cop_names)
|
45
45
|
check_target_ruby
|
46
46
|
validate_parameter_names(valid_cop_names)
|
47
47
|
validate_enforced_styles(valid_cop_names)
|
@@ -96,7 +96,8 @@ module RuboCop
|
|
96
96
|
raise ValidationError, msg
|
97
97
|
end
|
98
98
|
|
99
|
-
def
|
99
|
+
def alert_about_unrecognized_cops(invalid_cop_names)
|
100
|
+
unknown_cops = []
|
100
101
|
invalid_cop_names.each do |name|
|
101
102
|
# There could be a custom cop with this name. If so, don't warn
|
102
103
|
next if Cop::Cop.registry.contains_cop_matching?([name])
|
@@ -106,9 +107,10 @@ module RuboCop
|
|
106
107
|
# to do so than to pass the value around to various methods.
|
107
108
|
next if name == 'inherit_mode'
|
108
109
|
|
109
|
-
|
110
|
-
|
110
|
+
unknown_cops << "unrecognized cop #{name} found in " \
|
111
|
+
"#{smart_loaded_path}"
|
111
112
|
end
|
113
|
+
raise ValidationError, unknown_cops.join(', ') if unknown_cops.any?
|
112
114
|
end
|
113
115
|
|
114
116
|
def validate_syntax_cop
|
@@ -13,8 +13,8 @@ module RuboCop
|
|
13
13
|
#
|
14
14
|
# However, it don't replace all `sources` of `http://` with `https://`.
|
15
15
|
# For example, when specifying an internal gem server using HTTP on the
|
16
|
-
# intranet, a use case where HTTPS
|
17
|
-
# Consider using HTTP only if you
|
16
|
+
# intranet, a use case where HTTPS cannot be specified was considered.
|
17
|
+
# Consider using HTTP only if you cannot use HTTPS.
|
18
18
|
#
|
19
19
|
# @example
|
20
20
|
# # bad
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -172,6 +172,8 @@ module RuboCop
|
|
172
172
|
end
|
173
173
|
|
174
174
|
def disable_uncorrectable(node)
|
175
|
+
return unless node
|
176
|
+
|
175
177
|
@disabled_lines ||= {}
|
176
178
|
line = node.location.line
|
177
179
|
return if @disabled_lines.key?(line)
|
@@ -217,7 +219,7 @@ module RuboCop
|
|
217
219
|
!relevant_file?(file)
|
218
220
|
end
|
219
221
|
|
220
|
-
# This method should be
|
222
|
+
# This method should be overridden when a cop's behavior depends
|
221
223
|
# on state that lives outside of these locations:
|
222
224
|
#
|
223
225
|
# (1) the file under inspection
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
# rubocop:disable
|
5
|
+
# rubocop:disable Layout/LineLength
|
6
6
|
module Layout
|
7
7
|
# This cop checks the indentation of the first argument in a method call.
|
8
8
|
# Arguments after the first one are checked by Layout/ArgumentAlignment,
|
@@ -143,7 +143,7 @@ module RuboCop
|
|
143
143
|
# second_param
|
144
144
|
#
|
145
145
|
class FirstArgumentIndentation < Cop
|
146
|
-
# rubocop:enable
|
146
|
+
# rubocop:enable Layout/LineLength
|
147
147
|
include Alignment
|
148
148
|
include ConfigurableEnforcedStyle
|
149
149
|
include RangeHelp
|
@@ -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
|
@@ -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)
|
@@ -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`
|
@@ -58,6 +57,7 @@ module RuboCop
|
|
58
57
|
include ConfigurableMax
|
59
58
|
include IgnoredPattern
|
60
59
|
include RangeHelp
|
60
|
+
include LineLengthHelp
|
61
61
|
|
62
62
|
MSG = 'Line is too long. [%<length>d/%<max>d]'
|
63
63
|
|
@@ -130,20 +130,6 @@ module RuboCop
|
|
130
130
|
@heredocs ||= extract_heredocs(processed_source.ast)
|
131
131
|
end
|
132
132
|
|
133
|
-
def tab_indentation_width
|
134
|
-
config.for_cop('Layout/Tab')['IndentationWidth']
|
135
|
-
end
|
136
|
-
|
137
|
-
def indentation_difference(line)
|
138
|
-
return 0 unless tab_indentation_width
|
139
|
-
|
140
|
-
line.match(/^\t*/)[0].size * (tab_indentation_width - 1)
|
141
|
-
end
|
142
|
-
|
143
|
-
def line_length(line)
|
144
|
-
line.length + indentation_difference(line)
|
145
|
-
end
|
146
|
-
|
147
133
|
def highlight_start(line)
|
148
134
|
max - indentation_difference(line)
|
149
135
|
end
|
@@ -225,51 +211,10 @@ module RuboCop
|
|
225
211
|
end
|
226
212
|
end
|
227
213
|
|
228
|
-
def
|
229
|
-
|
230
|
-
|
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])
|
214
|
+
def line_in_heredoc?(line_number)
|
215
|
+
heredocs.any? do |range, _delimiter|
|
216
|
+
range.cover?(line_number)
|
259
217
|
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
218
|
end
|
274
219
|
|
275
220
|
def check_directive_line(line, line_index)
|
@@ -287,23 +232,6 @@ module RuboCop
|
|
287
232
|
)
|
288
233
|
end
|
289
234
|
|
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
235
|
def check_uri_line(line, line_index)
|
308
236
|
uri_range = find_excessive_uri_range(line)
|
309
237
|
return if uri_range && allowed_uri_position?(line, uri_range)
|
@@ -318,4 +246,3 @@ module RuboCop
|
|
318
246
|
end
|
319
247
|
end
|
320
248
|
end
|
321
|
-
# rubocop:enable Metrics/ClassLength
|