rubocop-rails 2.3.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f18a288648626076787a00773149df97edce3b5330a5dc650cf662af46214bd5
4
- data.tar.gz: f945d031d0a5bc98eb0af95a6cdf8e931cb5a469a1c1ced6ab11c1fb20f09bb5
3
+ metadata.gz: 26d2ede1a06dce0e42d2bcbfe3963745a159fc1ecdcc21ac55c3b9bf93e6acd4
4
+ data.tar.gz: 2c39a124756afd14f69febf84ab357f45fc720e68af45a16ba8e2668151a0664
5
5
  SHA512:
6
- metadata.gz: 24f03fcf8cd683c5ed3e2afc9243f113afaa8641fc5cbd938d5d2ff916b7eeed95a994b69b48509b20618341c5b5c39286bde009f1dc5b369f94dc249a65b148
7
- data.tar.gz: 57d3fff4181c71750d0eccdde094607ad63f79b7a6b273f698224dcc687a707879df82a264df063b4ac8f133fff3f4fe23dfcb820b4d2863cbae6792c6e38906
6
+ metadata.gz: 4b3d56057f612bf09a155255925aa8c85909866f4320629ce4bbf0657a81cfb4e39683e2daae6b87a37966a85882e549891271a73908ccf8ee66a0e40db09b14
7
+ data.tar.gz: 6bf0f0d6ae2d223368c44b80bb9a7c888603f06186e58d4fcacb085ac240d8877ce1717d9e694f8846c5ab06e3ffaeeea74b388f98f5ff3188184abceb3a029a
data/config/default.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  # Common configuration.
2
2
 
3
3
  AllCops:
4
+ Exclude:
5
+ - bin/bundle
4
6
  # What version of Rails is the inspected code using? If a value is specified
5
7
  # for TargetRailsVersion then it is used. Acceptable values are specificed
6
8
  # as a float (i.e. 5.1); the patch version of Rails should not be included.
@@ -9,9 +11,6 @@ AllCops:
9
11
  # application. If neither of those files exist, RuboCop will use Rails 5.0
10
12
  # as the default.
11
13
  TargetRailsVersion: ~
12
- # When specifying style guide URLs, any paths and/or fragments will be
13
- # evaluated relative to the base URL.
14
- StyleGuideBaseURL: https://rails.rubystyle.guide
15
14
 
16
15
  Rails/ActionFilter:
17
16
  Description: 'Enforces consistent use of action filter methods.'
@@ -140,7 +139,7 @@ Rails/DelegateAllowBlank:
140
139
 
141
140
  Rails/DynamicFindBy:
142
141
  Description: 'Use `find_by` instead of dynamic `find_by_*`.'
143
- StyleGuide: '#find_by'
142
+ StyleGuide: 'https://rails.rubystyle.guide#find_by'
144
143
  Enabled: true
145
144
  VersionAdded: '0.44'
146
145
  Whitelist:
@@ -148,7 +147,7 @@ Rails/DynamicFindBy:
148
147
 
149
148
  Rails/EnumHash:
150
149
  Description: 'Prefer hash syntax over array syntax when defining enums.'
151
- StyleGuide: '#enums'
150
+ StyleGuide: 'https://rails.rubystyle.guide#enums'
152
151
  Enabled: true
153
152
  VersionAdded: '2.3'
154
153
  Include:
@@ -192,7 +191,7 @@ Rails/FilePath:
192
191
 
193
192
  Rails/FindBy:
194
193
  Description: 'Prefer find_by over where.first.'
195
- StyleGuide: '#find_by'
194
+ StyleGuide: 'https://rails.rubystyle.guide#find_by'
196
195
  Enabled: true
197
196
  VersionAdded: '0.30'
198
197
  Include:
@@ -200,7 +199,7 @@ Rails/FindBy:
200
199
 
201
200
  Rails/FindEach:
202
201
  Description: 'Prefer all.find_each over all.find.'
203
- StyleGuide: '#find-each'
202
+ StyleGuide: 'https://rails.rubystyle.guide#find-each'
204
203
  Enabled: true
205
204
  VersionAdded: '0.30'
206
205
  Include:
@@ -208,7 +207,7 @@ Rails/FindEach:
208
207
 
209
208
  Rails/HasAndBelongsToMany:
210
209
  Description: 'Prefer has_many :through to has_and_belongs_to_many.'
211
- StyleGuide: '#has-many-through'
210
+ StyleGuide: 'https://rails.rubystyle.guide#has-many-through'
212
211
  Enabled: true
213
212
  VersionAdded: '0.12'
214
213
  Include:
@@ -216,7 +215,7 @@ Rails/HasAndBelongsToMany:
216
215
 
217
216
  Rails/HasManyOrHasOneDependent:
218
217
  Description: 'Define the dependent option to the has_many and has_one associations.'
219
- StyleGuide: '#has_many-has_one-dependent-option'
218
+ StyleGuide: 'https://rails.rubystyle.guide#has_many-has_one-dependent-option'
220
219
  Enabled: true
221
220
  VersionAdded: '0.50'
222
221
  Include:
@@ -263,7 +262,7 @@ Rails/InverseOf:
263
262
 
264
263
  Rails/LexicallyScopedActionFilter:
265
264
  Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the controller."
266
- StyleGuide: '#lexically-scoped-action-filter'
265
+ StyleGuide: 'https://rails.rubystyle.guide#lexically-scoped-action-filter'
267
266
  Enabled: true
268
267
  Safe: false
269
268
  VersionAdded: '0.52'
@@ -328,7 +327,7 @@ Rails/ReadWriteAttribute:
328
327
  Description: >-
329
328
  Checks for read_attribute(:attr) and
330
329
  write_attribute(:attr, val).
331
- StyleGuide: '#read-attribute'
330
+ StyleGuide: 'https://rails.rubystyle.guide#read-attribute'
332
331
  Enabled: true
333
332
  VersionAdded: '0.20'
334
333
  VersionChanged: '0.29'
@@ -379,7 +378,7 @@ Rails/RequestReferer:
379
378
 
380
379
  Rails/ReversibleMigration:
381
380
  Description: 'Checks whether the change method of the migration file is reversible.'
382
- StyleGuide: '#reversible-migration'
381
+ StyleGuide: 'https://rails.rubystyle.guide#reversible-migration'
383
382
  Reference: 'https://api.rubyonrails.org/classes/ActiveRecord/Migration/CommandRecorder.html'
384
383
  Enabled: true
385
384
  VersionAdded: '0.47'
@@ -398,7 +397,7 @@ Rails/SafeNavigation:
398
397
 
399
398
  Rails/SaveBang:
400
399
  Description: 'Identifies possible cases where Active Record save! or related should be used.'
401
- StyleGuide: '#save-bang'
400
+ StyleGuide: 'https://rails.rubystyle.guide#save-bang'
402
401
  Enabled: false
403
402
  VersionAdded: '0.42'
404
403
  VersionChanged: '0.59'
@@ -437,7 +436,7 @@ Rails/SkipsModelValidations:
437
436
 
438
437
  Rails/TimeZone:
439
438
  Description: 'Checks the correct usage of time zone aware methods.'
440
- StyleGuide: '#time'
439
+ StyleGuide: 'https://rails.rubystyle.guide#time'
441
440
  Reference: 'http://danilenko.org/2012/7/6/rails_timezones'
442
441
  Enabled: true
443
442
  Safe: false
@@ -38,6 +38,8 @@ module RuboCop
38
38
  # # good
39
39
  # a.presence || b
40
40
  class Presence < Cop
41
+ include RangeHelp
42
+
41
43
  MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
42
44
 
43
45
  def_node_matcher :redundant_receiver_and_other, <<-PATTERN
@@ -115,9 +117,31 @@ module RuboCop
115
117
  end
116
118
 
117
119
  def replacement(receiver, other)
118
- or_source = other.nil? || other.nil_type? ? '' : " || #{other.source}"
120
+ or_source = if other&.send_type?
121
+ build_source_for_or_method(other)
122
+ elsif other.nil? || other.nil_type?
123
+ ''
124
+ else
125
+ " || #{other.source}"
126
+ end
127
+
119
128
  "#{receiver.source}.presence" + or_source
120
129
  end
130
+
131
+ def build_source_for_or_method(other)
132
+ if other.parenthesized? || !other.arguments?
133
+ " || #{other.source}"
134
+ else
135
+ method = range_between(
136
+ other.source_range.begin_pos,
137
+ other.first_argument.source_range.begin_pos - 1
138
+ ).source
139
+
140
+ arguments = other.arguments.map(&:source).join(', ')
141
+
142
+ " || #{method}(#{arguments})"
143
+ end
144
+ end
121
145
  end
122
146
  end
123
147
  end
@@ -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.0'
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.0
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-13 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
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubygems_version: 3.0.4
140
+ rubygems_version: 3.0.6
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: Automatic Rails code style checking tool.