haxe-formatter icon indicating copy to clipboard operation
haxe-formatter copied to clipboard

Unexpected array wrapping behavior

Open Gama11 opened this issue 7 years ago • 3 comments

Array wrapping behavior is a bit counter-intuitive here. With a relatively short array literal, the formatting is kept as-is:

class TestMain {
	static function main() {
		UTest.run([
			new ArrayHelperTest(),
			new IdentifierHelperTest(),
			new ImportHelperTest(),
			new PathHelperTest(),
			new PositionHelperTest(),
		]);
	}
}

However, with a few more:

class TestMain {
	static function main() {
		UTest.run([
			new ArrayHelperTest(),
			new IdentifierHelperTest(),
			new ImportHelperTest(),
			new PathHelperTest(),
			new PositionHelperTest(),
			new RangeHelperTest(),
			new TypeHelperTest(),  
			new RenameResolverTest(), 
			new HelperTest(), 
			new TokenTreeTest()
		]);
	}
}

The code turns into this - I guess it switches to a different array wrapping mode:

class TestMain {
	static function main() {
		UTest.run([
			new ArrayHelperTest(), new IdentifierHelperTest(), new ImportHelperTest(), new PathHelperTest(), new PositionHelperTest(), new RangeHelperTest(),
			new TypeHelperTest(), new RenameResolverTest(), new HelperTest(), new TokenTreeTest()
		]);
	}
}

Gama11 avatar Feb 10 '19 12:02 Gama11

yep, when there is 10 or more items it will switch to fillLine instead of onePerLine....

At some point fillLine has to happen, because if you have dozens of items, then one per line would make for a very long file. I'm open for discussion if it should start at 10, we might even include additional conditions like item or line length.

AlexHaxe avatar Feb 10 '19 16:02 AlexHaxe

At some point fillLine has to happen, because if you have dozens of items, then one per line would make for a very long file.

Does it? Not sure I'd ever want it to happen in this case. Checking for item length might make the most sense, since the other wrapping mode is mostly good for int / float arrays, where the items are very short.

Gama11 avatar Feb 10 '19 16:02 Gama11

My 2 cents: I agree with @Gama11, I don't think I ever wanted it to become fillLine. I prefer slightly longer files that are easier to visually parse and are easier to edit.

zommerfelds avatar Jul 22 '21 06:07 zommerfelds