Koihik / LuaFormatter

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

help: two blank lines between the functions. How to set this format? #157

Open membphis opened 3 years ago

membphis commented 3 years ago

I checked the doc: https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md

I do not find this field.

membphis commented 3 years ago

@Koihik can you give me some suggestions about this feature? I want to make a try with it.

tammela commented 3 years ago

I didn't quite understand what you want to achieve.

Could you provide some code samples?

membphis commented 3 years ago

need a way to specify the style(one or two blank lines between the functions):

-- two blank lines between the functions
function x()
  print(1)
end

function y()
  print(1)
end

-- one blank line between the functions
function x()
  print(1)
end

function y()
  print(1)
end
tammela commented 3 years ago

We don't have this configuration and at a glance it seems non trivial (perhaps even impossible) to implement

membphis commented 3 years ago

here is my hack way:

https://github.com/Koihik/LuaFormatter/compare/master...membphis:membphis-2blank-func

I do not sure if it is acceptable, if yes, I'll try to submit a PR.

tammela commented 3 years ago

here is my hack way:

master...membphis:membphis-2blank-func

I do not sure if it is acceptable, if yes, I'll try to submit a PR.

If it works out for you then it's fine. The problem is that we can't accept it as is because it would also affect code like this:

set_callback(function ()
   -- ...
end)

function foo()
   function bar()
   end
   -- ...
end

local a = function ()
   -- ...
end

The visitor pattern that we use to parse the AST can't distinguish the function declaration in these situations without the need for more processing

membphis commented 3 years ago

@tammela Many thx for your remind I'll try to find a better way