Skip to content

Commit

Permalink
Allow using space instead of underscore in inline options
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeterv committed Jul 17, 2015
1 parent c968312 commit 8eff4b7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
4 changes: 2 additions & 2 deletions spec/samples/global_inline_options.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- luacheck: allow_defined_top
-- luacheck: allow defined top
foo = 4
print(foo)
bar = 6 -- luacheck: ignore 131

function f()
baz = 5
-- luacheck: allow_defined
-- luacheck: allow defined
qu = 4
print(qu)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/samples/inline_options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
foo()
bar()

local function f(a) -- luacheck: no unused_args
local function f(a) -- luacheck: no unused args
-- luacheck: globals baz
foo()
bar()
Expand Down
2 changes: 1 addition & 1 deletion spec/samples/read_globals_inline_options.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- luacheck: read_globals foo bar
-- luacheck: read globals foo bar
foo(bar, baz)
foo, bar, baz, baz[1] = false, true, nil, 5 -- luacheck: ignore 111/foo 121/ba.
-- luacheck: globals bar baz
Expand Down
45 changes: 27 additions & 18 deletions src/luacheck/inline_options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,48 @@ local function get_options(body)

for _, name_and_args in ipairs(utils.split(body, ",")) do
local args = utils.split(name_and_args)
local name = args[1]
local name = table.remove(args, 1)

if not name then
return
end

table.remove(args, 1)

if name == "std" then
if #args ~= 1 or not options.split_std(args[1]) then
return
end

opts.std = args[1]
elseif name == "ignore" and #args == 0 then
opts.ignore = {".*/.*"}
else
if name == "ignore" and #args == 0 then
args[1] = ".*/.*"
end

if options.variadic_inline_options[name] then
opts[name] = args
else
local flag = true
local flag = true

if name == "no" then
name = table.remove(args, 1)
flag = false
end
if name == "no" then
flag = false
name = table.remove(args, 1)
end

if options.nullary_inline_options[name] and #args == 0 then
opts[name] = flag
while true do
if options.variadic_inline_options[name] then
if flag then
opts[name] = args
break
else
-- Array option with 'no' prefix is invalid.
return
end
elseif #args == 0 then
if options.nullary_inline_options[name] then
opts[name] = flag
break
else
-- Consumed all arguments but didn't find a valid option name.
return
end
else
return
-- Join name with next argument,
name = name.."_"..table.remove(args, 1)
end
end
end
Expand Down

0 comments on commit 8eff4b7

Please sign in to comment.