Naming, layout and comments: descriptive full-word names, one item per line in wrapped calls and literals, and doc comments on exported names
Short and single-letter names in application code become full words (tests keep theirs). Wrapped calls, signatures and composite literals put one item per line, and one-line function bodies are expanded. Exported names and groups of constants get doc comments, and comments refer to the renamed identifiers.
This commit is contained in:
1 parent
043e307663
commit
465358609a
78 files changed
+2374
-1402
No files matched your search
@@ -70,7 +70,14 @@ func countSections(uses map[reflect.Type]int, section reflect.Type) {
|
||||
}
|
||||
}
|
||||
|
||||
func checkSections(t *testing.T, conf *JobSearchConfig, all map[string]any, uses map[reflect.Type]int, prefix string, section reflect.Value) {
|
||||
func checkSections(
|
||||
t *testing.T,
|
||||
conf *JobSearchConfig,
|
||||
all map[string]any,
|
||||
uses map[reflect.Type]int,
|
||||
prefix string,
|
||||
section reflect.Value,
|
||||
) {
|
||||
for _, f := range fieldsOf(section.Type()) {
|
||||
key := joinKey(prefix, f.key)
|
||||
if isSectionList(f.typ) {
|
||||
@@ -93,8 +100,12 @@ func checkSections(t *testing.T, conf *JobSearchConfig, all map[string]any, uses
|
||||
}
|
||||
for k := range keys {
|
||||
if _, ok := all[joinKey(keyPrefix, k)]; !ok {
|
||||
t.Errorf("%s.Flatten() key %q does not match its cfg tag %q",
|
||||
name, k, key)
|
||||
t.Errorf(
|
||||
"%s.Flatten() key %q does not match its cfg tag %q",
|
||||
name,
|
||||
k,
|
||||
key,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +127,7 @@ func checkSections(t *testing.T, conf *JobSearchConfig, all map[string]any, uses
|
||||
// checkSectionList checks the items of the list of sections at key implement
|
||||
// Section and that their methods agree with the list's value in all.
|
||||
func checkSectionList(t *testing.T, all map[string]any, key string, list reflect.Value) {
|
||||
t.Helper()
|
||||
name := list.Type().Elem().Name()
|
||||
if !reflect.PointerTo(list.Type().Elem()).Implements(sectionType) {
|
||||
t.Errorf("*%s (items of %s) does not implement Section", name, key)
|
||||
@@ -145,7 +157,13 @@ func checkSectionList(t *testing.T, all map[string]any, key string, list reflect
|
||||
// checkSectionMethods checks section's Map, TypeOf, ValueOf and SetValue
|
||||
// against want, its keys and values, and kinds, their kinds.
|
||||
// Setting each key to its own value must succeed and leave section unchanged.
|
||||
func checkSectionMethods(t *testing.T, name string, section reflect.Value, want map[string]any, kinds map[string]reflect.Kind) {
|
||||
func checkSectionMethods(
|
||||
t *testing.T,
|
||||
name string,
|
||||
section reflect.Value,
|
||||
want map[string]any,
|
||||
kinds map[string]reflect.Kind,
|
||||
) {
|
||||
s := section.Addr().Interface().(Section)
|
||||
if got := flattenMap("", s.Map()); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("%s.Map() =\n%v\nwant\n%v", name, got, want)
|
||||
@@ -184,14 +202,18 @@ func flattenMap(prefix string, m map[string]any) map[string]any {
|
||||
// checkEmbedded checks that structs embedded in a section, such as
|
||||
// JSCSourcesSource, implement Section too.
|
||||
func checkEmbedded(t *testing.T, section reflect.Type) {
|
||||
t.Helper()
|
||||
for i := 0; i < section.NumField(); i++ {
|
||||
sf := section.Field(i)
|
||||
if !sf.Anonymous || sf.Type.Kind() != reflect.Struct {
|
||||
continue
|
||||
}
|
||||
if !reflect.PointerTo(sf.Type).Implements(sectionType) {
|
||||
t.Errorf("*%s (embedded in %s) does not implement Section",
|
||||
sf.Type.Name(), section.Name())
|
||||
t.Errorf(
|
||||
"*%s (embedded in %s) does not implement Section",
|
||||
sf.Type.Name(),
|
||||
section.Name(),
|
||||
)
|
||||
}
|
||||
checkEmbedded(t, sf.Type)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user