diff --git a/src/luacheck/fs.lua b/src/luacheck/fs.lua index 101e6a1f..cf95b56c 100644 --- a/src/luacheck/fs.lua +++ b/src/luacheck/fs.lua @@ -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 diff --git a/src/luacheck/stages/unwrap_parens.lua b/src/luacheck/stages/unwrap_parens.lua index d790a27f..6d9a82bd 100644 --- a/src/luacheck/stages/unwrap_parens.lua +++ b/src/luacheck/stages/unwrap_parens.lua @@ -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 @@ -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" @@ -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]] }) @@ -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