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

Does not consistently style; dependent on the original line #287

Closed
RobloxJC opened this issue Nov 4, 2021 · 5 comments · Fixed by #288
Closed

Does not consistently style; dependent on the original line #287

RobloxJC opened this issue Nov 4, 2021 · 5 comments · Fixed by #288
Labels
bug Something isn't working

Comments

@RobloxJC
Copy link

RobloxJC commented Nov 4, 2021

local foo = {
	getTileProps = function(tile)
		local result = {
			adId = not GetFFlagLuaAppAddUniverseIdToGameImpressions() and (tile.props.entry and tile.props.entry.adId)
				or nil,
		}
	end,
}

This code does not get consistently styled. Specifically, the "adId" line will just have the "or nil" on a second line if you have it all one line to start.

However, if you break up the "adId" statement first, and then style, you'll get 3 lines:

local foo = {
	getTileProps = function(tile)
		local result = {
			adId = not GetFFlagLuaAppAddUniverseIdToGameImpressions()
					and (tile.props.entry and tile.props.entry.adId)
				or nil,
		}
	end,
}
@JohnnyMorganz JohnnyMorganz added the bug Something isn't working label Nov 4, 2021
@JohnnyMorganz
Copy link
Owner

I can't reproduce this, when you mean all on one line its something like this, right?:

local foo = {
	getTileProps = function(tile)
		local result = {
			adId = not GetFFlagLuaAppAddUniverseIdToGameImpressions() and (tile.props.entry and tile.props.entry.adId) or nil,
		}
	end,
}

This immediately gets transformed into the 3 line formatting when I run it

@RobloxJC
Copy link
Author

RobloxJC commented Nov 4, 2021

Yes, exactly.

local foo = {
	getTileProps = function(tile)
		local result = {
			adId = not GetFFlagLuaAppAddUniverseIdToGameImpressions() and (tile.props.entry and tile.props.entry.adId) or nil,
		}
	end,
}

gets formatted as

local foo = {
	getTileProps = function(tile)
		local result = {
			adId = not GetFFlagLuaAppAddUniverseIdToGameImpressions() and (tile.props.entry and tile.props.entry.adId)
				or nil,
		}
	end,
}

for me and another colleague. We're using 1.2.0 of StyLua, and using it through the VS Code extension and formatting on save.

What's interesting is that if I hit save again, I'll get the 3 line version.

I noticed the VS Code extension is a lot older than the binaries, so I tried downloading v0.10.1 binary (Windows won't let me get v0.11.0; it reports a virus) and calling it manually. It has the same issue, where if I run it manually with the file with all on one line, it gives me the 2 line version. But if I run it again, it doesn't change it. However, if I change the spacing a bit and run it, I'll get the 3 line version.

Is it possible it's fixed in v0.11.0?

@JohnnyMorganz
Copy link
Owner

I just tried it with v0.10.1 binary, and I get the 2 line formatting as you mentioned, but if I run it again it doesn't change to 3 line, it still stays at 2 line.

But, if I add a few spaces in between and (tile.props, it does format as 3 lines. And then it stays at 3 lines as you mention - so it seems to be an issue with spacing in the original input. I can also reproduce this in v0.11.0 though, except only if the spaces are added before the and, not after. So it is a bug in these versions.


Also, just to point out: The extension version (1.2.0) is independent from the binary version, and should normally automatically update to latest. You can also run the command StyLua: Reinstall StyLua from the VSCode command palette to update aswell.

@JohnnyMorganz
Copy link
Owner

Current master changes the behaviour though and now always formats these on 3 lines, so the inconsistency should no longer be an issue there.

Technically, 2 lines is under the column width of 120, so latest should really be formatting it onto 2 lines. It doesn't really seem like a big issue for me though, so unless you think it should be on 2 lines I'll leave it for now.

@JohnnyMorganz
Copy link
Owner

Actually, if I make the first function call slightly smaller, and do something like this:

local foo = {
	getTileProps = function(tile)
		local result = {
			adId = not GetFFlagLuaAppAddUniverseIdToGameImpress()         and           (tile.props.entry and tile.props.entry.adId)
				or nil,
		}
	end,
}

its gets formatted onto 3 lines, then second pass gets formatted onto 2. So this is still a valid bug.

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.

2 participants