Permalink
Browse files

Use consistent proper grammar; simplify some code.

  • Loading branch information...
dmitshur committed Dec 2, 2017
1 parent 9eec6a7 commit 96d51ee97c8b54cbd9821e2b00abeea68fe7688c
Showing with 14 additions and 16 deletions.
  1. +14 −16 github/gen-accessors.go
View
@@ -37,8 +37,7 @@ var (
sourceTmpl = template.Must(template.New("source").Parse(source))
// this blacklist lists structs for which we don't want to generate
// accessors.
// blacklistStructMethod lists "struct.method" combos to skip.
blacklistStructMethod = map[string]bool{
"RepositoryContent.GetContent": true,
"Client.GetBaseURL": true,
@@ -47,8 +46,7 @@ var (
"RateLimitError.GetResponse": true,
"AbuseRateLimitError.GetResponse": true,
}
// this blacklist lists structs for which we don't want to generate
// accessors.
// blacklistStruct lists structs to skip.
blacklistStruct = map[string]bool{
"Client": true,
}
@@ -101,14 +99,14 @@ func (t *templateData) processAST(f *ast.File) error {
if !ok {
continue
}
// skip unexported identifiers
// Skip unexported identifiers.
if !ts.Name.IsExported() {
logf("Struct %v is unexported; skipping.", ts.Name)
continue
}
// check in blacklist if the ts.Name struct is blacklisted
if key := fmt.Sprintf("%v", ts.Name); blacklistStruct[key] {
logf("Struct %v blacklisted; skipping.", key)
// Check if the struct is blacklisted.
if blacklistStruct[ts.Name.Name] {
logf("Struct %v is blacklisted; skipping.", ts.Name)
continue
}
st, ok := ts.Type.(*ast.StructType)
@@ -122,14 +120,14 @@ func (t *templateData) processAST(f *ast.File) error {
}
fieldName := field.Names[0]
// skip unexported identifiers
// Skip unexported identifiers.
if !fieldName.IsExported() {
logf("Field %v is unexported; skipping.", fieldName)
continue
}
// check for "struct.method" in blacklist
// Check if "struct.method" is blacklisted.
if key := fmt.Sprintf("%v.Get%v", ts.Name, fieldName); blacklistStructMethod[key] {
logf("Method %v blacklisted; skipping.", key)
logf("Method %v is blacklisted; skipping.", key)
continue
}
@@ -161,7 +159,7 @@ func (t *templateData) dump() error {
return nil
}
// Sort getters by ReceiverType.FieldName
// Sort getters by ReceiverType.FieldName.
sort.Sort(byName(t.Getters))
var buf bytes.Buffer
@@ -247,7 +245,7 @@ func (t *templateData) addMapType(x *ast.MapType, receiverType, fieldName string
}
func (t *templateData) addSelectorExpr(x *ast.SelectorExpr, receiverType, fieldName string) {
if strings.ToLower(fieldName[:1]) == fieldName[:1] { // non-exported field
if strings.ToLower(fieldName[:1]) == fieldName[:1] { // Non-exported field.
return
}
@@ -283,13 +281,13 @@ type templateData struct {
}
type getter struct {
sortVal string // lower-case version of "ReceiverType.FieldName"
ReceiverVar string // the one-letter variable name to match the ReceiverType
sortVal string // Lower-case version of "ReceiverType.FieldName".
ReceiverVar string // The one-letter variable name to match the ReceiverType.
ReceiverType string
FieldName string
FieldType string
ZeroValue string
NamedStruct bool // getter for named struct
NamedStruct bool // Getter for named struct.
}
type byName []*getter

0 comments on commit 96d51ee

Please sign in to comment.