Skip to content

Commit

Permalink
tools: colorise the output of cmd/tools/show_ancient_deprecations.v, …
Browse files Browse the repository at this point in the history
…reduce false positives (#22048)
  • Loading branch information
spytheman committed Aug 15, 2024
1 parent f879368 commit a7e7335
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cmd/tools/show_ancient_deprecations.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import term
import time

struct Context {
Expand All @@ -15,13 +16,13 @@ fn (mut ctx Context) analyze_line(line string, position_file string, position_li
ts := blame_for_time.output.all_after('committer-time').all_before('\n').trim_space().int()
t := time.unix(ts)
if ctx.cut_time < t {
println('>>> SKIPPING since t: ${t} > ${ctx.cut_time}, line: ${line}')
println(term.colorize(term.gray, '>>> SKIPPING since t: ${t} > ${ctx.cut_time}, ${position_file}:${position_line}: ${line}'))
return
}
ctx.deprecations++
blame_for_context := os.execute('git blame -L${position_line},+5 -- ${position_file}')
context := blame_for_context.output.trim_space().split_into_lines()
println('${position_file}:${position_line}: deprecation: ${ctx.deprecations}, timestamp: ${ts} - ${t}')
println(term.colorize(term.red, '${position_file}:${position_line}: deprecation: ${ctx.deprecations}, timestamp: ${ts} - ${t}'))
for cline in context {
println(' ${cline}')
}
Expand All @@ -41,11 +42,11 @@ fn main() {
all_v_files := os.walk_ext('.', '.v')
for v_file in all_v_files {
if v_file == './vlib/v/fmt/tests/attrs_keep.vv' {
println('>>> SKIPPING deprecations attrs formatting test file ${v_file}')
println(term.colorize(term.gray, '>>> SKIPPING deprecations attrs formatting test file ${v_file}'))
continue
}
if v_file.starts_with('./vlib/v/checker/tests') && v_file.contains('deprec') {
println('>>> SKIPPING deprecations test file ${v_file}')
println(term.colorize(term.gray, '>>> SKIPPING deprecations test file ${v_file}'))
continue
}
file_content := os.read_file(v_file)!
Expand All @@ -56,6 +57,9 @@ fn main() {
for line_num := lines.len - 1; line_num > 0; line_num-- {
line := lines[line_num]
mut is_deprecation_line := false
if line.contains('\tif ') {
continue
}
if line.contains('[deprecated:') {
is_deprecation_line = true
}
Expand All @@ -68,5 +72,9 @@ fn main() {
ctx.analyze_line(line, v_file, line_num + 1)
}
}
println('> Summary: there were ${ctx.deprecations} deprecations found, done before ${cut_time}.')
println('> Summary: there were ${term.colorize(term.bright_yellow, ctx.deprecations.str())} deprecations found, done before ${term.colorize(term.magenta,
cut_time.str())}.')
if ctx.deprecations > 0 {
exit(1)
}
}

0 comments on commit a7e7335

Please sign in to comment.