fix: skip number literal hashes in SCL001 diagnostic

16#FFFF (hex), 2#1010 (binary), 8#777 (octal) are TIA Portal
base-specific number literals, not hash-prefixed variables.
Check if the character before # is a digit to distinguish them.
This commit is contained in:
2026-07-22 17:10:05 +02:00
parent dae99fb33e
commit 73735192bd
+9 -1
View File
@@ -138,12 +138,20 @@ function M.validate_diagnostics(content, workspace_types, root_dir)
return prefix == "T" or prefix == "D" or prefix == "S" return prefix == "T" or prefix == "D" or prefix == "S"
end end
-- Check if hash is part of a base-specific number literal like 16#FFFF, 2#1010
local function is_number_literal_at(line, match_start)
if not line or not match_start then return false end
if match_start <= 1 then return false end
local before = line:sub(match_start - 1, match_start - 1)
return before:match("%d") ~= nil
end
if not in_var_section then if not in_var_section then
local hash_vars = {} local hash_vars = {}
for var in line:gmatch("#[%w_]+") do for var in line:gmatch("#[%w_]+") do
local var_name = var:sub(2) local var_name = var:sub(2)
local match_start = line:find(var, 1, true) local match_start = line:find(var, 1, true)
if not is_iec_literal_at(line, match_start) then if not is_iec_literal_at(line, match_start) and not is_number_literal_at(line, match_start) then
hash_vars[var_name] = true hash_vars[var_name] = true
end end
end end