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

Suggestion: Allow same-line for assignment

Open jgranick opened this issue 6 years ago • 4 comments

Describe the Feature
We use settings to put braces on the next line, but I think it would be nice to have a setting to allow assignment brackets to be on the same.

For example:

class Main
{
    static function main()
    {
        var object = {
            field: 100
        };
    }
}

The current output seems a little strange?

class Main
{
    static function main()
    {
        var object =
            {
                field: 100
            };
    }
}

Perhaps there should be an option to not indent the assignment as well?

jgranick avatar Feb 14 '19 22:02 jgranick

The current output seems a little strange?

I agree, I wonder if that's just a bug / related to https://github.com/HaxeCheckstyle/haxe-formatter/issues/315.

Perhaps there should be an option to not indent the assignment as well?

Should probably be the default behavior, actually.

Gama11 avatar Feb 14 '19 22:02 Gama11

Here's a slightly different version of this for the unit tests:

class Main
{
	static function main()
	{
		return [
			{
				"name": "Lime",
				"type": "lime",
				"request": "launch"
			}];
	}
}
{
	"lineEnds": {
		"leftCurly": "both"
	}
}

Gama11 avatar Mar 18 '19 18:03 Gama11

I have an additional use case for this request: anonymous types

function polarToRec(r:Float, theta:Float):{
    x:Float,
    y:Float
}
{
  return ...
}

Typedefs too, although this could be considered as similar to an assignment

typedef Point = {
    x:Float,
    y:Float
}

gene-pavlovsky avatar Mar 21 '19 10:03 gene-pavlovsky

@jgranick The 1.7.0 release addresses half of this issue, you can now achieve this formatting:

class Main
{
    static function main()
    {
        var object = {
            field: 100
        };
    }
}

With the following config:

{
	"lineEnds": {
		"leftCurly": "both",
		"objectLiteralCurly": {
			"leftCurly": "after"
		}
	}
}

Gama11 avatar May 17 '19 00:05 Gama11