Skip to content

Tag alignment/width doesn't respect comments  #108

@adriangoransson

Description

@adriangoransson

It seems that the inline spacing/width of tags does not take comments into account.

In the example below, we see that the sql tag is placed 42 characters before the string start. Which looks strange because the fields are not aligned by their name or types due to the comment.

type Example struct {
	A string `json:"some-really-really-long-identifier" sql:"-"`
	// SomeOtherField
	SomeOtherField []int `                                          sql:"-"`
}

If we were to remove the comment, everything looks nicely aligned.

type Example struct {
	A              string `json:"some-really-really-long-identifier" sql:"-"`
	SomeOtherField []int  `                                          sql:"-"`
}

Likewise if we inserted a blank line before the comment:

type Example struct {
	A string `json:"some-really-really-long-identifier" sql:"-"`

	// SomeOtherField
	SomeOtherField []int `sql:"-"`
}

This is the desired effect:

type Example struct {
	A string `json:"some-really-really-long-identifier" sql:"-"`
	// SomeOtherField
	SomeOtherField []int `sql:"-"`
}

Since names and types are only aligned within groups of non-comment lines I think tags should respect that as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions