rubocop-rails 2.15.1 → 2.15.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +1 -0
- data/lib/rubocop/cop/rails/delegate.rb +4 -9
- data/lib/rubocop/cop/rails/deprecated_active_model_errors_methods.rb +2 -0
- data/lib/rubocop/cop/rails/expanded_date_range.rb +38 -22
- data/lib/rubocop/cop/rails/strip_heredoc.rb +1 -1
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 169ed04b1f5378e9e08fbffdca151afaf4b84fd54b1867a173740aadaede60b3
|
4
|
+
data.tar.gz: 1a2ac75c313cfcdeec1814d7e3aff4777c5013527d2cf4a2aa4f95aeb45446bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51d495edd3e825db49ece8f51bfc118c73887681f414b86d31cd47d85dc5a1a22a385a2a17ed4ebf7d1c6332989795e2cde999a364d911c60f452993dc926c4b
|
7
|
+
data.tar.gz: 4546785b39af93e6c7fe5a6a3b637fa5c21d4b358c38ea8ad3ebd5c272d1d0a504e8206e8201cfe3771af9199c336649d033e32b324f16b06fc7d150054dc488
|
data/config/default.yml
CHANGED
@@ -54,6 +54,7 @@ module RuboCop
|
|
54
54
|
# delegate :bar, to: :foo, prefix: true
|
55
55
|
class Delegate < Base
|
56
56
|
extend AutoCorrector
|
57
|
+
include VisibilityHelp
|
57
58
|
|
58
59
|
MSG = 'Use `delegate` to define delegations.'
|
59
60
|
|
@@ -112,17 +113,11 @@ module RuboCop
|
|
112
113
|
end
|
113
114
|
|
114
115
|
def private_or_protected_delegation(node)
|
115
|
-
|
116
|
-
private_or_protected_before(line) ||
|
117
|
-
private_or_protected_inline(line)
|
116
|
+
private_or_protected_inline(node) || node_visibility(node) != :public
|
118
117
|
end
|
119
118
|
|
120
|
-
def
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
def private_or_protected_inline(line)
|
125
|
-
processed_source[line - 1].strip.match?(/\A(private )|(protected )/)
|
119
|
+
def private_or_protected_inline(node)
|
120
|
+
processed_source[node.first_line - 1].strip.match?(/\A(private )|(protected )/)
|
126
121
|
end
|
127
122
|
end
|
128
123
|
end
|
@@ -29,14 +29,6 @@ module RuboCop
|
|
29
29
|
|
30
30
|
minimum_target_rails_version 5.1
|
31
31
|
|
32
|
-
def_node_matcher :expanded_date_range, <<~PATTERN
|
33
|
-
(irange
|
34
|
-
(send
|
35
|
-
$_ {:beginning_of_day :beginning_of_week :beginning_of_month :beginning_of_quarter :beginning_of_year})
|
36
|
-
(send
|
37
|
-
$_ {:end_of_day :end_of_week :end_of_month :end_of_quarter :end_of_year}))
|
38
|
-
PATTERN
|
39
|
-
|
40
32
|
PREFERRED_METHODS = {
|
41
33
|
beginning_of_day: 'all_day',
|
42
34
|
beginning_of_week: 'all_week',
|
@@ -54,31 +46,55 @@ module RuboCop
|
|
54
46
|
}.freeze
|
55
47
|
|
56
48
|
def on_irange(node)
|
57
|
-
return unless expanded_date_range(node)
|
58
|
-
|
59
49
|
begin_node = node.begin
|
60
50
|
end_node = node.end
|
61
|
-
return
|
62
|
-
|
63
|
-
beginning_method = begin_node.method_name
|
64
|
-
end_method = end_node.method_name
|
65
|
-
return unless use_mapped_methods?(beginning_method, end_method)
|
51
|
+
return if allow?(begin_node, end_node)
|
66
52
|
|
67
|
-
preferred_method =
|
53
|
+
preferred_method = preferred_method(begin_node)
|
54
|
+
if begin_node.method?(:beginning_of_week) && begin_node.arguments.one?
|
55
|
+
return unless same_argument?(begin_node, end_node)
|
68
56
|
|
69
|
-
|
70
|
-
|
57
|
+
preferred_method << "(#{begin_node.first_argument.source})"
|
58
|
+
elsif any_arguments?(begin_node, end_node)
|
59
|
+
return
|
71
60
|
end
|
61
|
+
|
62
|
+
register_offense(node, preferred_method)
|
72
63
|
end
|
73
64
|
|
74
65
|
private
|
75
66
|
|
76
|
-
def
|
77
|
-
|
67
|
+
def allow?(begin_node, end_node)
|
68
|
+
return true unless (begin_source = receiver_source(begin_node))
|
69
|
+
return true unless (end_source = receiver_source(end_node))
|
70
|
+
|
71
|
+
begin_source != end_source || MAPPED_DATE_RANGE_METHODS[begin_node.method_name] != end_node.method_name
|
72
|
+
end
|
73
|
+
|
74
|
+
def receiver_source(node)
|
75
|
+
return if !node&.send_type? || node.receiver.nil?
|
76
|
+
|
77
|
+
node.receiver.source
|
78
78
|
end
|
79
79
|
|
80
|
-
def
|
81
|
-
|
80
|
+
def same_argument?(begin_node, end_node)
|
81
|
+
begin_node.first_argument.source == end_node.first_argument.source
|
82
|
+
end
|
83
|
+
|
84
|
+
def preferred_method(begin_node)
|
85
|
+
+"#{begin_node.receiver.source}.#{PREFERRED_METHODS[begin_node.method_name]}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def any_arguments?(begin_node, end_node)
|
89
|
+
begin_node.arguments.any? || end_node.arguments.any?
|
90
|
+
end
|
91
|
+
|
92
|
+
def register_offense(node, preferred_method)
|
93
|
+
message = format(MSG, preferred_method: preferred_method)
|
94
|
+
|
95
|
+
add_offense(node, message: message) do |corrector|
|
96
|
+
corrector.replace(node, preferred_method)
|
97
|
+
end
|
82
98
|
end
|
83
99
|
end
|
84
100
|
end
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
|
44
44
|
def register_offense(node, heredoc)
|
45
45
|
add_offense(node) do |corrector|
|
46
|
-
squiggly_heredoc = heredoc.source.sub(/\A
|
46
|
+
squiggly_heredoc = heredoc.source.sub(/\A<<(-|~)?/, '<<~')
|
47
47
|
|
48
48
|
corrector.replace(heredoc, squiggly_heredoc)
|
49
49
|
corrector.remove(node.loc.dot)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.15.
|
4
|
+
version: 2.15.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-07-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
227
|
- !ruby/object:Gem::Version
|
228
228
|
version: '0'
|
229
229
|
requirements: []
|
230
|
-
rubygems_version: 3.
|
230
|
+
rubygems_version: 3.1.6
|
231
231
|
signing_key:
|
232
232
|
specification_version: 4
|
233
233
|
summary: Automatic Rails code style checking tool.
|