yoshiki 11.0.0.pre.8 → 11.0.0.pre.9
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/Gemfile.lock +1 -1
- data/lib/rubocop/cop/yoshiki/style/it_block_parameter.rb +22 -12
- data/lib/yoshiki/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 15c6b40d96843b4e382ed33f54c8f0aab30f8f7c85f84b79f52552ec0ca68f30
|
|
4
|
+
data.tar.gz: 43addf10ac85160ca98e9a10df47db1defe7d3ff841bcca1eb30e7689dfccd6c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4443fd5e0d5d268a8a3b4adaea6ee4dabea427803b1fdad635012fca031f9cb2ab9b9b7f5cce3b89fad100c676738a3293e11efaa30ad8d422810cafe9237465
|
|
7
|
+
data.tar.gz: 185d9c3f40485a41cf997573098c93ed4dd01b95d1aa18fb06896a2e9d9df469c18f07046cfd93155fefded56747a2ba1449c8d7b1cf4d3f7ef121e502247546
|
data/Gemfile.lock
CHANGED
|
@@ -34,11 +34,8 @@ module RuboCop
|
|
|
34
34
|
return unless node.arguments.one?
|
|
35
35
|
return unless node.first_argument.arg_type?
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
remove_block_arguments(corrector, node)
|
|
40
|
-
corrector.replace(variable, 'it')
|
|
41
|
-
end
|
|
37
|
+
correct_to_it(node, node.first_argument.source) do |corrector|
|
|
38
|
+
remove_block_arguments(corrector, node)
|
|
42
39
|
end
|
|
43
40
|
end
|
|
44
41
|
|
|
@@ -47,11 +44,7 @@ module RuboCop
|
|
|
47
44
|
return unless node.single_line?
|
|
48
45
|
return unless node.children[1] == 1
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
add_offense(variable, message: MSG_USE_IT_PARAMETER) do |corrector|
|
|
52
|
-
corrector.replace(variable, 'it')
|
|
53
|
-
end
|
|
54
|
-
end
|
|
47
|
+
correct_to_it(node, '_1')
|
|
55
48
|
end
|
|
56
49
|
|
|
57
50
|
private
|
|
@@ -66,8 +59,17 @@ module RuboCop
|
|
|
66
59
|
corrector.remove(range)
|
|
67
60
|
end
|
|
68
61
|
|
|
69
|
-
def
|
|
70
|
-
find_block_variables(node, name)
|
|
62
|
+
def correct_to_it node, name, &before_replace
|
|
63
|
+
variables = find_block_variables(node, name)
|
|
64
|
+
return if variables.empty?
|
|
65
|
+
return if variables.any? { used_in_nested_block?(it, node) }
|
|
66
|
+
|
|
67
|
+
variables.each do |variable|
|
|
68
|
+
add_offense(variable, message: MSG_USE_IT_PARAMETER) do |corrector|
|
|
69
|
+
before_replace&.call(corrector)
|
|
70
|
+
corrector.replace(variable, 'it')
|
|
71
|
+
end
|
|
72
|
+
end
|
|
71
73
|
end
|
|
72
74
|
|
|
73
75
|
def find_block_variables node, name
|
|
@@ -78,6 +80,14 @@ module RuboCop
|
|
|
78
80
|
vars
|
|
79
81
|
end
|
|
80
82
|
|
|
83
|
+
# `it` is per-block. Replacing an outer param that is read inside an
|
|
84
|
+
# inner block would bind those reads to the inner `it`.
|
|
85
|
+
def used_in_nested_block? variable, block_node
|
|
86
|
+
variable.each_ancestor
|
|
87
|
+
.take_while { !it.equal?(block_node) }
|
|
88
|
+
.any?(&:any_block_type?)
|
|
89
|
+
end
|
|
90
|
+
|
|
81
91
|
end
|
|
82
92
|
end
|
|
83
93
|
end
|
data/lib/yoshiki/version.rb
CHANGED