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

Linefeed removed after multi line comments in composite literals #170

Closed
cckim opened this issue Nov 19, 2021 · 1 comment
Closed

Linefeed removed after multi line comments in composite literals #170

cckim opened this issue Nov 19, 2021 · 1 comment
Labels
good first issue Good for newcomers
Milestone

Comments

@cckim
Copy link

cckim commented Nov 19, 2021

Composite literals have blank lines removed, but it seems to treat the trailing */ of a multi-line comment as a blank line.

If we add the following testcase to composite-literals-leading-lines

var _ = map[string]string{
        /*
        */

        "foo": "bar",
}

formatting produces:

var _ = map[string]string{
        /*
        */ "foo": "bar",
}

This seems like an unintended consequence of f2d9f32

Also, this creates a conflict with gofmt v0.1.7 which wants (removed blank space):

var _ = map[string]string{
        /*
        */"foo": "bar",
}
@mvdan
Copy link
Owner

mvdan commented Nov 20, 2021

Thanks - this seems to be one of the cases where we forgot to check if there are any comments in those "empty" lines we're removing. If there are comments, we don't want to remove their newlines.

Leaving as "good first issue" for a couple of days to see if someone wants to pick it up :)

@mvdan mvdan added the good first issue Good for newcomers label Nov 20, 2021
@mvdan mvdan added this to the v0.2.1 milestone Dec 2, 2021
mvdan added a commit that referenced this issue Dec 4, 2021
For an input such as:

	var _ = map[string]string{
		/*
			joint comment
		*/
		"foo": "bar",
	}

We would incorrectly join the comment with the first element:

	var _ = map[string]string{
		/*
			joint comment
		*/ "foo": "bar",
	}

Just like in other parts of the codebase,
consider the first comment's position if it exists.

Fixes #170.
@mvdan mvdan closed this as completed in 872763c Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants