Skip to content

Commit

Permalink
add -I option
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 22, 2025
1 parent 01c6bcd commit 52d6857
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
17 changes: 11 additions & 6 deletions cmd/tools/vvet/analyze.v
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ fn (mut vt VetAnalyze) expr(vet &Vet, expr ast.Expr) {

// long_or_empty_fns checks for long or empty functions
fn (mut vt VetAnalyze) long_or_empty_fns(mut vet Vet, fn_decl ast.FnDecl) {
nr_lines := fn_decl.end_pos.line_nr - fn_decl.pos.line_nr - 2
if nr_lines > long_fns_cutoff {
vet.notice('Long function - ${nr_lines} lines long.', fn_decl.pos.line_nr, .long_fns)
} else if nr_lines == 0 {
vet.notice('Empty function.', fn_decl.pos.line_nr, .empty_fn)
}
}

// potential_non_inlined checks for potential fns to be inlined
fn (mut vt VetAnalyze) potential_non_inlined(mut vet Vet, fn_decl ast.FnDecl) {
nr_lines := fn_decl.end_pos.line_nr - fn_decl.pos.line_nr - 2
if nr_lines < short_fns_cutoff {
attr := fn_decl.attrs.find_first('inline')
Expand All @@ -129,11 +139,6 @@ fn (mut vt VetAnalyze) long_or_empty_fns(mut vet Vet, fn_decl ast.FnDecl) {
}
}
}
if nr_lines > long_fns_cutoff {
vet.notice('Long function - ${nr_lines} lines long.', fn_decl.pos.line_nr, .long_fns)
} else if nr_lines == 0 {
vet.notice('Empty function.', fn_decl.pos.line_nr, .empty_fn)
}
}

// vet_fn_analysis reports repeated code by scope
Expand Down Expand Up @@ -176,7 +181,7 @@ fn (mut vt Vet) vet_code_analyze() {
if vt.opt.repeated_code {
vt.analyze.vet_repeated_code(mut vt)
}
if vt.opt.fn_sizing {
if vt.opt.fn_inlining {
vt.analyze.vet_inlining_fn(mut vt)
}
}
5 changes: 5 additions & 0 deletions cmd/tools/vvet/vvet.v
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct Options {
doc_private_fns_too bool
fn_sizing bool
repeated_code bool
fn_inlining bool
mut:
is_vfmt_off bool
}
Expand All @@ -52,6 +53,7 @@ fn main() {
|| (term_colors && '-nocolor' !in vet_options)
repeated_code: '-r' in vet_options
fn_sizing: '-F' in vet_options
fn_inlining: '-I' in vet_options
}
}
mut paths := cmdline.only_non_options(vet_options)
Expand Down Expand Up @@ -296,6 +298,9 @@ fn (mut vt Vet) stmt(stmt ast.Stmt) {
if vt.opt.fn_sizing {
vt.analyze.long_or_empty_fns(mut vt, stmt)
}
if vt.opt.fn_inlining {
vt.analyze.potential_non_inlined(mut vt, stmt)
}
vt.analyze.cur_fn = old_fn_decl
}
ast.StructDecl {
Expand Down
6 changes: 4 additions & 2 deletions vlib/v/help/common/vet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ Options:

-v, -verbose Enable verbose logging.

-F Report potential function to be inlined, empty, long function
declaration (>300 lines).
-F Report empty and long function declaration
(default: >300 lines).

-I Report potential function to be inlined.

-p Report private functions with missing documentation too
(by default, only the `pub fn` functions will be reported).
Expand Down

0 comments on commit 52d6857

Please sign in to comment.