rubocop-rails 2.17.1 → 2.17.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:
|
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
|
|
@@ -31,6 +31,8 @@ module RuboCop
|
|
31
31
|
|
32
32
|
def on_block(node)
|
33
33
|
pluck_candidate?(node) do |argument, key|
|
34
|
+
next unless use_one_block_argument?(argument)
|
35
|
+
|
34
36
|
match = if node.block_type?
|
35
37
|
block_argument = argument.children.first.source
|
36
38
|
use_block_argument_in_key?(block_argument, key)
|
@@ -39,19 +41,22 @@ module RuboCop
|
|
39
41
|
end
|
40
42
|
next unless match
|
41
43
|
|
42
|
-
|
43
|
-
message = message(replacement, node)
|
44
|
-
|
45
|
-
add_offense(offense_range(node), message: message) do |corrector|
|
46
|
-
corrector.replace(offense_range(node), replacement)
|
47
|
-
end
|
44
|
+
register_offense(node, key)
|
48
45
|
end
|
49
46
|
end
|
50
47
|
alias on_numblock on_block
|
51
48
|
|
52
49
|
private
|
53
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
|
+
|
54
57
|
def use_block_argument_in_key?(block_argument, key)
|
58
|
+
return false if block_argument == key.source
|
59
|
+
|
55
60
|
key.each_descendant(:lvar).none? { |lvar| block_argument == lvar.source }
|
56
61
|
end
|
57
62
|
|
@@ -59,6 +64,15 @@ module RuboCop
|
|
59
64
|
node.send_node.loc.selector.join(node.loc.end)
|
60
65
|
end
|
61
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
|
+
|
62
76
|
def message(replacement, node)
|
63
77
|
current = offense_range(node).source
|
64
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
|