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

Declaring field parse order #291

Closed
rmfitzpatrick opened this issue Jan 18, 2023 · 4 comments
Closed

Declaring field parse order #291

rmfitzpatrick opened this issue Jan 18, 2023 · 4 comments

Comments

@rmfitzpatrick
Copy link

This (extremely helpful) library may be currently incompatible with projects enforcing fieldalignment in the likely chance their ast fields aren't defined in an already optimal order. Is there an existing option or feature that allows using something like reflect's Type.FieldByName()?

type AST struct {
  Two string `@Ident`
  One string `@Ident`
}

func (a AST) ParseOrder() []string {
  return []string{"One", "Two"}
}
@alecthomas
Copy link
Owner

There is no option for this, no.

While I appreciate the use case, it's pretty niche, and reordering the fields would make understanding the grammar extremely difficult.

@rmfitzpatrick
Copy link
Author

I've not had immediate luck in finding how to disable the analyzer for a given package/file and understand the potentially poor experience with such a helper method. Another thought would be to allow defining a parser from an ebnf grammar where terminals are field names to not require struct tags at all, but that's probably much more complicated.

@alecthomas
Copy link
Owner

I use golangci-lint which I believe includes this. It supports a //nolint:XXX directive

@rmfitzpatrick
Copy link
Author

Thanks, though I'm referring to its cmd invocation fieldalignment -fix and will just have to enumerate paths rather than ./....

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