rubocop-vibe 0.5.0 → 0.6.0
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/config/default.yml +2 -0
- data/lib/rubocop/cop/vibe/attr_order.rb +8 -8
- data/lib/rubocop/cop/vibe/blank_line_after_assignment.rb +55 -55
- data/lib/rubocop/cop/vibe/blank_line_before_expectation.rb +39 -39
- data/lib/rubocop/cop/vibe/class_organization.rb +246 -345
- data/lib/rubocop/cop/vibe/consecutive_assignment_alignment.rb +30 -30
- data/lib/rubocop/cop/vibe/consecutive_constant_alignment.rb +30 -30
- data/lib/rubocop/cop/vibe/consecutive_indexed_assignment_alignment.rb +45 -45
- data/lib/rubocop/cop/vibe/consecutive_instance_variable_assignment_alignment.rb +30 -30
- data/lib/rubocop/cop/vibe/consecutive_let_alignment.rb +38 -38
- data/lib/rubocop/cop/vibe/consecutive_scope_alignment.rb +46 -46
- data/lib/rubocop/cop/vibe/constant_alpha_order.rb +27 -27
- data/lib/rubocop/cop/vibe/describe_block_order.rb +74 -67
- data/lib/rubocop/cop/vibe/explicit_return_conditional.rb +69 -69
- data/lib/rubocop/cop/vibe/is_expected_one_liner.rb +16 -16
- data/lib/rubocop/cop/vibe/keyword_argument_order.rb +46 -46
- data/lib/rubocop/cop/vibe/let_order.rb +34 -34
- data/lib/rubocop/cop/vibe/multiline_hash_argument_style.rb +63 -63
- data/lib/rubocop/cop/vibe/no_compound_conditions.rb +30 -30
- data/lib/rubocop/cop/vibe/no_rubocop_disable.rb +21 -22
- data/lib/rubocop/cop/vibe/no_skipped_tests.rb +8 -8
- data/lib/rubocop/cop/vibe/no_unless_guard_clause.rb +96 -96
- data/lib/rubocop/cop/vibe/prefer_one_liner_expectation.rb +35 -35
- data/lib/rubocop/cop/vibe/raise_unless_block.rb +20 -20
- data/lib/rubocop/cop/vibe/rspec_before_block_style.rb +18 -18
- data/lib/rubocop/cop/vibe/rspec_stub_chain_style.rb +100 -100
- data/lib/rubocop/cop/vibe/validate_after_validates.rb +39 -39
- data/lib/rubocop/cop/vibe/validates_alpha_order.rb +41 -41
- data/lib/rubocop/vibe/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: 32efe500f7fb50e4005a4ef34081405eee947bc058b96c684e60d3edb1095976
|
|
4
|
+
data.tar.gz: 79b4d44786594d509536e369756ead61b0cd34cd54cf288f857b4fa04e90f0a5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 62fb11ebb915d21241f1c0da9b6684564e457aeaa0469ce2fc5ec708bfaf1754f8b4f85dfc7167b7ea68b9e498424d6feb3e6afb57673f28a2921e88fba56f3d
|
|
7
|
+
data.tar.gz: 10bdf89f1dcfd15dbdfe06d293d3a6633193ecf953d50133be333d50b70b3ed7f84f081f6d40c4cbafd3fa68ae50839958ad1fe92eafddd44151b3f1c068e090
|
data/config/default.yml
CHANGED
|
@@ -85,6 +85,7 @@ Vibe/ClassOrganization:
|
|
|
85
85
|
Enabled: true
|
|
86
86
|
SafeAutoCorrect: false
|
|
87
87
|
VersionAdded: "0.1.0"
|
|
88
|
+
VersionChanged: "0.6.0"
|
|
88
89
|
|
|
89
90
|
Vibe/ConsecutiveAssignmentAlignment:
|
|
90
91
|
Description: "Enforces alignment of consecutive variable assignments at the = operator."
|
|
@@ -133,6 +134,7 @@ Vibe/DescribeBlockOrder:
|
|
|
133
134
|
Enabled: true
|
|
134
135
|
SafeAutoCorrect: false
|
|
135
136
|
VersionAdded: "0.1.0"
|
|
137
|
+
VersionChanged: "0.6.0"
|
|
136
138
|
|
|
137
139
|
Vibe/ExplicitReturnConditional:
|
|
138
140
|
Description: "Enforces explicit if/else/end blocks instead of ternary or trailing conditionals for return values."
|
|
@@ -42,14 +42,6 @@ module RuboCop
|
|
|
42
42
|
|
|
43
43
|
private
|
|
44
44
|
|
|
45
|
-
# Check if the node is an attr_* method call.
|
|
46
|
-
#
|
|
47
|
-
# @param [RuboCop::AST::Node] node The send node.
|
|
48
|
-
# @return [Boolean]
|
|
49
|
-
def attr_method?(node)
|
|
50
|
-
node.receiver.nil? && ATTR_METHODS.include?(node.method_name)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
45
|
# Check if all arguments are symbols.
|
|
54
46
|
#
|
|
55
47
|
# @param [Array<RuboCop::AST::Node>] arguments The arguments.
|
|
@@ -68,6 +60,14 @@ module RuboCop
|
|
|
68
60
|
names == names.sort
|
|
69
61
|
end
|
|
70
62
|
|
|
63
|
+
# Check if the node is an attr_* method call.
|
|
64
|
+
#
|
|
65
|
+
# @param [RuboCop::AST::Node] node The send node.
|
|
66
|
+
# @return [Boolean]
|
|
67
|
+
def attr_method?(node)
|
|
68
|
+
node.receiver.nil? && ATTR_METHODS.include?(node.method_name)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
71
|
# Auto-correct by reordering arguments alphabetically.
|
|
72
72
|
#
|
|
73
73
|
# @param [RuboCop::AST::Corrector] corrector The corrector.
|
|
@@ -68,6 +68,45 @@ module RuboCop
|
|
|
68
68
|
|
|
69
69
|
private
|
|
70
70
|
|
|
71
|
+
# Get the variable name from an assignment node.
|
|
72
|
+
#
|
|
73
|
+
# @param [RuboCop::AST::Node] node The assignment node.
|
|
74
|
+
# @return [Symbol, nil]
|
|
75
|
+
def assigned_variable_name(node)
|
|
76
|
+
return node.children.first if node.lvasgn_type?
|
|
77
|
+
|
|
78
|
+
target = node.children.first
|
|
79
|
+
|
|
80
|
+
if target.lvasgn_type?
|
|
81
|
+
target.children.first
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Check if a node is a variable assignment.
|
|
86
|
+
#
|
|
87
|
+
# @param [RuboCop::AST::Node] node The node to check.
|
|
88
|
+
# @return [Boolean]
|
|
89
|
+
def assignment?(node)
|
|
90
|
+
node.type?(:lvasgn, :op_asgn, :or_asgn, :and_asgn)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Get the value being assigned.
|
|
94
|
+
#
|
|
95
|
+
# @param [RuboCop::AST::Node] node The assignment node.
|
|
96
|
+
# @return [RuboCop::AST::Node, nil]
|
|
97
|
+
def assignment_value(node)
|
|
98
|
+
node.children.last
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Check if there's a blank line between two statements.
|
|
102
|
+
#
|
|
103
|
+
# @param [RuboCop::AST::Node] previous_node The previous statement.
|
|
104
|
+
# @param [RuboCop::AST::Node] current_node The current statement.
|
|
105
|
+
# @return [Boolean]
|
|
106
|
+
def blank_line_between?(previous_node, current_node)
|
|
107
|
+
current_node.loc.line - previous_node.loc.last_line > 1
|
|
108
|
+
end
|
|
109
|
+
|
|
71
110
|
# Check the body for missing blank lines after assignments.
|
|
72
111
|
#
|
|
73
112
|
# @param [RuboCop::AST::Node] body The body node.
|
|
@@ -82,18 +121,6 @@ module RuboCop
|
|
|
82
121
|
end
|
|
83
122
|
end
|
|
84
123
|
|
|
85
|
-
# Extract statements from a body node.
|
|
86
|
-
#
|
|
87
|
-
# @param [RuboCop::AST::Node] body The body node.
|
|
88
|
-
# @return [Array<RuboCop::AST::Node>]
|
|
89
|
-
def extract_statements(body)
|
|
90
|
-
if body.begin_type?
|
|
91
|
-
body.children
|
|
92
|
-
else
|
|
93
|
-
[body]
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
124
|
# Check a pair of statements for missing blank line after assignment.
|
|
98
125
|
#
|
|
99
126
|
# @param [RuboCop::AST::Node] current The current statement.
|
|
@@ -114,17 +141,6 @@ module RuboCop
|
|
|
114
141
|
end
|
|
115
142
|
end
|
|
116
143
|
|
|
117
|
-
# Get the inner statement from a modifier node.
|
|
118
|
-
#
|
|
119
|
-
# @param [RuboCop::AST::Node] node The node to unwrap.
|
|
120
|
-
# @return [RuboCop::AST::Node]
|
|
121
|
-
def inner_statement(node)
|
|
122
|
-
return node.if_branch if node.type?(:if) && node.modifier_form?
|
|
123
|
-
return node.body if node.type?(:while, :until) && node.modifier_form?
|
|
124
|
-
|
|
125
|
-
node
|
|
126
|
-
end
|
|
127
|
-
|
|
128
144
|
# Check if both statements are FactoryBot calls.
|
|
129
145
|
#
|
|
130
146
|
# @param [RuboCop::AST::Node] assignment The assignment node.
|
|
@@ -134,12 +150,16 @@ module RuboCop
|
|
|
134
150
|
factory_bot_call?(assignment_value(assignment)) && factory_bot_call?(following)
|
|
135
151
|
end
|
|
136
152
|
|
|
137
|
-
#
|
|
153
|
+
# Extract statements from a body node.
|
|
138
154
|
#
|
|
139
|
-
# @param [RuboCop::AST::Node]
|
|
140
|
-
# @return [RuboCop::AST::Node
|
|
141
|
-
def
|
|
142
|
-
|
|
155
|
+
# @param [RuboCop::AST::Node] body The body node.
|
|
156
|
+
# @return [Array<RuboCop::AST::Node>]
|
|
157
|
+
def extract_statements(body)
|
|
158
|
+
if body.begin_type?
|
|
159
|
+
body.children
|
|
160
|
+
else
|
|
161
|
+
[body]
|
|
162
|
+
end
|
|
143
163
|
end
|
|
144
164
|
|
|
145
165
|
# Check if a node is a FactoryBot method call.
|
|
@@ -167,18 +187,15 @@ module RuboCop
|
|
|
167
187
|
receiver.lvar_type? && receiver.children.first == var_name
|
|
168
188
|
end
|
|
169
189
|
|
|
170
|
-
# Get the
|
|
190
|
+
# Get the inner statement from a modifier node.
|
|
171
191
|
#
|
|
172
|
-
# @param [RuboCop::AST::Node] node The
|
|
173
|
-
# @return [
|
|
174
|
-
def
|
|
175
|
-
return node.
|
|
176
|
-
|
|
177
|
-
target = node.children.first
|
|
192
|
+
# @param [RuboCop::AST::Node] node The node to unwrap.
|
|
193
|
+
# @return [RuboCop::AST::Node]
|
|
194
|
+
def inner_statement(node)
|
|
195
|
+
return node.if_branch if node.type?(:if) && node.modifier_form?
|
|
196
|
+
return node.body if node.type?(:while, :until) && node.modifier_form?
|
|
178
197
|
|
|
179
|
-
|
|
180
|
-
target.children.first
|
|
181
|
-
end
|
|
198
|
+
node
|
|
182
199
|
end
|
|
183
200
|
|
|
184
201
|
# Get the leftmost receiver in a method chain.
|
|
@@ -195,23 +212,6 @@ module RuboCop
|
|
|
195
212
|
|
|
196
213
|
current
|
|
197
214
|
end
|
|
198
|
-
|
|
199
|
-
# Check if a node is a variable assignment.
|
|
200
|
-
#
|
|
201
|
-
# @param [RuboCop::AST::Node] node The node to check.
|
|
202
|
-
# @return [Boolean]
|
|
203
|
-
def assignment?(node)
|
|
204
|
-
node.type?(:lvasgn, :op_asgn, :or_asgn, :and_asgn)
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
# Check if there's a blank line between two statements.
|
|
208
|
-
#
|
|
209
|
-
# @param [RuboCop::AST::Node] previous_node The previous statement.
|
|
210
|
-
# @param [RuboCop::AST::Node] current_node The current statement.
|
|
211
|
-
# @return [Boolean]
|
|
212
|
-
def blank_line_between?(previous_node, current_node)
|
|
213
|
-
current_node.loc.line - previous_node.loc.last_line > 1
|
|
214
|
-
end
|
|
215
215
|
end
|
|
216
216
|
end
|
|
217
217
|
end
|
|
@@ -55,36 +55,13 @@ module RuboCop
|
|
|
55
55
|
|
|
56
56
|
private
|
|
57
57
|
|
|
58
|
-
# Check if
|
|
58
|
+
# Check if there's a blank line between two statements.
|
|
59
59
|
#
|
|
60
|
-
# @param [RuboCop::AST::Node]
|
|
60
|
+
# @param [RuboCop::AST::Node] previous_node The previous statement.
|
|
61
|
+
# @param [RuboCop::AST::Node] current_node The current statement.
|
|
61
62
|
# @return [Boolean]
|
|
62
|
-
def
|
|
63
|
-
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Extract statements from the block body.
|
|
67
|
-
#
|
|
68
|
-
# @param [RuboCop::AST::Node] body The block body.
|
|
69
|
-
# @return [Array<RuboCop::AST::Node>]
|
|
70
|
-
def extract_statements(body)
|
|
71
|
-
if body.begin_type?
|
|
72
|
-
body.children
|
|
73
|
-
else
|
|
74
|
-
[body]
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# Check statements for missing blank lines before expectations.
|
|
79
|
-
#
|
|
80
|
-
# @param [Array<RuboCop::AST::Node>] statements The statements to check.
|
|
81
|
-
# @return [void]
|
|
82
|
-
def check_statements(statements)
|
|
83
|
-
statements.each_with_index do |statement, index|
|
|
84
|
-
next if index.zero?
|
|
85
|
-
|
|
86
|
-
check_statement_pair(statements[index - 1], statement)
|
|
87
|
-
end
|
|
63
|
+
def blank_line_between?(previous_node, current_node)
|
|
64
|
+
current_node.loc.line - previous_node.loc.last_line > 1
|
|
88
65
|
end
|
|
89
66
|
|
|
90
67
|
# Check a pair of statements for missing blank line.
|
|
@@ -102,14 +79,27 @@ module RuboCop
|
|
|
102
79
|
register_offense(expect_node, previous_statement)
|
|
103
80
|
end
|
|
104
81
|
|
|
105
|
-
#
|
|
82
|
+
# Check statements for missing blank lines before expectations.
|
|
106
83
|
#
|
|
107
|
-
# @param [RuboCop::AST::Node]
|
|
108
|
-
# @param [RuboCop::AST::Node] previous_statement The previous statement.
|
|
84
|
+
# @param [Array<RuboCop::AST::Node>] statements The statements to check.
|
|
109
85
|
# @return [void]
|
|
110
|
-
def
|
|
111
|
-
|
|
112
|
-
|
|
86
|
+
def check_statements(statements)
|
|
87
|
+
statements.each_with_index do |statement, index|
|
|
88
|
+
next if index.zero?
|
|
89
|
+
|
|
90
|
+
check_statement_pair(statements[index - 1], statement)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Extract statements from the block body.
|
|
95
|
+
#
|
|
96
|
+
# @param [RuboCop::AST::Node] body The block body.
|
|
97
|
+
# @return [Array<RuboCop::AST::Node>]
|
|
98
|
+
def extract_statements(body)
|
|
99
|
+
if body.begin_type?
|
|
100
|
+
body.children
|
|
101
|
+
else
|
|
102
|
+
[body]
|
|
113
103
|
end
|
|
114
104
|
end
|
|
115
105
|
|
|
@@ -133,13 +123,23 @@ module RuboCop
|
|
|
133
123
|
node.each_descendant(:send).find { |send_node| expect_call?(send_node) }
|
|
134
124
|
end
|
|
135
125
|
|
|
136
|
-
# Check if
|
|
126
|
+
# Check if the block should be processed.
|
|
137
127
|
#
|
|
138
|
-
# @param [RuboCop::AST::Node]
|
|
139
|
-
# @param [RuboCop::AST::Node] current_node The current statement.
|
|
128
|
+
# @param [RuboCop::AST::Node] node The block node.
|
|
140
129
|
# @return [Boolean]
|
|
141
|
-
def
|
|
142
|
-
|
|
130
|
+
def processable_block?(node)
|
|
131
|
+
spec_file? && example_block?(node) && node.body
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Register an offense for missing blank line.
|
|
135
|
+
#
|
|
136
|
+
# @param [RuboCop::AST::Node] expect_node The expect node.
|
|
137
|
+
# @param [RuboCop::AST::Node] previous_statement The previous statement.
|
|
138
|
+
# @return [void]
|
|
139
|
+
def register_offense(expect_node, previous_statement)
|
|
140
|
+
add_offense(expect_node.loc.selector) do |corrector|
|
|
141
|
+
corrector.insert_after(previous_statement, "\n")
|
|
142
|
+
end
|
|
143
143
|
end
|
|
144
144
|
end
|
|
145
145
|
end
|