Skip to content

Commit

Permalink
feat: add package name to output of failed structures
Browse files Browse the repository at this point in the history
  • Loading branch information
xobotyi committed Mar 23, 2023
1 parent d849875 commit 6a2ef91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (a *analyzer) processStruct(
if f := a.litSkippedFields(lit, structTyp, !isSamePackage); len(f) > 0 {
structName := "anonymous struct"
if namedTyp != nil {
structName = namedTyp.Obj().Name()
structName = namedTyp.Obj().Pkg().Name() + "." + namedTyp.Obj().Name()
}

pos := lit.Pos()
Expand Down
22 changes: 11 additions & 11 deletions analyzer/testdata/src/i/i.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func shouldPassOnlyOptionalOmitted() {
}

func shouldFailRequiredOmitted() {
_ = Test{ // want "Test is missing field D"
_ = Test{ // want "i.Test is missing field D"
A: "",
B: 0,
C: 0.0,
Expand All @@ -69,11 +69,11 @@ func shouldPassEmptyStructWithNonNilErr() (Test, error) {
}

func shouldFailEmptyStructWithNilErr() (Test, error) {
return Test{}, nil // want "Test is missing fields A, B, C, D"
return Test{}, nil // want "i.Test is missing fields A, B, C, D"
}

func shouldFailEmptyNestedStructWithNonNilErr() ([]Test, error) {
return []Test{{}}, nil // want "Test is missing fields A, B, C, D"
return []Test{{}}, nil // want "i.Test is missing fields A, B, C, D"
}

func shouldPassUnnamed() {
Expand Down Expand Up @@ -110,8 +110,8 @@ func shouldFailEmbedded() {
}

func shouldFailEmbeddedCompletelyMissing() {
_ = Test2{ // want "Test2 is missing field Embedded"
External: e.External{ // want "External is missing field B"
_ = Test2{ // want "i.Test2 is missing field Embedded"
External: e.External{ // want "e.External is missing field B"
A: "",
},
}
Expand All @@ -130,8 +130,8 @@ func shouldPassGeneric() {
}

func shouldFailGeneric() {
_ = testGenericStruct[int]{} // want "testGenericStruct is missing fields A, B"
_ = testGenericStruct[int]{ // want "testGenericStruct is missing field B"
_ = testGenericStruct[int]{} // want "i.testGenericStruct is missing fields A, B"
_ = testGenericStruct[int]{ // want "i.testGenericStruct is missing field B"
A: 42,
}
}
Expand Down Expand Up @@ -169,8 +169,8 @@ func shouldPassSlicesOfStructs() {

func shouldFailSlicesOfStructs() {
_ = []Test3{
{}, // want "Test3 is missing field A"
Test3{B: 123}, // want "Test3 is missing field A"
{}, // want "i.Test3 is missing field A"
Test3{B: 123}, // want "i.Test3 is missing field A"
}
}

Expand All @@ -184,8 +184,8 @@ func shouldPassMapOfStructs() {

func shouldFailMapOfStructs() {
_ = map[string]Test3{
"a": {}, // want "Test3 is missing field A"
"b": Test3{B: 123}, // want "Test3 is missing field A"
"a": {}, // want "i.Test3 is missing field A"
"b": Test3{B: 123}, // want "i.Test3 is missing field A"
}
}

Expand Down

0 comments on commit 6a2ef91

Please sign in to comment.