head 1.3; access; symbols perseant-exfatfs-base-20261102:1.3 netbsd-11-1-RELEASE:1.3 netbsd-10-2-RELEASE:1.2 netbsd-11-0-RELEASE:1.3 netbsd-11-0-RC7:1.3 netbsd-11-0-RC6:1.3 netbsd-11-0-RC5:1.3 netbsd-11-0-RC4:1.3 netbsd-11-0-RC3:1.3 netbsd-11-0-RC2:1.3 netbsd-11-0-RC1:1.3 perseant-exfatfs-base-20250801:1.3 netbsd-11:1.3.0.2 netbsd-11-base:1.3 netbsd-10-1-RELEASE:1.2 perseant-exfatfs-base-20240630:1.2 perseant-exfatfs:1.2.0.4 perseant-exfatfs-base:1.2 netbsd-10-0-RELEASE:1.2 netbsd-10-0-RC6:1.2 netbsd-10-0-RC5:1.2 netbsd-10-0-RC4:1.2 netbsd-10-0-RC3:1.2 netbsd-10-0-RC2:1.2 netbsd-10-0-RC1:1.2 netbsd-10:1.2.0.2 netbsd-10-base:1.2 cjep_sun2x-base1:1.1 cjep_sun2x:1.1.0.4 cjep_sun2x-base:1.1 cjep_staticlib_x-base1:1.1 cjep_staticlib_x:1.1.0.2 cjep_staticlib_x-base:1.1; locks; strict; comment @# @; 1.3 date 2024.11.30.18.17.11; author rillig; state Exp; branches; next 1.2; commitid 4Hpg5WbzfkKJjHzF; 1.2 date 2021.09.10.21.05.08; author rillig; state Exp; branches 1.2.4.1; next 1.1; commitid 1KtENolj0EuN7s8D; 1.1 date 2021.02.28.18.17.08; author rillig; state Exp; branches; next ; commitid esQGfbit98AtqvJC; 1.2.4.1 date 2025.08.02.05.58.46; author perseant; state Exp; branches; next ; commitid 23j6GFaDws3O875G; desc @@ 1.3 log @lint: reword lint2 warnings, reduce punctuation The previous diagnostics used unusual punctuation, for example by placing spaces inside parentheses, as well as using space-space-tab and double-colon as separators. Convert these diagnostics into readily readable prose, and mark them clearly as coming from lint2, so that they can be related to the tests in /usr/tests/usr.bin/xlint/lint2/msg_???.ln. This change means that usr.bin/error no longer recognizes these messages as coming from lint2, but that can be fixed later if necessary. @ text @#! /usr/bin/lua -- $NetBSD: check-msgs.lua,v 1.2 2021/09/10 21:05:08 rillig Exp $ --[[ usage: lua ./check-msgs.lua *.c Check that the message text in the comments of the C source code matches the actual user-visible message text in msg.c. ]] local function load_messages(fname) local msgs = {} ---@@type tablestring local f = assert(io.open(fname, "r")) for line in f:lines() do local msg, id = line:match("%s*\"(.+)\",%s*// (%d+)$") if msg ~= nil then msgs[tonumber(id)] = msg end end f:close() return msgs end local had_errors = false ---@@param fmt string function print_error(fmt, ...) print(fmt:format(...)) had_errors = true end local function check_message(fname, lineno, id, comment, msgs) local msg = msgs[id] if msg == nil then print_error("%s:%d: id=%d not found", fname, lineno, id) return end msg = msg:gsub("/%*", "**") msg = msg:gsub("%*/", "**") msg = msg:gsub("\\t", "\\\\t") -- for lint2 msg = msg:gsub("\\(.)", "%1") if comment == msg then return end local prefix = comment:match("^(.-)%s*%.%.%.$") if prefix ~= nil and msg:find(prefix, 1, 1) == 1 then return end print_error("%s:%d: id=%-3d msg=%-40s comment=%s", fname, lineno, id, msg, comment) end local function check_file(fname, msgs) local f = assert(io.open(fname, "r")) local lineno = 0 local prev = "" for line in f:lines() do lineno = lineno + 1 local func, id = line:match("^%s+(%w+)%((%d+)[),]") id = tonumber(id) if func == "msg" then local comment = prev:match("^%s+/%* (.+) %*/$") if comment ~= nil then check_message(fname, lineno, id, comment, msgs) else print_error("%s:%d: missing comment for %d: /* %s */", fname, lineno, id, msgs[id]) end end prev = line end f:close() end local function main(arg) local msgs = load_messages("msg.c") for _, fname in ipairs(arg) do check_file(fname, msgs) end end main(arg) os.exit(not had_errors) @ 1.2 log @tests/lint: align message checker for lint2 to the one from lint1 No functional change. @ text @d2 1 a2 1 -- $NetBSD: check-msgs.lua,v 1.1 2021/02/28 18:17:08 rillig Exp $ d19 1 a19 1 local msg, id = line:match("%s*\"(.+)\",%s*/%*%s*(%d+)%s*%*/$") @ 1.2.4.1 log @Sync with HEAD @ text @d2 1 a2 1 -- $NetBSD: check-msgs.lua,v 1.3 2024/11/30 18:17:11 rillig Exp $ d19 1 a19 1 local msg, id = line:match("%s*\"(.+)\",%s*// (%d+)$") @ 1.1 log @lint2: add redundancy checker for comments in source code Based on the redundancy checker for lint1. No functional change. @ text @d2 1 a2 1 -- $NetBSD$ d15 1 a15 1 local msgs = {} d31 9 a39 1 local function check_message(fname, lineno, id, comment, msgs, errors) d43 1 a43 1 errors:add("%s:%d: id=%d not found", fname, lineno, id) d61 1 a61 1 errors:add("%s:%d: id=%-3d msg=%-40s comment=%s", d66 1 a66 6 local function collect_errors(fname, msgs) local errors = {} errors.add = function(self, fmt, ...) table.insert(self, fmt:format(...)) end d78 1 a78 1 check_message(fname, lineno, id, comment, msgs, errors) d80 1 a80 1 errors:add("%s:%d: missing comment for %d: /* %s */", a88 11 return errors end local function check_file(fname, msgs) local errors = collect_errors(fname, msgs) for _, err in ipairs(errors) do print(err) end return #errors == 0 a93 1 local ok = true d95 1 a95 1 ok = check_file(fname, msgs) and ok a96 1 return ok d99 2 a100 2 os.exit(main(arg)) @