rubocop-rails 2.3.1 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 147c7b2462cbfbefa559fc9e6d23b3bad655397784ab1296d2865aede5d41aff
4
- data.tar.gz: 1fe87be1d5319fa8687f82e4ece29feedcad65ef1568be8d3f849666f4ba0a5b
3
+ metadata.gz: 26d2ede1a06dce0e42d2bcbfe3963745a159fc1ecdcc21ac55c3b9bf93e6acd4
4
+ data.tar.gz: 2c39a124756afd14f69febf84ab357f45fc720e68af45a16ba8e2668151a0664
5
5
  SHA512:
6
- metadata.gz: 191ef083e5a22f0b8deb9b4918b70cd10556f9db0ff98fdfddc944a40b176050dacdb3a5fbb819abe7a9aaee38c7f4cc06329bd59b82738a98de6c9ffebca7a2
7
- data.tar.gz: 4b7b0d972bde8df9df3f8b7b956077d4b895ffcc7f5e0aab1c3885b1f6027244b4b918b0d1f619afb079388a7d2756a70a45fee85ffeca1bae25062370299d41
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
- else
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.arguments.last
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.replace(
89
- last_argument.loc.expression,
90
- "#{validate_type}: #{braced_options(last_argument)}"
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)
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Rails
5
5
  # This module holds the RuboCop Rails version information.
6
6
  module Version
7
- STRING = '2.3.1'
7
+ STRING = '2.3.2'
8
8
  end
9
9
  end
10
10
  end
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.1
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-08-26 00:00:00.000000000 Z
13
+ date: 2019-09-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack