rubocop 0.63.0 → 0.63.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +1 -0
- data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +4 -3
- data/lib/rubocop/cop/rails/relative_date_constant.rb +40 -36
- data/lib/rubocop/cop/style/copyright.rb +1 -1
- data/lib/rubocop/rspec/cop_helper.rb +2 -0
- data/lib/rubocop/rspec/expect_offense.rb +43 -2
- data/lib/rubocop/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 403ba108281ac77da6c733ad24b88350e4b4a3055ad36b6059d7784cbf4df56e
|
4
|
+
data.tar.gz: 86ebf007930c2de6e2f5eddbd0a6fba6e99ce9a7645f6407fdd4554a4e3c632c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65c260a9df4e731b52ed42e5412d100e71199d5b75e6dac98adaf097020b351019c3fabedd99f2c34465d414eba0439680aeb7799ece4321c63918b4ac2e46e9
|
7
|
+
data.tar.gz: 5bfe411917f9d371b3ce33464297b5aa7840959dccf1275553545601af6b5228a7e770e3993663b98d5880f91f18dfdb94cf55cfa697af923e63c3b9fb3bcd8f
|
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 locking in your `Gemfile`:
|
54
54
|
|
55
55
|
```rb
|
56
|
-
gem 'rubocop', '~> 0.63.
|
56
|
+
gem 'rubocop', '~> 0.63.1', require: false
|
57
57
|
```
|
58
58
|
|
59
59
|
## Quickstart
|
@@ -94,7 +94,7 @@ module RuboCop
|
|
94
94
|
begin_line_num = previous_line_num - base_line_num + 1
|
95
95
|
end_line_num = node.first_line - base_line_num + 1
|
96
96
|
lines = source_in_lines[begin_line_num...end_line_num]
|
97
|
-
"\n
|
97
|
+
"\n#{(lines.join("\n").split(node.source).first || '')}"
|
98
98
|
end
|
99
99
|
|
100
100
|
def fix_escaped_content(word_node, escape, delimiters)
|
@@ -133,6 +133,7 @@ module RuboCop
|
|
133
133
|
# Although there are multiple choices for a correct column,
|
134
134
|
# select the first one of candidates to determine a specification.
|
135
135
|
correct_column = candidates.first
|
136
|
+
@column_delta = correct_column - right_paren.column
|
136
137
|
add_offense(right_paren,
|
137
138
|
location: right_paren,
|
138
139
|
message: message(correct_column,
|
@@ -34,12 +34,13 @@ module RuboCop
|
|
34
34
|
def check(node)
|
35
35
|
return unless node.method_name == :initialize
|
36
36
|
|
37
|
-
check_body(node)
|
37
|
+
check_body(node.body)
|
38
38
|
end
|
39
39
|
|
40
40
|
# @param [DefNode] node a constructor definition
|
41
|
-
def check_body(
|
42
|
-
|
41
|
+
def check_body(body)
|
42
|
+
return if body.nil?
|
43
|
+
|
43
44
|
case body.type
|
44
45
|
when :begin
|
45
46
|
check_body_lines(body.child_nodes)
|
@@ -19,18 +19,15 @@ module RuboCop
|
|
19
19
|
# end
|
20
20
|
# end
|
21
21
|
class RelativeDateConstant < Cop
|
22
|
+
include RangeHelp
|
23
|
+
|
22
24
|
MSG = 'Do not assign %<method_name>s to constants as it ' \
|
23
25
|
'will be evaluated only once.'.freeze
|
24
26
|
|
25
|
-
RELATIVE_DATE_METHODS = %i[ago from_now since until].freeze
|
26
|
-
|
27
27
|
def on_casgn(node)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
return unless rhs
|
32
|
-
|
33
|
-
check_node(rhs)
|
28
|
+
relative_date_assignment?(node) do |method_name|
|
29
|
+
add_offense(node, message: format(MSG, method_name: method_name))
|
30
|
+
end
|
34
31
|
end
|
35
32
|
|
36
33
|
def on_masgn(node)
|
@@ -39,20 +36,29 @@ module RuboCop
|
|
39
36
|
return unless rhs && rhs.array_type?
|
40
37
|
|
41
38
|
lhs.children.zip(rhs.children).each do |(name, value)|
|
42
|
-
|
39
|
+
next unless name.casgn_type?
|
40
|
+
|
41
|
+
relative_date?(value) do |method_name|
|
42
|
+
add_offense(node,
|
43
|
+
location: range_between(name.loc.expression.begin_pos,
|
44
|
+
value.loc.expression.end_pos),
|
45
|
+
message: format(MSG, method_name: method_name))
|
46
|
+
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
50
|
def on_or_asgn(node)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
check_node(rhs)
|
51
|
+
relative_date_or_assignment?(node) do |method_name|
|
52
|
+
add_offense(node, message: format(MSG, method_name: method_name))
|
53
|
+
end
|
52
54
|
end
|
53
55
|
|
54
56
|
def autocorrect(node)
|
55
|
-
|
57
|
+
return unless node.casgn_type?
|
58
|
+
|
59
|
+
scope, const_name, value = *node
|
60
|
+
return unless scope.nil?
|
61
|
+
|
56
62
|
indent = ' ' * node.loc.column
|
57
63
|
new_code = ["def self.#{const_name.downcase}",
|
58
64
|
"#{indent}#{value.source}",
|
@@ -62,27 +68,25 @@ module RuboCop
|
|
62
68
|
|
63
69
|
private
|
64
70
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
!node.arguments?
|
85
|
-
end
|
71
|
+
def_node_matcher :relative_date_assignment?, <<-PATTERN
|
72
|
+
{
|
73
|
+
(casgn _ _ (send _ ${:since :from_now :after :ago :until :before}))
|
74
|
+
(casgn _ _ ({erange irange} _ (send _ ${:since :from_now :after :ago :until :before})))
|
75
|
+
(casgn _ _ ({erange irange} (send _ ${:since :from_now :after :ago :until :before}) _))
|
76
|
+
}
|
77
|
+
PATTERN
|
78
|
+
|
79
|
+
def_node_matcher :relative_date_or_assignment?, <<-PATTERN
|
80
|
+
(:or_asgn (casgn _ _) (send _ ${:since :from_now :after :ago :until :before}))
|
81
|
+
PATTERN
|
82
|
+
|
83
|
+
def_node_matcher :relative_date?, <<-PATTERN
|
84
|
+
{
|
85
|
+
({erange irange} _ (send _ ${:since :from_now :after :ago :until :before}))
|
86
|
+
({erange irange} (send _ ${:since :from_now :after :ago :until :before}) _)
|
87
|
+
(send _ ${:since :from_now :after :ago :until :before})
|
88
|
+
}
|
89
|
+
PATTERN
|
86
90
|
end
|
87
91
|
end
|
88
92
|
end
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
|
21
21
|
MSG = 'Include a copyright notice matching /%<notice>s/ before ' \
|
22
22
|
'any code.'.freeze
|
23
|
-
AUTOCORRECT_EMPTY_WARNING = 'An AutocorrectNotice must be defined in' \
|
23
|
+
AUTOCORRECT_EMPTY_WARNING = 'An AutocorrectNotice must be defined in ' \
|
24
24
|
'your RuboCop config'.freeze
|
25
25
|
|
26
26
|
def investigate(processed_source)
|
@@ -38,6 +38,8 @@ module CopHelper
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def autocorrect_source(source, file = nil)
|
41
|
+
RuboCop::Formatter::DisabledConfigFormatter.config_to_allow_offenses = {}
|
42
|
+
RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
|
41
43
|
cop.instance_variable_get(:@options)[:auto_correct] = true
|
42
44
|
processed_source = parse_source(source, file)
|
43
45
|
_investigate(cop, processed_source)
|
@@ -38,24 +38,65 @@ module RuboCop
|
|
38
38
|
# 'Avoid chaining a method call on a do...end block.'
|
39
39
|
# )
|
40
40
|
#
|
41
|
+
# Auto-correction can be tested using `expect_correction` after
|
42
|
+
# `expect_offense`.
|
43
|
+
#
|
44
|
+
# @example `expect_offense` and `expect_correction`
|
45
|
+
#
|
46
|
+
# expect_offense(<<-RUBY.strip_indent)
|
47
|
+
# x % 2 == 0
|
48
|
+
# ^^^^^^^^^^ Replace with `Integer#even?`.
|
49
|
+
# RUBY
|
50
|
+
#
|
51
|
+
# expect_correction(<<-RUBY.strip_indent)
|
52
|
+
# x.even?
|
53
|
+
# RUBY
|
54
|
+
#
|
41
55
|
# If you do not want to specify an offense then use the
|
42
56
|
# companion method `expect_no_offenses`. This method is a much
|
43
57
|
# simpler assertion since it just inspects the source and checks
|
44
58
|
# that there were no offenses. The `expect_offense` method has
|
45
59
|
# to do more work by parsing out lines that contain carets.
|
46
60
|
module ExpectOffense
|
61
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
47
62
|
def expect_offense(source, file = nil)
|
63
|
+
RuboCop::Formatter::DisabledConfigFormatter
|
64
|
+
.config_to_allow_offenses = {}
|
65
|
+
RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
|
66
|
+
cop.instance_variable_get(:@options)[:auto_correct] = true
|
67
|
+
|
48
68
|
expected_annotations = AnnotatedSource.parse(source)
|
49
69
|
|
50
70
|
if expected_annotations.plain_source == source
|
51
|
-
raise 'Use expect_no_offenses to assert that no offenses are found'
|
71
|
+
raise 'Use `expect_no_offenses` to assert that no offenses are found'
|
72
|
+
end
|
73
|
+
|
74
|
+
@processed_source = parse_source(expected_annotations.plain_source,
|
75
|
+
file)
|
76
|
+
|
77
|
+
unless @processed_source.valid_syntax?
|
78
|
+
raise 'Error parsing example code'
|
52
79
|
end
|
53
80
|
|
54
|
-
|
81
|
+
_investigate(cop, @processed_source)
|
55
82
|
actual_annotations =
|
56
83
|
expected_annotations.with_offense_annotations(cop.offenses)
|
84
|
+
|
57
85
|
expect(actual_annotations.to_s).to eq(expected_annotations.to_s)
|
58
86
|
end
|
87
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
88
|
+
|
89
|
+
def expect_correction(correction)
|
90
|
+
unless @processed_source
|
91
|
+
raise '`expect_correction` must follow `expect_offense`'
|
92
|
+
end
|
93
|
+
|
94
|
+
corrector =
|
95
|
+
RuboCop::Cop::Corrector.new(@processed_source.buffer, cop.corrections)
|
96
|
+
new_source = corrector.rewrite
|
97
|
+
|
98
|
+
expect(new_source).to eq(correction)
|
99
|
+
end
|
59
100
|
|
60
101
|
def expect_no_offenses(source, file = nil)
|
61
102
|
inspect_source(source, file)
|
data/lib/rubocop/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
# This module holds the RuboCop version information.
|
5
5
|
module Version
|
6
|
-
STRING = '0.63.
|
6
|
+
STRING = '0.63.1'.freeze
|
7
7
|
|
8
8
|
MSG = '%<version>s (using Parser %<parser_version>s, running on ' \
|
9
9
|
'%<ruby_engine>s %<ruby_version>s %<ruby_platform>s)'.freeze
|
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.63.
|
4
|
+
version: 0.63.1
|
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-01-
|
13
|
+
date: 2019-01-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: jaro_winkler
|
@@ -830,8 +830,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
830
830
|
- !ruby/object:Gem::Version
|
831
831
|
version: '0'
|
832
832
|
requirements: []
|
833
|
-
|
834
|
-
rubygems_version: 2.6.11
|
833
|
+
rubygems_version: 3.0.1
|
835
834
|
signing_key:
|
836
835
|
specification_version: 4
|
837
836
|
summary: Automatic Ruby code style checking tool.
|