Skip to content

Commit 713c95f

Browse files
authored
Fix: vet false warning on brackets in documentation (#17767)
1 parent db97630 commit 713c95f

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

cmd/tools/vvet/tests/brackets_in_documentation_comment_no_warn.out

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
// normalize_vector Normalizes a vector
3+
//
4+
// Example:
5+
// ```v
6+
// vector := Vector{3, 4}
7+
// normalize_vector(vector) // Vector{0.6, 0.8}
8+
// ```
9+
pub fn normalize_vector(vector f32) {}

cmd/tools/vvet/vvet.v

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,28 @@ fn (mut vt Vet) vet_fn_documentation(lines []string, line string, lnumber int) {
187187
prev_prev_line = lines[j - 1]
188188
}
189189
prev_line := lines[j]
190+
191+
if prev_line.starts_with('//') {
192+
if prev_line.starts_with('// ${fn_name} ') {
193+
grab = false
194+
break
195+
} else if prev_line.starts_with('// ${fn_name}')
196+
&& !prev_prev_line.starts_with('//') {
197+
grab = false
198+
clean_line := line.all_before_last('{').trim(' ')
199+
vt.warn('The documentation for "${clean_line}" seems incomplete.',
200+
lnumber, .doc)
201+
break
202+
}
203+
204+
continue
205+
}
206+
190207
if prev_line.contains('}') { // We've looked back to the above scope, stop here
191208
break
192-
} else if prev_line.starts_with('// ${fn_name} ') {
193-
grab = false
194-
break
195-
} else if prev_line.starts_with('// ${fn_name}')
196-
&& !prev_prev_line.starts_with('//') {
197-
grab = false
198-
clean_line := line.all_before_last('{').trim(' ')
199-
vt.warn('The documentation for "${clean_line}" seems incomplete.',
200-
lnumber, .doc)
201-
break
202209
} else if prev_line.starts_with('[') {
203210
tags << collect_tags(prev_line)
204211
continue
205-
} else if prev_line.starts_with('//') { // Single-line comment
206-
continue
207212
}
208213
}
209214
if grab {

0 commit comments

Comments
 (0)