mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tools: handle fn attributes/comments more robustly, when v missdoc
is run (#14774)
This commit is contained in:
parent
01fdd5d07f
commit
18dfaf6164
@ -62,38 +62,30 @@ fn (opt &Options) collect_undocumented_functions_in_file(nfile string) []Undocum
|
||||
contents := os.read_file(file) or { panic(err) }
|
||||
lines := contents.split('\n')
|
||||
mut list := []UndocumentedFN{}
|
||||
mut comments := []string{}
|
||||
mut tags := []string{}
|
||||
for i, line in lines {
|
||||
if line.starts_with('pub fn') || (opt.private && (line.starts_with('fn ')
|
||||
&& !(line.starts_with('fn C.') || line.starts_with('fn main')))) {
|
||||
// println('Match: $line')
|
||||
if i > 0 && lines.len > 0 {
|
||||
mut line_above := lines[i - 1]
|
||||
if !line_above.starts_with('//') {
|
||||
mut tags := []string{}
|
||||
mut grab := true
|
||||
for j := i - 1; j >= 0; j-- {
|
||||
prev_line := lines[j]
|
||||
if prev_line.contains('}') { // We've looked back to the above scope, stop here
|
||||
break
|
||||
} else if prev_line.starts_with('[') {
|
||||
tags << collect_tags(prev_line)
|
||||
continue
|
||||
} else if prev_line.starts_with('//') { // Single-line comment
|
||||
grab = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if grab {
|
||||
clean_line := line.all_before_last(' {')
|
||||
list << UndocumentedFN{
|
||||
line: i + 1
|
||||
signature: clean_line
|
||||
tags: tags
|
||||
file: file
|
||||
}
|
||||
}
|
||||
if line.starts_with('//') {
|
||||
comments << line
|
||||
} else if line.trim_space().starts_with('[') {
|
||||
tags << collect_tags(line)
|
||||
} else if line.starts_with('pub fn')
|
||||
|| (opt.private && (line.starts_with('fn ') && !(line.starts_with('fn C.')
|
||||
|| line.starts_with('fn main')))) {
|
||||
if comments.len == 0 {
|
||||
clean_line := line.all_before_last(' {')
|
||||
list << UndocumentedFN{
|
||||
line: i + 1
|
||||
signature: clean_line
|
||||
tags: tags
|
||||
file: file
|
||||
}
|
||||
}
|
||||
tags = []
|
||||
comments = []
|
||||
} else {
|
||||
tags = []
|
||||
comments = []
|
||||
}
|
||||
}
|
||||
return list
|
||||
|
Loading…
Reference in New Issue
Block a user