Skip to content

Commit

Permalink
notにも対応。()のネストが深い場合に対応。
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatakinov committed Jul 23, 2022
1 parent f2fb9fe commit da75b43
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions yayalint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -541,14 +541,21 @@ local function recursive(scope, gv, upper, filename, funcname, global, opt)
end
end

local function assignmentInCondition(t, filename)
for _, v in ipairs(t) do
local function assignmentInCondition(t, filename, has_comparison)
local function child(t)
return #t == 1 and child(t[1]) or t
end
for i, v in ipairs(t) do
if type(v) == "table" then
if v.assign then
if v.assign and not(has_comparison) then
output:append(table.concat({"assignment operator exists in conditional statement:", v.assign, "at", filename, "pos:", v.line .. ":" .. v.col}, OutputSep)):append(NewLine)
end
if #v > 0 then
assignmentInCondition(v, filename)
local pre = t[i - 1] or {}
local post = t[i + 1] or {}
pre = pre.comparison or pre["not"]
post = post.comparison or post["not"]
assignmentInCondition(child(v), filename, pre or post)
end
end
end
Expand Down

0 comments on commit da75b43

Please sign in to comment.