Skip to content

Commit

Permalink
Fix top level config options not applied to stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeterv committed Jul 11, 2015
1 parent 8069ac5 commit f91150b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
8 changes: 8 additions & 0 deletions spec/cli_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,14 @@ Total: 0 warnings / 0 errors in 1 file
]], get_output "spec/samples/compat.lua --config=spec/configs/global_config.luacheckrc")
end)

it("uses config when checking stdin", function()
assert.equal([[
Checking stdin OK
Total: 0 warnings / 0 errors in 1 file
]], get_output "- --config=spec/configs/global_config.luacheckrc < spec/samples/compat.lua")
end)

it("uses per-file overrides", function()
assert.equal([[
Checking spec/samples/bad_code.lua Failure
Expand Down
11 changes: 8 additions & 3 deletions src/luacheck/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,20 @@ function config.get_top_options(conf)
return conf.empty and {} or conf.options
end

-- Returns array of options for a path.
function config.get_options(conf, path)
-- Returns array of options for a file.
function config.get_options(conf, file)
if conf.empty then
return {}
end

path = fs.normalize(fs.join(conf.cur_dir, path))
local res = {conf.options}

if type(file) ~= "string" then
return res
end

local path = fs.normalize(fs.join(conf.cur_dir, file))

for _, override_path in ipairs(conf.overrides.paths) do
if fs.is_subpath(override_path, path) then
table.insert(res, conf.overrides.options[override_path])
Expand Down
8 changes: 2 additions & 6 deletions src/luacheck/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,8 @@ Otherwise, the pattern matches warning code.]])
local res = {}

for i, file in ipairs(files) do
if type(file) == "string" then
res[i] = config.get_options(conf, file)
table.insert(res[i], cli_opts)
else
res[i] = cli_opts
end
res[i] = config.get_options(conf, file)
table.insert(res[i], cli_opts)
end

return res
Expand Down

0 comments on commit f91150b

Please sign in to comment.