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

Tag alignment/width doesn't respect comments #108

Open
adriangoransson opened this issue Sep 15, 2023 · 1 comment
Open

Tag alignment/width doesn't respect comments #108

adriangoransson opened this issue Sep 15, 2023 · 1 comment

Comments

@adriangoransson
Copy link

adriangoransson commented Sep 15, 2023

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.

@j-krose
Copy link

j-krose commented Sep 21, 2024

Also seeing this in my code, causing a conflict between golines and tagalign linter.

Applying golines to:

type ConnectionConfig struct {
	Host               string `env:"NEO4J_HOST,notEmpty"`
	BoltPort           int    `env:"NEO4J_BOLT_PORT,notEmpty"`
	SuperadminPassword string `env:"NEO4J_SUPERADMIN_PASSWORD,notEmpty"`
	// Should only be used for development environments; makes the system log sensitive information
	UseVerboseNeo4jLogging bool `env:"VERBOSE_NEO4J_LOGGING" envDefault:"false"`
}

yields:

type ConnectionConfig struct {
	Host               string `env:"NEO4J_HOST,notEmpty"`
	BoltPort           int    `env:"NEO4J_BOLT_PORT,notEmpty"`
	SuperadminPassword string `env:"NEO4J_SUPERADMIN_PASSWORD,notEmpty"`
	// Should only be used for development environments; makes the system log sensitive information
	UseVerboseNeo4jLogging bool `env:"VERBOSE_NEO4J_LOGGING"              envDefault:"false"`
}

which breaks the linter with Error: .../config.go:8:30: tag is not aligned , should be: env:"VERBOSE_NEO4J_LOGGING" envDefault:"false" (tagalign)


with a newline added golines produces:

type ConnectionConfig struct {
	Host               string `env:"NEO4J_HOST,notEmpty"`
	BoltPort           int    `env:"NEO4J_BOLT_PORT,notEmpty"`
	SuperadminPassword string `env:"NEO4J_SUPERADMIN_PASSWORD,notEmpty"`

	// Should only be used for development environments; makes the system log sensitive information
	UseVerboseNeo4jLogging bool `env:"VERBOSE_NEO4J_LOGGING" envDefault:"false"`
}

which agrees with the linter

with comment removed golines produces:

type ConnectionConfig struct {
	Host                   string `env:"NEO4J_HOST,notEmpty"`
	BoltPort               int    `env:"NEO4J_BOLT_PORT,notEmpty"`
	SuperadminPassword     string `env:"NEO4J_SUPERADMIN_PASSWORD,notEmpty"`
	UseVerboseNeo4jLogging bool   `env:"VERBOSE_NEO4J_LOGGING"              envDefault:"false"`
}

which also agrees with the linter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants