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

Multiple runs with different output #261

Closed
qbedard opened this issue Sep 8, 2021 · 2 comments · Fixed by #267
Closed

Multiple runs with different output #261

qbedard opened this issue Sep 8, 2021 · 2 comments · Fixed by #267
Labels
bug Something isn't working

Comments

@qbedard
Copy link
Contributor

qbedard commented Sep 8, 2021

Running multiple times on the same file without otherwise changing the file sometimes yields different results.

  • Version: 0.10.1
  • Platform: macOS Big Sur 11.5.2

Config at /Users/tim/stylua.toml:

column_width = 88

Lua file before (at `/Users/tim/example.lua):

local thisisathing = {this_is_one = "one", this_is_two = "two", this_is_three = "three"}

First run:

stylua -v example.lua

config: starting config search from /Users/tim - recurisvely searching parents: false
config: Config {
    column_width: 88,
    line_endings: Unix,
    indent_type: Tabs,
    indent_width: 4,
    quote_style: AutoPreferDouble,
    no_call_parentheses: false,
}
creating a pool with 8 threads
formatted example.lua in 1.121355ms
local thisisathing =
	{
		this_is_one = "one",
		this_is_two = "two",
		this_is_three = "three",
	}

Second run:

stylua -v example.lua

config: starting config search from /Users/tim - recurisvely searching parents: false
config: Config {
    column_width: 88,
    line_endings: Unix,
    indent_type: Tabs,
    indent_width: 4,
    quote_style: AutoPreferDouble,
    no_call_parentheses: false,
}
creating a pool with 8 threads
formatted example.lua in 1.314414ms
local thisisathing = {
	this_is_one = "one",
	this_is_two = "two",
	this_is_three = "three",
}

Expected:

The output of the second run should be the result after the first run, and subsequent runs should result in no changes.

@zovits
Copy link

zovits commented Sep 9, 2021

Running into this issue where subsequent runs give different results, and it gets caught in a loop where it bounces back and forth between the two states, causing my Github Action check to always fail since StyLua always wants the other.

State 0:

local targetCash = { id = "Ben Franklin" }
local targetName = "StyLua_Bug"

local function findMoney()
	for _, existingObject in pairs(workspace:GetChildren()) do
		if
			existingObject:GetAttribute("MoneyID") == targetCash.id
			and existingObject.Name == targetName .. ".money"
		then
			break
		end
	end
end

State 1:

local targetCash = { id = "Ben Franklin" }
local targetName = "StyLua_Bug"

local function findMoney()
	for _, existingObject in pairs(workspace:GetChildren()) do
		if
			existingObject:GetAttribute("MoneyID") == targetCash.id and existingObject.Name
				== targetName .. ".money"
		then
			break
		end
	end
end

If you take either of these and run StyLua, it will flip to the other. Running many times just flips back and forth, never ending.

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

State 1:

local targetCash = { id = "Ben Franklin" }

local targetName = "StyLua_Bug"



local function findMoney()

	for _, existingObject in pairs(workspace:GetChildren()) do

		if

			existingObject:GetAttribute("MoneyID") == targetCash.id and existingObject.Name

				== targetName .. ".money"

		then

			break

		end

	end

end

Seems to be the same (incorrect) formatting issue as #257, except in this case it's even worse as it keeps flipping between the two.

In all these cases, I assume it's very near the column width boundary - this probably means we are incorrectly calculating the width budget available on a line somewhere, just need to find out where.

JohnnyMorganz added a commit that referenced this issue Sep 14, 2021
We did not look at the RHS precedence level when determining to hang an expression.
This led to assymetric formatting, which doesn't look as nice.

This also led to an unstable formatting issue in #261
JohnnyMorganz added a commit that referenced this issue Sep 14, 2021
* Add unstable formatting test case

* Fix unstable formatting of singleline table

Caused by singleline table just hitting column width
initially with no spaces between braces

* Fix misformatting due to RHS binop precedence of expression

We did not look at the RHS precedence level when determining to hang an expression.
This led to assymetric formatting, which doesn't look as nice.

This also led to an unstable formatting issue in #261
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