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

Ternary operator: option to add new lines before ? and : #595

Open
Zielak opened this issue Jun 4, 2020 · 0 comments
Open

Ternary operator: option to add new lines before ? and : #595

Zielak opened this issue Jun 4, 2020 · 0 comments
Labels
enhancement New feature or request wrapping Incorrect or undesirable wrapping

Comments

@Zielak
Copy link

Zielak commented Jun 4, 2020

Describe the Feature

Given below config:

{
	"wrapping": {
		"maxLineLength": "100"
	}
}

And a very long one-liner:

class Main {
	public function foo(param1:Int, someObject:Dynamic) {
		var longOptionValue = someObject.longFlagName == true ? longOptionValue1 + somethingElse : longOptionValue2 + anotherThing;
	}
}

Formatter currently outputs:

class Main {
	public function foo(param1:Int, someObject:Dynamic) {
		var longOptionValue = someObject.longFlagName == true ? longOptionValue1
			+ somethingElse : longOptionValue2
			+ anotherThing;
	}
}

Expressions on both "true" and "false" sides are broken apart across two lines. It would be easier to read if each operand (condition, expression1, expression2) would be placed in their own lines, like below:

(Optional) Sample of desired output

class Main {
	public function foo(param1:Int, someObject:Dynamic) {
		var longOptionValue = someObject.longFlagName == true
			? longOptionValue1 + somethingElse
			: longOptionValue2 + anotherThing;
	}
}

The above is what I currently desire 🙇 but I imagine someone else also wanting to have question mark and semicolon kept at the end of lines instead:

class Main {
	public function foo(param1:Int, someObject:Dynamic) {
		var longOptionValue = someObject.longFlagName == true ?
			longOptionValue1 + somethingElse :
			longOptionValue2 + anotherThing;
	}
}

Edit: Just found another example - condition may also break across lines:

// Source
class Main {
	function test(){
		var file = Reflect.hasField(imageData, 'file') ? Reflect.field(imageData, 'file') : 'img/missing.jpg';
	}
}
// Becomes:
class Main {
	function test(){
		var file = Reflect.hasField(imageData,
			'file') ? Reflect.field(imageData, 'file') : 'img/missing.jpg';
	}
}
@AlexHaxe AlexHaxe added enhancement New feature or request wrapping Incorrect or undesirable wrapping labels Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wrapping Incorrect or undesirable wrapping
Projects
None yet
Development

No branches or pull requests

2 participants