rubocop-rails 2.3.1 → 2.3.2
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/lib/rubocop/cop/rails/presence.rb +3 -1
- data/lib/rubocop/cop/rails/validation.rb +46 -8
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26d2ede1a06dce0e42d2bcbfe3963745a159fc1ecdcc21ac55c3b9bf93e6acd4
|
4
|
+
data.tar.gz: 2c39a124756afd14f69febf84ab357f45fc720e68af45a16ba8e2668151a0664
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b3d56057f612bf09a155255925aa8c85909866f4320629ce4bbf0657a81cfb4e39683e2daae6b87a37966a85882e549891271a73908ccf8ee66a0e40db09b14
|
7
|
+
data.tar.gz: 6bf0f0d6ae2d223368c44b80bb9a7c888603f06186e58d4fcacb085ac240d8877ce1717d9e694f8846c5ab06e3ffaeeea74b388f98f5ff3188184abceb3a029a
|
@@ -119,8 +119,10 @@ module RuboCop
|
|
119
119
|
def replacement(receiver, other)
|
120
120
|
or_source = if other&.send_type?
|
121
121
|
build_source_for_or_method(other)
|
122
|
-
|
122
|
+
elsif other.nil? || other.nil_type?
|
123
123
|
''
|
124
|
+
else
|
125
|
+
" || #{other.source}"
|
124
126
|
end
|
125
127
|
|
126
128
|
"#{receiver.source}.presence" + or_source
|
@@ -61,7 +61,8 @@ module RuboCop
|
|
61
61
|
|
62
62
|
def autocorrect(node)
|
63
63
|
last_argument = node.arguments.last
|
64
|
-
return if !last_argument.literal? && !last_argument.splat_type?
|
64
|
+
return if !last_argument.literal? && !last_argument.splat_type? &&
|
65
|
+
!frozen_array_argument?(last_argument)
|
65
66
|
|
66
67
|
lambda do |corrector|
|
67
68
|
corrector.replace(node.loc.selector, 'validates')
|
@@ -81,19 +82,56 @@ module RuboCop
|
|
81
82
|
end
|
82
83
|
|
83
84
|
def correct_validate_type(corrector, node)
|
84
|
-
last_argument = node.
|
85
|
-
validate_type = node.method_name.to_s.split('_')[1]
|
85
|
+
last_argument = node.last_argument
|
86
86
|
|
87
87
|
if last_argument.hash_type?
|
88
|
-
corrector
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
correct_validate_type_for_hash(corrector, node, last_argument)
|
89
|
+
elsif last_argument.array_type?
|
90
|
+
loc = last_argument.loc
|
91
|
+
|
92
|
+
correct_validate_type_for_array(corrector, node, last_argument, loc)
|
93
|
+
elsif frozen_array_argument?(last_argument)
|
94
|
+
arguments = node.last_argument.receiver
|
95
|
+
loc = arguments.parent.loc
|
96
|
+
|
97
|
+
correct_validate_type_for_array(corrector, node, arguments, loc)
|
92
98
|
else
|
93
99
|
range = last_argument.source_range
|
94
100
|
|
95
|
-
corrector.insert_after(range, ", #{validate_type}: true")
|
101
|
+
corrector.insert_after(range, ", #{validate_type(node)}: true")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def correct_validate_type_for_hash(corrector, node, arguments)
|
106
|
+
corrector.replace(
|
107
|
+
arguments.loc.expression,
|
108
|
+
"#{validate_type(node)}: #{braced_options(arguments)}"
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
def correct_validate_type_for_array(corrector, node, arguments, loc)
|
113
|
+
attributes = []
|
114
|
+
|
115
|
+
arguments.each_child_node do |child_node|
|
116
|
+
attributes << if arguments.percent_literal?
|
117
|
+
":#{child_node.source}"
|
118
|
+
else
|
119
|
+
child_node.source
|
120
|
+
end
|
96
121
|
end
|
122
|
+
|
123
|
+
corrector.replace(
|
124
|
+
loc.expression,
|
125
|
+
"#{attributes.join(', ')}, #{validate_type(node)}: true"
|
126
|
+
)
|
127
|
+
end
|
128
|
+
|
129
|
+
def validate_type(node)
|
130
|
+
node.method_name.to_s.split('_')[1]
|
131
|
+
end
|
132
|
+
|
133
|
+
def frozen_array_argument?(argument)
|
134
|
+
argument.send_type? && argument.method?(:freeze)
|
97
135
|
end
|
98
136
|
|
99
137
|
def braced_options(options)
|
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.3.
|
4
|
+
version: 2.3.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: 2019-
|
13
|
+
date: 2019-09-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rack
|