rubocop-rails 2.17.0 → 2.17.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 +3 -3
- data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +10 -8
- data/lib/rubocop/cop/rails/http_status.rb +1 -6
- data/lib/rubocop/cop/rails/pluck.rb +29 -10
- data/lib/rubocop/cop/rails/where_not_with_multiple_conditions.rb +1 -1
- 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: 97069bbada22491ece697f32f933ce8dc5274c18ad2782bb832cd83b168874a3
|
4
|
+
data.tar.gz: 4a691068f93c7be89e9cf695c3be16fe183cb23be4b187e822a9bf9d896c9af7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 213e3da3d5e23338c53ee9428d8d44a57123fa8a239c3974e5eb0181797555639da23ed7e09336e906e14ba3c99c46e33efba18db44646f0efe86913dc0b7847
|
7
|
+
data.tar.gz: ed27cd2b9106a650b01fc700e9c2511971853412f49aa93876589dfa67e77c7a246fa364dd4682747fc97ffe8121d286a4096e6ef0b257483668c36f99fec9e1
|
data/config/default.yml
CHANGED
@@ -73,7 +73,7 @@ Rails/ActionControllerFlashBeforeRender:
|
|
73
73
|
StyleGuide: 'https://rails.rubystyle.guide/#flash-before-render'
|
74
74
|
Reference: 'https://api.rubyonrails.org/classes/ActionController/FlashBeforeRender.html'
|
75
75
|
Enabled: 'pending'
|
76
|
-
|
76
|
+
SafeAutoCorrect: false
|
77
77
|
VersionAdded: '2.16'
|
78
78
|
|
79
79
|
Rails/ActionControllerTestCase:
|
@@ -81,7 +81,7 @@ Rails/ActionControllerTestCase:
|
|
81
81
|
StyleGuide: 'https://rails.rubystyle.guide/#integration-testing'
|
82
82
|
Reference: 'https://api.rubyonrails.org/classes/ActionController/TestCase.html'
|
83
83
|
Enabled: 'pending'
|
84
|
-
|
84
|
+
SafeAutoCorrect: false
|
85
85
|
VersionAdded: '2.14'
|
86
86
|
Include:
|
87
87
|
- '**/test/**/*.rb'
|
@@ -873,7 +873,7 @@ Rails/RootJoinChain:
|
|
873
873
|
Rails/RootPathnameMethods:
|
874
874
|
Description: 'Use `Rails.root` IO methods instead of passing it to `File`.'
|
875
875
|
Enabled: pending
|
876
|
-
|
876
|
+
SafeAutoCorrect: false
|
877
877
|
VersionAdded: '2.16'
|
878
878
|
|
879
879
|
Rails/RootPublicPath:
|
@@ -37,8 +37,8 @@ module RuboCop
|
|
37
37
|
^(send (send nil? :flash) :[]= ...)
|
38
38
|
PATTERN
|
39
39
|
|
40
|
-
def_node_search :
|
41
|
-
(send nil? :
|
40
|
+
def_node_search :render?, <<~PATTERN
|
41
|
+
(send nil? :render ...)
|
42
42
|
PATTERN
|
43
43
|
|
44
44
|
def_node_search :action_controller?, <<~PATTERN
|
@@ -53,7 +53,7 @@ module RuboCop
|
|
53
53
|
def on_send(flash_node)
|
54
54
|
return unless flash_assignment?(flash_node)
|
55
55
|
|
56
|
-
return
|
56
|
+
return unless followed_by_render?(flash_node)
|
57
57
|
|
58
58
|
return unless instance_method_or_block?(flash_node)
|
59
59
|
|
@@ -66,13 +66,15 @@ module RuboCop
|
|
66
66
|
|
67
67
|
private
|
68
68
|
|
69
|
-
def
|
69
|
+
def followed_by_render?(flash_node)
|
70
70
|
flash_assigment_node = find_ancestor(flash_node, type: :send)
|
71
|
-
context = flash_assigment_node
|
71
|
+
context = flash_assigment_node
|
72
|
+
context = context.parent if context.parent.if_type?
|
73
|
+
context = context.right_siblings
|
74
|
+
return true if context.empty?
|
72
75
|
|
73
|
-
|
74
|
-
|
75
|
-
index > flash_index && redirect_to?(node)
|
76
|
+
context.compact.any? do |node|
|
77
|
+
render?(node)
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
@@ -12,7 +12,6 @@ module RuboCop
|
|
12
12
|
# render plain: 'foo/bar', status: 304
|
13
13
|
# redirect_to root_url, status: 301
|
14
14
|
# head 200
|
15
|
-
# get '/foobar', to: redirect('/foobar/baz', status: 301)
|
16
15
|
#
|
17
16
|
# # good
|
18
17
|
# render :foo, status: :ok
|
@@ -20,7 +19,6 @@ module RuboCop
|
|
20
19
|
# render plain: 'foo/bar', status: :not_modified
|
21
20
|
# redirect_to root_url, status: :moved_permanently
|
22
21
|
# head :ok
|
23
|
-
# get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently)
|
24
22
|
#
|
25
23
|
# @example EnforcedStyle: numeric
|
26
24
|
# # bad
|
@@ -29,7 +27,6 @@ module RuboCop
|
|
29
27
|
# render plain: 'foo/bar', status: :not_modified
|
30
28
|
# redirect_to root_url, status: :moved_permanently
|
31
29
|
# head :ok
|
32
|
-
# get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently)
|
33
30
|
#
|
34
31
|
# # good
|
35
32
|
# render :foo, status: 200
|
@@ -37,20 +34,18 @@ module RuboCop
|
|
37
34
|
# render plain: 'foo/bar', status: 304
|
38
35
|
# redirect_to root_url, status: 301
|
39
36
|
# head 200
|
40
|
-
# get '/foobar', to: redirect('/foobar/baz', status: 301)
|
41
37
|
#
|
42
38
|
class HttpStatus < Base
|
43
39
|
include ConfigurableEnforcedStyle
|
44
40
|
extend AutoCorrector
|
45
41
|
|
46
|
-
RESTRICT_ON_SEND = %i[render redirect_to head
|
42
|
+
RESTRICT_ON_SEND = %i[render redirect_to head].freeze
|
47
43
|
|
48
44
|
def_node_matcher :http_status, <<~PATTERN
|
49
45
|
{
|
50
46
|
(send nil? {:render :redirect_to} _ $hash)
|
51
47
|
(send nil? {:render :redirect_to} $hash)
|
52
48
|
(send nil? :head ${int sym} ...)
|
53
|
-
(send nil? :redirect _ $hash)
|
54
49
|
}
|
55
50
|
PATTERN
|
56
51
|
|
@@ -26,34 +26,53 @@ module RuboCop
|
|
26
26
|
minimum_target_rails_version 5.0
|
27
27
|
|
28
28
|
def_node_matcher :pluck_candidate?, <<~PATTERN
|
29
|
-
({block numblock} (send _ {:map :collect}) $_argument (send
|
29
|
+
({block numblock} (send _ {:map :collect}) $_argument (send lvar :[] $_key))
|
30
30
|
PATTERN
|
31
31
|
|
32
32
|
def on_block(node)
|
33
|
-
pluck_candidate?(node) do |argument,
|
33
|
+
pluck_candidate?(node) do |argument, key|
|
34
|
+
next unless use_one_block_argument?(argument)
|
35
|
+
|
34
36
|
match = if node.block_type?
|
35
|
-
argument.children.first.source
|
37
|
+
block_argument = argument.children.first.source
|
38
|
+
use_block_argument_in_key?(block_argument, key)
|
36
39
|
else # numblock
|
37
|
-
argument == 1 &&
|
40
|
+
argument == 1 && use_block_argument_in_key?('_1', key)
|
38
41
|
end
|
39
42
|
next unless match
|
40
43
|
|
41
|
-
|
42
|
-
message = message(replacement, node)
|
43
|
-
|
44
|
-
add_offense(offense_range(node), message: message) do |corrector|
|
45
|
-
corrector.replace(offense_range(node), replacement)
|
46
|
-
end
|
44
|
+
register_offense(node, key)
|
47
45
|
end
|
48
46
|
end
|
49
47
|
alias on_numblock on_block
|
50
48
|
|
51
49
|
private
|
52
50
|
|
51
|
+
def use_one_block_argument?(argument)
|
52
|
+
return true if argument == 1 # Checks for numbered argument `_1`.
|
53
|
+
|
54
|
+
argument.respond_to?(:one?) && argument.one?
|
55
|
+
end
|
56
|
+
|
57
|
+
def use_block_argument_in_key?(block_argument, key)
|
58
|
+
return false if block_argument == key.source
|
59
|
+
|
60
|
+
key.each_descendant(:lvar).none? { |lvar| block_argument == lvar.source }
|
61
|
+
end
|
62
|
+
|
53
63
|
def offense_range(node)
|
54
64
|
node.send_node.loc.selector.join(node.loc.end)
|
55
65
|
end
|
56
66
|
|
67
|
+
def register_offense(node, key)
|
68
|
+
replacement = "pluck(#{key.source})"
|
69
|
+
message = message(replacement, node)
|
70
|
+
|
71
|
+
add_offense(offense_range(node), message: message) do |corrector|
|
72
|
+
corrector.replace(offense_range(node), replacement)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
57
76
|
def message(replacement, node)
|
58
77
|
current = offense_range(node).source
|
59
78
|
|
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.17.
|
4
|
+
version: 2.17.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-10-
|
13
|
+
date: 2022-10-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|