-
Notifications
You must be signed in to change notification settings - Fork 43
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
feat: add flag to print resolved config #179
feat: add flag to print resolved config #179
Conversation
Thank you very much for opening a PR! This is an awesome feature idea, it'll be a big help. I apologize in advance that I'm going to suggest a complete change to the approach. This is mostly due to reasoning for structuring the code certain ways that you couldn't have known going in because I don't document it. I don't get a lot of feature PRs, so I appreciate your work! 😄 There are a couple reasons I'd prefer not to do it this way:
Here's my alternative approach: Add a new method to the Implement the func (f *BasicFormatter) ConfigMap() (map[string]any, error) {
configMap := map[string]any{}
err := mapstructure.Decode(f.Config, &configMap)
if err != nil {
return nil, err
}
configMap["type"] = BasicFormatterType
return configMap, err
} This way the formatter can maintain ownership of that Upon printing configuration, use the same On each of these maps, you can use The only downside of going to a map and then yaml is that the order gets a bit whacky. For this reason, I think the nicest output result would be: commandConfig := map[string]any{}
err = mapstructure.Decode(c.Config, &commandConfig)
if err != nil {
return err
}
delete(commandConfig, "formatter")
out, err := yaml.Marshal(commandConfig)
if err != nil {
return err
}
fmt.Print(string(out))
formatterConfigMap, err := formatter.ConfigMap()
if err != nil {
return err
}
out, err = yaml.Marshal(map[string]any{
"formatter": formatterConfigMap,
})
if err != nil {
return err
}
fmt.Print(string(out)) This results in this kind of output:
Finally, I would recommend changing For integration tests, I like the integration test you've added. I'd recommend adding another one that uses a If this is too much of a change, I would understand if you decide to close the PR and I can implement this for v0.13.0 instead. Up to you. Thanks again for the PR! |
google#179 (comment) * Prefer basic formatter having mapstructure rather than yaml tag in command * Rename resolved with print * Add integration tests for loading config files
google#179 (comment) * Prefer basic formatter having mapstructure rather than yaml tag in command * Rename resolved with print * Add integration tests for loading config files
c228b70
to
2d4315e
Compare
Thank you for the polite review and suggestions. 🙏 Especially, this is my first experience using |
Yes that's correct. An assumption I've never actually documented, but throughout the project I essentially always use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for applying the suggestions! Looks great, just one minor comment and this will be good to merge.
@@ -1,5 +1,6 @@ | |||
# Sometimes use these for testing | |||
.yamlfmt | |||
!integrationtest/**/.yamlfmt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I didn't think of that
@@ -0,0 +1,2 @@ | |||
a: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These yaml files can be removed for these -print_conf
tests. They should be able to operate without them.
Ah okay, forgot about that git quirk. Could you fill any folders with no files with a file called |
Thank you for quick reviews, I have updated! |
🙏 Thank you! |
Suggestion
Make it possible yamlfmt could provide an overview of the final config it interprets from the config files and CLI flags.
Background
I have recently used several different versions of yamlfmt for projects with different configurations. When the behavior was different from what I expected, I was confused about whether it was due to the version of yamlfmt or a mistake in my own settings. I think it's also because the yamlfmt doesn't throw an error even when given formatter options it doesn't accept, and the number of available config file name patterns has increased from recent versions.
To my knowledge, such a feature is not uncommon in configurable linters and formatters.
dprint output-resolved-config
tsc --showConfig
eslint --print-config
rubocop --show-cops