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

Type interfaces always format to a single line no matter the length. #226

Closed
howmanysmall opened this issue Jul 12, 2021 · 5 comments · Fixed by #244
Closed

Type interfaces always format to a single line no matter the length. #226

howmanysmall opened this issue Jul 12, 2021 · 5 comments · Fixed by #244
Labels
bug Something isn't working

Comments

@howmanysmall
Copy link

howmanysmall commented Jul 12, 2021

This was nothing like the behavior before. No matter the length of the contents of a type interface, it always shrinks down to a single line.

export type Sprite = {
	Image: string,
	ImageRectOffset: Vector2,
	ImageRectSize: Vector2,
}

-- becomes:
export type Sprite = { Image: string, ImageRectOffset: Vector2, ImageRectSize: Vector2 }
export type Sprite = {
	Image: string,
	ImageRectOffset: Vector2,
	ImageRectSize: Vector2,
	ImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSize: Vector2,
}

-- becomes:
export type Sprite = { Image: string, ImageRectOffset: Vector2, ImageRectSize: Vector2, ImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSizeImageRectSize: Vector2 }

This completely destroys readability if the interface is super long like the exaggerated example shown before.

@JohnnyMorganz JohnnyMorganz added the bug Something isn't working label Jul 13, 2021
@JohnnyMorganz
Copy link
Owner

Strange how this wasn't picked up in a test. I'll take a look tonight and see

@JohnnyMorganz
Copy link
Owner

I can't reproduce the issue you are describing.
Could there be anything else affecting this? (e.g. other code, a specific stylua.toml configuration etc.)

@howmanysmall
Copy link
Author

It might be my config's column_width = 248347834343, but it doesn't do it for tables, so i'm not sure why it'd do it for types

@JohnnyMorganz
Copy link
Owner

It might be my config's column_width = 248347834343, but it doesn't do it for tables, so i'm not sure why it'd do it for types

That's definitely the issue here!

The difference between tables and types (currently) is that in tables we implement an extra heuristic where if there is a newline between the opening brace and the first field, we will always expand multi line, regardless of column width. https://prettier.io/docs/en/rationale.html#multi-line-objects may provide a better explanation, but this is what we do too.

I could also migrate this to table types as well, so that they will always remain multi line. The only thing I don't like about it is the formatting reversibility, but that's also an issue for tables and it may make sense to make the formatting consistent between the two.

@matthargett
Copy link

I very much like it using the carriage-return after the first opening context token ('{' in the table case) being used so it always formats multi-line (even if not bumping against the column budget).

if that logic was more consistent (re-used code, even) across if/while/{/(, in both Lua and in types, that would be fantastic. The fact it's not consistent, and needs deep explanation when someone notices this discrepancies, is definitely an impediment to broader adoption in the teams I work with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants