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

chore: Refactoring attr doc gen to use Go templates #274

Merged
merged 5 commits into from
Jan 11, 2025

Conversation

traut
Copy link
Member

@traut traut commented Jan 8, 2025

No description provided.

@traut traut requested review from Andrew-Morozko and dobarx and removed request for Andrew-Morozko January 8, 2025 19:00
Copy link
Contributor

@dobarx dobarx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍
Just few minor issues with Go idioms but you don't necessarily need to fix. 😄

@@ -35,9 +36,9 @@ func makeHTTPDataSource(version string) *plugin.DataSource {
Header: dataspec.HeadersSpec{
dataspec.ExactMatcher{"basic_auth"},
},
Doc: `
Doc: u.Dedent(`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's good idea to require correctness of Doc formatting at each plugin Spec.
"Dedent" it at doc generator or where you want to print this Doc string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rolled it back, looked at the code, thought about it more, and re-applied the change.

It makes sense to have clean data from the start: it removes the expectation that some code down the stream will clean the value up and the uncertainty about what exactly the clean-up does. There are 2 separate places where this clean-up happens at the moment. If we add another way to use the Doc value, we'll need to copy-paste it into the 3rd place, or abstract the code away into the attr schema struct. Or we can avoid all of that by passing a clean string in the first place with minimum complexity.

Moreover, we avoid uncertainty on how the text would be mutated during formatting, giving control to the plugin author, instead of doing it our job to clean messy doc string (and it might be messy in all different ways) before formatting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to roll it in for now and revisit later!

@@ -68,71 +67,47 @@ func MemoizedKeys[M ~map[string]V, V any](m *M) func() string {
})
}

const defaultTabSize = 4
// Strip common margin from the beginnings of the lines
func Dedent(text string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid adding new functions to util package. In general packages like util common helpers are anti-pattern in Go. You should add this logic where you really need it (docgen maybe?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted! In this case, dedent should really be part of the stdlib :D and we're using it in 2 separate places already, so I suspect it will stay in utils

@traut traut merged commit aa0ed0d into rss-fixes Jan 11, 2025
35 of 37 checks passed
@traut traut deleted the doc-gen-simplification branch January 11, 2025 14:11
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

Successfully merging this pull request may close these issues.

2 participants