diff --git a/cmd/tools/vvet/analyze.v b/cmd/tools/vvet/analyze.v index 973ef3aca0dc27..d155c39a27549b 100644 --- a/cmd/tools/vvet/analyze.v +++ b/cmd/tools/vvet/analyze.v @@ -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') @@ -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 @@ -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) } } diff --git a/cmd/tools/vvet/vvet.v b/cmd/tools/vvet/vvet.v index 64f1ed25529db4..168e9923167d5a 100644 --- a/cmd/tools/vvet/vvet.v +++ b/cmd/tools/vvet/vvet.v @@ -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 } @@ -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) @@ -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 { diff --git a/vlib/v/help/common/vet.txt b/vlib/v/help/common/vet.txt index 6beaf606ec54de..ba2a71013fd8ad 100644 --- a/vlib/v/help/common/vet.txt +++ b/vlib/v/help/common/vet.txt @@ -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).