Koihik / LuaFormatter

Code formatter for Lua
Apache License 2.0
708 stars 86 forks source link

Luau Syntax Support #243

Open djfjfofoc3 opened 2 years ago

djfjfofoc3 commented 2 years ago

Luau is a fork of Lua 5.1, primarily used by Roblox, but also used by other projects. Now Luau adds to the Lua 5.1 syntax in ways this project doesn't support. An example of this is it's type checking, which is typescript-alike in syntax, and a basic example of it can be found here:

local someFunction = function(var:string)
  -- some code, that uses var, where var is guaranteed to be a string
end;

This issue is basically me requesting support for Luau-syntax for this repo.

Useful Resources related to this:

Checklist:

I would personally really like if any, if not all of these are added to the project, since I hate converting code that uses these, to code that doesn't, just to make the formatter not complain.

Sincerely, - Mokiy

djfjfofoc3 commented 2 years ago

P.S. If all of the above are correctly implemented, this script should format without erroring:

type Str_Repeat = (string,number)->string; -- Type Definition using `type` keyword
local str_repeat: Str_Repeat = function(str, count)
  local str2 = "";
  for _ = 1, count do
    str2..=str; -- Compound Operator
  end
  return str2;
end;
local notOp = function(someBool:boolean) -- Type def using inline-parameter-stuff
  return if someBool then false else true -- If-then-else Expressions
end
for i=0,20,1 do
  if i==10 then
    continue; -- Continue statement
  end;
end;
print(
  str_repeat(
    tostring(
      notOp(true)
    ) .. '\u{22}', -- String Literals
    0x000_00F -- Number Literals
  )
);
Koihik commented 2 years ago

This seems like require a new project (or fork from lua-formatter) to implement.