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
@@ -49,8 +49,9 @@ module RuboCop
|
|
49
49
|
|
50
50
|
if body.if_type?
|
51
51
|
check_ending_if(body)
|
52
|
-
elsif body.begin_type?
|
53
|
-
|
52
|
+
elsif body.begin_type?
|
53
|
+
final_expression = body.children.last
|
54
|
+
check_ending_if(final_expression) if final_expression&.if_type?
|
54
55
|
end
|
55
56
|
end
|
56
57
|
alias on_defs on_def
|
@@ -7,7 +7,7 @@ module RuboCop
|
|
7
7
|
# written as modifier `if`/`unless`. The cop also checks for modifier
|
8
8
|
# `if`/`unless` lines that exceed the maximum line length.
|
9
9
|
#
|
10
|
-
# The maximum line length is configured in the `
|
10
|
+
# The maximum line length is configured in the `Layout/LineLength`
|
11
11
|
# cop. The tab size is configured in the `IndentationWidth` of the
|
12
12
|
# `Layout/Tab` cop.
|
13
13
|
#
|
@@ -32,6 +32,8 @@ module RuboCop
|
|
32
32
|
# end
|
33
33
|
class IfUnlessModifier < Cop
|
34
34
|
include StatementModifier
|
35
|
+
include LineLengthHelp
|
36
|
+
include IgnoredPattern
|
35
37
|
|
36
38
|
MSG_USE_MODIFIER = 'Favor modifier `%<keyword>s` usage when having a ' \
|
37
39
|
'single-line body. Another good alternative is ' \
|
@@ -66,6 +68,10 @@ module RuboCop
|
|
66
68
|
|
67
69
|
private
|
68
70
|
|
71
|
+
def ignored_patterns
|
72
|
+
config.for_cop('Layout/LineLength')['IgnoredPatterns'] || []
|
73
|
+
end
|
74
|
+
|
69
75
|
def too_long_single_line?(node)
|
70
76
|
return false unless max_line_length
|
71
77
|
|
@@ -73,12 +79,41 @@ module RuboCop
|
|
73
79
|
return false unless range.first_line == range.last_line
|
74
80
|
return false unless line_length_enabled_at_line?(range.first_line)
|
75
81
|
|
76
|
-
range.
|
82
|
+
line = range.source_line
|
83
|
+
return false if line_length(line) <= max_line_length
|
84
|
+
|
85
|
+
too_long_line_based_on_config?(range, line)
|
86
|
+
end
|
87
|
+
|
88
|
+
def too_long_line_based_on_config?(range, line)
|
89
|
+
return false if matches_ignored_pattern?(line)
|
90
|
+
|
91
|
+
too_long = too_long_line_based_on_ignore_cop_directives?(range, line)
|
92
|
+
return too_long unless too_long == :undetermined
|
93
|
+
|
94
|
+
too_long_line_based_on_allow_uri?(line)
|
95
|
+
end
|
96
|
+
|
97
|
+
def too_long_line_based_on_ignore_cop_directives?(range, line)
|
98
|
+
if ignore_cop_directives? && directive_on_source_line?(range.line - 1)
|
99
|
+
return line_length_without_directive(line) > max_line_length
|
100
|
+
end
|
101
|
+
|
102
|
+
:undetermined
|
103
|
+
end
|
104
|
+
|
105
|
+
def too_long_line_based_on_allow_uri?(line)
|
106
|
+
if allow_uri?
|
107
|
+
uri_range = find_excessive_uri_range(line)
|
108
|
+
return false if uri_range && allowed_uri_position?(line, uri_range)
|
109
|
+
end
|
110
|
+
|
111
|
+
true
|
77
112
|
end
|
78
113
|
|
79
114
|
def line_length_enabled_at_line?(line)
|
80
115
|
processed_source.comment_config
|
81
|
-
.cop_enabled_at_line?('
|
116
|
+
.cop_enabled_at_line?('Layout/LineLength', line)
|
82
117
|
end
|
83
118
|
|
84
119
|
def named_capture_in_condition?(node)
|
@@ -58,7 +58,7 @@ module RuboCop
|
|
58
58
|
# `loop do` without further modification. The reason is that a
|
59
59
|
# variable that's introduced inside a while/until loop is in scope
|
60
60
|
# outside of that loop too, but a variable that's assigned for the
|
61
|
-
# first time inside a block
|
61
|
+
# first time inside a block cannot be accessed after the block. In
|
62
62
|
# those more complicated cases we don't report an offense.
|
63
63
|
return if @variables.any? do |var|
|
64
64
|
assigned_inside_loop?(var, range) &&
|
@@ -20,8 +20,14 @@ module RuboCop
|
|
20
20
|
# a, *b, _ = foo()
|
21
21
|
# # => The correction `a, *b, = foo()` is a syntax error
|
22
22
|
#
|
23
|
-
#
|
23
|
+
# @example AllowNamedUnderscoreVariables: true (default)
|
24
|
+
# # good
|
24
25
|
# a, b, _something = foo()
|
26
|
+
#
|
27
|
+
# @example AllowNamedUnderscoreVariables: false
|
28
|
+
# # bad
|
29
|
+
# a, b, _something = foo()
|
30
|
+
#
|
25
31
|
class TrailingUnderscoreVariable < Cop
|
26
32
|
include SurroundingSpace
|
27
33
|
include RangeHelp
|
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Style
|
6
6
|
# Checks for while and until statements that would fit on one line
|
7
7
|
# if written as a modifier while/until. The maximum line length is
|
8
|
-
# configured in the `
|
8
|
+
# configured in the `Layout/LineLength` cop.
|
9
9
|
#
|
10
10
|
# @example
|
11
11
|
# # bad
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable
|
3
|
+
# rubocop:disable Layout/LineLength
|
4
4
|
|
5
5
|
module RuboCop
|
6
6
|
module Formatter
|
@@ -41,7 +41,7 @@ module RuboCop
|
|
41
41
|
# * `#finished`
|
42
42
|
#
|
43
43
|
class BaseFormatter
|
44
|
-
# rubocop:enable
|
44
|
+
# rubocop:enable Layout/LineLength
|
45
45
|
|
46
46
|
# @api public
|
47
47
|
#
|
@@ -53,11 +53,12 @@ module RuboCop
|
|
53
53
|
|
54
54
|
def hash_for_offense(offense)
|
55
55
|
{
|
56
|
-
severity:
|
57
|
-
message:
|
58
|
-
cop_name:
|
59
|
-
corrected:
|
60
|
-
|
56
|
+
severity: offense.severity.name,
|
57
|
+
message: offense.message,
|
58
|
+
cop_name: offense.cop_name,
|
59
|
+
corrected: offense.corrected?,
|
60
|
+
correctable: offense.correctable?,
|
61
|
+
location: hash_for_location(offense)
|
61
62
|
}
|
62
63
|
end
|
63
64
|
|
data/lib/rubocop/node_pattern.rb
CHANGED
data/lib/rubocop/options.rb
CHANGED
@@ -264,18 +264,18 @@ module RuboCop
|
|
264
264
|
# rubocop:disable Metrics/AbcSize
|
265
265
|
def validate_compatibility # rubocop:disable Metrics/MethodLength
|
266
266
|
if only_includes_redundant_disable?
|
267
|
-
raise OptionArgumentError, 'Lint/RedundantCopDisableDirective
|
268
|
-
'
|
267
|
+
raise OptionArgumentError, 'Lint/RedundantCopDisableDirective cannot ' \
|
268
|
+
'be used with --only.'
|
269
269
|
end
|
270
270
|
if except_syntax?
|
271
|
-
raise OptionArgumentError, 'Syntax checking
|
271
|
+
raise OptionArgumentError, 'Syntax checking cannot be turned off.'
|
272
272
|
end
|
273
273
|
unless boolean_or_empty_cache?
|
274
274
|
raise OptionArgumentError, '-C/--cache argument must be true or false'
|
275
275
|
end
|
276
276
|
|
277
277
|
if display_only_fail_level_offenses_with_autocorrect?
|
278
|
-
raise OptionArgumentError, '--autocorrect
|
278
|
+
raise OptionArgumentError, '--autocorrect cannot be used with ' \
|
279
279
|
'--display-only-fail-level-offenses'
|
280
280
|
end
|
281
281
|
validate_auto_gen_config
|
@@ -329,8 +329,8 @@ module RuboCop
|
|
329
329
|
auto_gen_config: '-P/--parallel uses caching to speed up execution, ' \
|
330
330
|
'while --auto-gen-config needs a non-cached run, ' \
|
331
331
|
'so they cannot be combined.',
|
332
|
-
fail_fast: '-P/--parallel
|
333
|
-
auto_correct: '-P/--parallel
|
332
|
+
fail_fast: '-P/--parallel cannot be combined with -F/--fail-fast.',
|
333
|
+
auto_correct: '-P/--parallel cannot be combined with --auto-correct.'
|
334
334
|
}
|
335
335
|
|
336
336
|
combos.each do |key, msg|
|
@@ -373,7 +373,7 @@ module RuboCop
|
|
373
373
|
# This module contains help texts for command line options.
|
374
374
|
module OptionsHelp
|
375
375
|
MAX_EXCL = RuboCop::Options::DEFAULT_MAXIMUM_EXCLUSION_ITEMS.to_s
|
376
|
-
# rubocop:disable
|
376
|
+
# rubocop:disable Layout/LineLength
|
377
377
|
FORMATTER_OPTION_LIST = RuboCop::Formatter::FormatterSet::BUILTIN_FORMATTERS_FOR_KEYS.keys
|
378
378
|
|
379
379
|
TEXT = {
|
@@ -455,6 +455,6 @@ module RuboCop
|
|
455
455
|
'reports. This is useful for editor integration.'],
|
456
456
|
init: 'Generate a .rubocop.yml file in the current directory.'
|
457
457
|
}.freeze
|
458
|
-
# rubocop:enable
|
458
|
+
# rubocop:enable Layout/LineLength
|
459
459
|
end
|
460
460
|
end
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -186,6 +186,8 @@ module RuboCop
|
|
186
186
|
options.to_s.gsub(/[^a-z]+/i, '_')
|
187
187
|
end
|
188
188
|
|
189
|
+
# The external dependency checksums are cached per RuboCop team so that
|
190
|
+
# the checksums don't need to be recomputed for each file.
|
189
191
|
def team_checksum(team)
|
190
192
|
@checksum_by_team ||= {}
|
191
193
|
@checksum_by_team[team.object_id] ||= team.external_dependency_checksum
|
data/lib/rubocop/runner.rb
CHANGED
@@ -214,7 +214,7 @@ module RuboCop
|
|
214
214
|
@config_store.for(Dir.pwd).for_all_cops['UseCache']) &&
|
215
215
|
# When running --auto-gen-config, there's some processing done in the
|
216
216
|
# cops related to calculating the Max parameters for Metrics cops. We
|
217
|
-
# need to do that processing and
|
217
|
+
# need to do that processing and cannot use caching.
|
218
218
|
!@options[:auto_gen_config] &&
|
219
219
|
# We can't cache results from code which is piped in to stdin
|
220
220
|
!@options[:stdin]
|
@@ -366,6 +366,10 @@ module RuboCop
|
|
366
366
|
end
|
367
367
|
end
|
368
368
|
|
369
|
+
# A Cop::Team instance is stateful and may change when inspecting.
|
370
|
+
# The "standby" team for a given config is an initialized but
|
371
|
+
# otherwise dormant team that can be used for config- and option-
|
372
|
+
# level caching in ResultCache.
|
369
373
|
def standby_team(config)
|
370
374
|
@team_by_config ||= {}
|
371
375
|
@team_by_config[config.object_id] ||=
|
data/lib/rubocop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.78.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-12-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jaro_winkler
|
@@ -302,6 +302,7 @@ files:
|
|
302
302
|
- lib/rubocop/cop/layout/initial_indentation.rb
|
303
303
|
- lib/rubocop/cop/layout/leading_comment_space.rb
|
304
304
|
- lib/rubocop/cop/layout/leading_empty_lines.rb
|
305
|
+
- lib/rubocop/cop/layout/line_length.rb
|
305
306
|
- lib/rubocop/cop/layout/multiline_array_brace_layout.rb
|
306
307
|
- lib/rubocop/cop/layout/multiline_array_line_breaks.rb
|
307
308
|
- lib/rubocop/cop/layout/multiline_assignment_layout.rb
|
@@ -380,6 +381,7 @@ files:
|
|
380
381
|
- lib/rubocop/cop/lint/nested_method_definition.rb
|
381
382
|
- lib/rubocop/cop/lint/nested_percent_literal.rb
|
382
383
|
- lib/rubocop/cop/lint/next_without_accumulator.rb
|
384
|
+
- lib/rubocop/cop/lint/non_deterministic_require_order.rb
|
383
385
|
- lib/rubocop/cop/lint/non_local_exit_from_iterator.rb
|
384
386
|
- lib/rubocop/cop/lint/number_conversion.rb
|
385
387
|
- lib/rubocop/cop/lint/ordered_magic_comments.rb
|
@@ -429,7 +431,6 @@ files:
|
|
429
431
|
- lib/rubocop/cop/metrics/block_nesting.rb
|
430
432
|
- lib/rubocop/cop/metrics/class_length.rb
|
431
433
|
- lib/rubocop/cop/metrics/cyclomatic_complexity.rb
|
432
|
-
- lib/rubocop/cop/metrics/line_length.rb
|
433
434
|
- lib/rubocop/cop/metrics/method_length.rb
|
434
435
|
- lib/rubocop/cop/metrics/module_length.rb
|
435
436
|
- lib/rubocop/cop/metrics/parameter_lists.rb
|
@@ -464,6 +465,7 @@ files:
|
|
464
465
|
- lib/rubocop/cop/mixin/ignored_pattern.rb
|
465
466
|
- lib/rubocop/cop/mixin/integer_node.rb
|
466
467
|
- lib/rubocop/cop/mixin/interpolation.rb
|
468
|
+
- lib/rubocop/cop/mixin/line_length_help.rb
|
467
469
|
- lib/rubocop/cop/mixin/match_range.rb
|
468
470
|
- lib/rubocop/cop/mixin/method_complexity.rb
|
469
471
|
- lib/rubocop/cop/mixin/method_preference.rb
|
@@ -483,6 +485,7 @@ files:
|
|
483
485
|
- lib/rubocop/cop/mixin/preceding_following_alignment.rb
|
484
486
|
- lib/rubocop/cop/mixin/preferred_delimiters.rb
|
485
487
|
- lib/rubocop/cop/mixin/range_help.rb
|
488
|
+
- lib/rubocop/cop/mixin/rational_literal.rb
|
486
489
|
- lib/rubocop/cop/mixin/rescue_node.rb
|
487
490
|
- lib/rubocop/cop/mixin/safe_assignment.rb
|
488
491
|
- lib/rubocop/cop/mixin/space_after_punctuation.rb
|