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

feat: allow using raw docstring for type docs #28

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ProcessorConfig struct {
IgnoreTypes []string `json:"ignoreTypes"`
IgnoreFields []string `json:"ignoreFields"`
IgnoreGroupVersions []string `json:"ignoreGroupVersions"`
UseRawDocstring bool `json:"useRawDocstring"`
}

type RenderConfig struct {
Expand Down
2 changes: 2 additions & 0 deletions processor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func compileConfig(conf *config.Config) (cc *compiledConfig, err error) {
ignoreTypes: make([]*regexp.Regexp, len(conf.Processor.IgnoreTypes)),
ignoreFields: make([]*regexp.Regexp, len(conf.Processor.IgnoreFields)),
ignoreGroupVersions: make([]*regexp.Regexp, len(conf.Processor.IgnoreGroupVersions)),
useRawDocstring: conf.Processor.UseRawDocstring,
}

for i, t := range conf.Processor.IgnoreTypes {
Expand Down Expand Up @@ -59,6 +60,7 @@ type compiledConfig struct {
ignoreTypes []*regexp.Regexp
ignoreFields []*regexp.Regexp
ignoreGroupVersions []*regexp.Regexp
useRawDocstring bool
}

func (cc *compiledConfig) shouldIgnoreGroupVersion(gv string) bool {
Expand Down
5 changes: 5 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ func (p *processor) processType(pkg *loader.Package, info *markers.TypeInfo, dep
Doc: info.Doc,
}

if p.useRawDocstring && info.RawDecl != nil {
// use raw docstring to support multi-line and indent preservation
typeDef.Doc = strings.TrimSuffix(info.RawDecl.Doc.Text(), "\n")
}

// if the field list is non-empty, this is a struct
if len(info.Fields) > 0 {
typeDef.Kind = types.StructKind
Expand Down