Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Alignment of multiline operator expressions #188

Open
4lph4-Ph4un opened this issue Sep 30, 2024 · 2 comments
Open

Feature Request: Alignment of multiline operator expressions #188

4lph4-Ph4un opened this issue Sep 30, 2024 · 2 comments

Comments

@4lph4-Ph4un
Copy link

4lph4-Ph4un commented Sep 30, 2024

Sorry about spamming feature request lately! But I'm happy I've found a Lua-formatter/style checker that works for most of my needs!
Here's something I do with my code often, and I wonder if this could be added as some kind of rule. I tend to align multiline statements that start with operators and here's the different usecases I do them:

Alignment in if-statements:

-- NOTE: Alignment of the first line in if statements that have multilines that begin with an operator.
-- The first expression is aligned with the first non-operator on the next line and so forth.
-- the operators are aligned too. note that "then" closes the if on multiline statements and is on it's first line
-- aligned with the "if":
if   true  and true
  or false and false
  or true
then
  print("Yay!")
end

-- NOTE: A case where one of the preceding operators is longer than others:
if    true  and true
  or  false and false
  not true
then
  print("Yay!")
end

Aligment on multine expressions inside brackets (and for example in a return).

-- NOTE: The first expression is aligned according to the first non-operator below it and so forth:
function foo()
  return (
      100
    * 123
    + 456
  )
end

And lastly in assigment where there's a hanging "="-sign:

package.path
  =  "./?.lua;./?/init.lua;"
  .. "./src/?.lua;./src/?/init.lua;"
  .. "./lib/?.lua;./lib/?/init.lua;"
  .. "./spec/?.lua;./spec/?/init.lua;"
  .. package.path
  
-- NOTE: Alternatively this:
package.path = 
     "./?.lua;./?/init.lua;"
  .. "./src/?.lua;./src/?/init.lua;"
  .. "./lib/?.lua;./lib/?/init.lua;"
  .. "./spec/?.lua;./spec/?/init.lua;"
  .. package.path

I understand if these are out of the scope for this stylechecker/formatter, but I tend to use these in a lot of my codebases and would really enjoy having them covered, but I understand if there are some tricky cornercases that make these difficult to implement!

@CppCXY
Copy link
Owner

CppCXY commented Sep 30, 2024

I'm busy implementing language server, and the next week is our holiday, so it may be a long time before I do

@4lph4-Ph4un
Copy link
Author

Absolutely no problem! If it's on the table at some point and possible to implement, it's still great even if later!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants