1
0
Fork 0
mirror of https://github.com/Reuh/candran.git synced 2025-10-27 17:59:30 +00:00

Improve cancheck column detection for identifiers

This commit is contained in:
Étienne Fildadut 2020-12-24 18:17:27 +01:00
parent 24a3e0ed69
commit 98efdc95f4

View file

@ -99,6 +99,13 @@ local function check(can)
end
end
-- Errors codes highlighting a identifier (alphanumeric+underscore not starting with a number):
-- 1xx: global variables
-- 2xx: unused variables
-- 3xx: unused values
-- 4xx: shadowing delarations
local isIdentifier = tonumber(warning.code) >= 100 and tonumber(warning.code) < 500
-- calculating candran column
local can_line = can_lines[warning.can_line]
local lua_token = lua_line:sub(warning.column, warning.end_column)
@ -125,6 +132,14 @@ local function check(can)
start, stop = nstart, nstop
end
end
-- for non aliases token that are identifier, check if match is a full identifier
-- (avoid things like `let e` matching the e in let)
elseif start and isIdentifier then
local prev = can_line:sub(start-1, start-1)
local next = can_line:sub(stop, stop)
if prev:match("[%w_]") or next:match("[%w_]") then
can_n = can_n - 1 -- skip this match
end
end
-- found
if start then