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

Remove extra indentation of parentheses, similar to tables/function calls #274

Closed
archiif opened this issue Oct 7, 2021 · 3 comments · Fixed by #427
Closed

Remove extra indentation of parentheses, similar to tables/function calls #274

archiif opened this issue Oct 7, 2021 · 3 comments · Fixed by #427
Labels
enhancement New feature or request

Comments

@archiif
Copy link

archiif commented Oct 7, 2021

Stuff enclosed in parentheses seems to have an inconsistent indentation style.
Instead of looking like this:

local tbl = {
    key = long_variable_name,
    key = long_variable_name,
    key = long_variable_name,
    key = long_variable_name,
}
function_call(
    long_variable_name,
    long_variable_name,
    long_variable_name,
    long_variable_name,
)
local test = (
        long_variable_name
        + long_variable_name
        + long_variable_name
        + long_variable_name
    )

It should look more like this:

local tbl = {
    key = long_variable_name,
    key = long_variable_name,
    key = long_variable_name,
    key = long_variable_name,
}
function_call(
    long_variable_name,
    long_variable_name,
    long_variable_name,
    long_variable_name,
)
local test = (
    long_variable_name
    + long_variable_name
    + long_variable_name
    + long_variable_name
)
@JohnnyMorganz
Copy link
Owner

Hm, I can't remember exactly why parentheses were indented a level further compared to others - I'll need to look into that.

I do agree (if I can't find a concrete reason) that it's probably better to be consistent here. I'm a bit reluctant though because I imagine this is going to lead to a lot of diff changes

@JohnnyMorganz
Copy link
Owner

Ah, I figured out why its indented one level further, but that doesn't mean we can't change it:

Basically at an assignment, what we are doing here is hanging the assigned expression. In this case, the expression is a set of additions wrapped around in parentheses.
We add a single further level of indentation because we do this for all expressions, e.g.:

local expr_result = 1
    + 2
    + 3
    + 4
    + 5 --a comment
    + 6
    + 6
    + 8

local instance = someReallyLongConditionExtremelyLongSoLongYourMindWillMelt
        and someReallyLongCondition
        and someOtherReallyLongCondition
    or somethingElse

If we remove this extra level of indentation, in the above two cases it will turn into

local expr_result = 1
+ 2
+ 3
+ 4
+ 5 --a comment
+ 6
+ 6
+ 8

local instance = someReallyLongConditionExtremelyLongSoLongYourMindWillMelt
    and someReallyLongCondition
    and someOtherReallyLongCondition
or somethingElse

which doesn't look that nice.
Parentheses take a single increase in indentation the same as above, as its handled in the same "hang expression".
The reason it gets another indentation is because we then expand out the inner expression of the parentheses - this adds an extra indent level.

We could special case parentheses to not hang here. The only issue I have with it is its a large diff change for a minor style change - need to weigh up the pros and cons

@JohnnyMorganz JohnnyMorganz added enhancement New feature or request rfc/in discussion This issue is currently in discussion, comments are welcome! labels Dec 11, 2021
@JohnnyMorganz JohnnyMorganz changed the title More consistent formatting of parentheses? Remove extra indentation of parentheses, similar to tables/function calls Dec 11, 2021
@JohnnyMorganz
Copy link
Owner

Going to plan to fix this inconsistency having thought about it more - it definitely looks much better when everything is aligned the same way

@JohnnyMorganz JohnnyMorganz removed the rfc/in discussion This issue is currently in discussion, comments are welcome! label Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants