Skip to content

Commit

Permalink
Merge pull request #56 from lunarmodules/threadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque authored Mar 24, 2022
2 parents cc1a72d + bfbc70d commit 17ec37a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/luacheck/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ local function make_absolute_dirs(dir_path)

local make_ok, make_error = lfs.mkdir(dir_path)

-- Avoid race condition. Even if the mkdir returns an error it *may* be
-- because another thread created it in the mean time. If it exists now we
-- are good to move on and ignore the error.
if fs.is_dir(dir_path) then
return true
end

if not make_ok then
return nil, ("Couldn't make directory %s: %s"):format(dir_path, make_error)
end
Expand Down
29 changes: 13 additions & 16 deletions src/luacheck/stages/unwrap_parens.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ local replacements = {
le = ">",
}

local chstate

-- Mutates an array of nodes and non-tables, unwrapping Paren nodes.
-- If list_start is given, tail Paren is not unwrapped if it's unpacking and past list_start index.
local function handle_nodes(nodes, list_start)
local function handle_nodes(chstate, nodes, list_start)
local num_nodes = #nodes

for index = 1, num_nodes do
Expand All @@ -40,21 +38,21 @@ local function handle_nodes(nodes, list_start)
local tag = node.tag

if tag == "Table" or tag == "Return" then
handle_nodes(node, 1)
handle_nodes(chstate, node, 1)
elseif tag == "Call" then
handle_nodes(node, 2)
handle_nodes(chstate, node, 2)
elseif tag == "Invoke" then
handle_nodes(node, 3)
handle_nodes(chstate, node, 3)
elseif tag == "Forin" then
handle_nodes(node[2], 1)
handle_nodes(node[3])
handle_nodes(chstate, node[2], 1)
handle_nodes(chstate, node[3])
elseif tag == "Local" then
if node[2] then
handle_nodes(node[2])
handle_nodes(chstate, node[2])
end
elseif tag == "Set" then
handle_nodes(node[1])
handle_nodes(node[2], 1)
handle_nodes(chstate, node[1])
handle_nodes(chstate, node[2], 1)
else
-- warn that not x == y means (not x) == y
if tag ~= "Paren"
Expand All @@ -66,11 +64,11 @@ local function handle_nodes(nodes, list_start)
chstate:warn_range("582", node[1])
end

handle_nodes(node)
handle_nodes(chstate, node)

-- warn that not (x == y) can become x ~= y
if tag == "Op" and node[1] == "not" and node[2].tag == "Op" and relational_operators[node[2][1]] then
chstate:warn_range("581", node, {
chstate:warn_range("581", node, {
operator = relational_operators[node[2][1]],
replacement_operator = replacements[node[2][1]]
})
Expand All @@ -91,9 +89,8 @@ end
-- Mutates AST, unwrapping Paren nodes.
-- Paren nodes are preserved only when they matter:
-- at the ends of expression lists with potentially multi-value inner expressions.
function stage.run(check_state)
chstate = check_state
handle_nodes(check_state.ast)
function stage.run(chstate)
handle_nodes(chstate, chstate.ast)
end

return stage

0 comments on commit 17ec37a

Please sign in to comment.