Centralizing comment / description cleanup in chromedp-gen
This commit is contained in:
parent
df58ab5964
commit
fd310a9b84
|
@ -57,7 +57,7 @@ func (d *Domain) String() string {
|
||||||
|
|
||||||
// GetDescription returns the formatted description of the domain.
|
// GetDescription returns the formatted description of the domain.
|
||||||
func (d *Domain) GetDescription() string {
|
func (d *Domain) GetDescription() string {
|
||||||
return CodeRE.ReplaceAllString(d.Description, "")
|
return CleanDesc(d.Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PackageName returns the Go package name to use for the domain.
|
// PackageName returns the Go package name to use for the domain.
|
||||||
|
@ -216,7 +216,6 @@ func (t Type) IDorName() string {
|
||||||
func (t Type) String() string {
|
func (t Type) String() string {
|
||||||
desc := t.GetDescription()
|
desc := t.GetDescription()
|
||||||
if desc != "" {
|
if desc != "" {
|
||||||
desc, _ = MisspellReplacer.Replace(desc)
|
|
||||||
desc = " - " + desc
|
desc = " - " + desc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +224,7 @@ func (t Type) String() string {
|
||||||
|
|
||||||
// GetDescription returns the cleaned description for the type.
|
// GetDescription returns the cleaned description for the type.
|
||||||
func (t *Type) GetDescription() string {
|
func (t *Type) GetDescription() string {
|
||||||
return CodeRE.ReplaceAllString(t.Description, "")
|
return CleanDesc(t.Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnumValues returns enum values for the type.
|
// EnumValues returns enum values for the type.
|
||||||
|
|
|
@ -19,12 +19,28 @@ const (
|
||||||
Base64EncodedDescriptionPrefix = "Base64-encoded"
|
Base64EncodedDescriptionPrefix = "Base64-encoded"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MisspellReplacer is the misspelling replacer
|
// misspellReplacer is the misspelling replacer
|
||||||
var MisspellReplacer *misspell.Replacer
|
var misspellReplacer *misspell.Replacer
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
MisspellReplacer = misspell.New()
|
misspellReplacer = misspell.New()
|
||||||
MisspellReplacer.Compile()
|
misspellReplacer.Compile()
|
||||||
|
}
|
||||||
|
|
||||||
|
var badHTMLReplacer = strings.NewReplacer(
|
||||||
|
"<", "<",
|
||||||
|
">", ">",
|
||||||
|
">", ">",
|
||||||
|
)
|
||||||
|
|
||||||
|
// codeRE is a regexp to match <code> and </code> tags.
|
||||||
|
var codeRE = regexp.MustCompile(`<\/?code>`)
|
||||||
|
|
||||||
|
// CleanDesc cleans comments / descriptions of "<code>" and "</code>" strings
|
||||||
|
// and "`" characters, and fixes common misspellings.
|
||||||
|
func CleanDesc(s string) string {
|
||||||
|
s, _ = misspellReplacer.Replace(strings.Replace(codeRE.ReplaceAllString(s, ""), "`", "", -1))
|
||||||
|
return badHTMLReplacer.Replace(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForceCamel forces camel case specific to go.
|
// ForceCamel forces camel case specific to go.
|
||||||
|
@ -49,9 +65,6 @@ func ForceCamelWithFirstLower(s string) string {
|
||||||
return strings.ToLower(first) + s[len(first):]
|
return strings.ToLower(first) + s[len(first):]
|
||||||
}
|
}
|
||||||
|
|
||||||
// CodeRE is a regexp to match <code> and </code> tags.
|
|
||||||
var CodeRE = regexp.MustCompile(`<\/?code>`)
|
|
||||||
|
|
||||||
// resolve finds the ref in the provided domains, relative to domain d when ref
|
// resolve finds the ref in the provided domains, relative to domain d when ref
|
||||||
// is not namespaced.
|
// is not namespaced.
|
||||||
func resolve(ref string, d *Domain, domains []*Domain) (DomainType, *Type, string) {
|
func resolve(ref string, d *Domain, domains []*Domain) (DomainType, *Type, string) {
|
||||||
|
@ -123,9 +136,7 @@ func structDef(types []*Type, d *Domain, domains []*Domain, noExposeOverride, om
|
||||||
|
|
||||||
// add comment
|
// add comment
|
||||||
if v.Type != TypeObject && v.Description != "" {
|
if v.Type != TypeObject && v.Description != "" {
|
||||||
comment := CodeRE.ReplaceAllString(v.Description, "")
|
s += " // " + CleanDesc(v.Description)
|
||||||
comment, _ = MisspellReplacer.Replace(comment)
|
|
||||||
s += " // " + comment
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(types) > 0 {
|
if len(types) > 0 {
|
||||||
|
|
|
@ -25,17 +25,10 @@ var keep = map[string]bool{
|
||||||
"JavaScript": true,
|
"JavaScript": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
var badHTMLReplacer = strings.NewReplacer(
|
|
||||||
"<", "<",
|
|
||||||
">", ">",
|
|
||||||
">", ">",
|
|
||||||
)
|
|
||||||
|
|
||||||
// formatComment formats a comment.
|
// formatComment formats a comment.
|
||||||
func formatComment(s, chop, newstr string) string {
|
func formatComment(s, chop, newstr string) string {
|
||||||
s = strings.TrimPrefix(s, chop)
|
s = strings.TrimPrefix(s, chop)
|
||||||
s = strings.TrimSpace(internal.CodeRE.ReplaceAllString(s, ""))
|
s = strings.TrimSpace(internal.CleanDesc(s))
|
||||||
s = badHTMLReplacer.Replace(s)
|
|
||||||
|
|
||||||
l := len(s)
|
l := len(s)
|
||||||
if newstr != "" && l > 0 {
|
if newstr != "" && l > 0 {
|
||||||
|
@ -57,8 +50,6 @@ func formatComment(s, chop, newstr string) string {
|
||||||
}
|
}
|
||||||
s += "."
|
s += "."
|
||||||
|
|
||||||
s, _ = internal.MisspellReplacer.Replace(s)
|
|
||||||
|
|
||||||
return wrap(s, commentWidth-len(commentPrefix), commentPrefix)
|
return wrap(s, commentWidth-len(commentPrefix), commentPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user