Repository: openconfig/ygot
Pull request #386 (2020-05-19 02:50:54)

Add staticcheck CI Step
Most of the checks have looked useful so far.
I've added two ignore rules at the top of two test files, both due to generated code.

wenovus: There are a couple types of errors I don't know how to handle. @robshakir could you take a look?
wenovus: Thanks for the reviews and suggestions!

Patch:
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 763df1a..6afd84b 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -11,6 +11,7 @@ jobs:
     name: Build
     runs-on: ubuntu-latest
     strategy:
+      fail-fast: false
       matrix:
         go: ['1.12', '1.13', '1.14']
 
@@ -38,6 +39,10 @@ jobs:
         run: |
           go get -u github.com/go-playground/overalls
 
+      - name: Install Staticcheck
+        run: |
+          go get -u honnef.co/go/tools/cmd/staticcheck
+
       - name: Check out code
         uses: actions/checkout@v2
         with:
@@ -92,6 +97,15 @@ jobs:
           done
         working-directory: go/src/github.com/openconfig/ygot
 
+      - name: Staticcheck
+        run: |
+          checkstr=""
+          for i in util ygot ygen ytypes ygot/pathtranslate testutil testcmp ypathgen; do
+            checkstr="$checkstr github.com/openconfig/ygot/$i"
+          done
+          staticcheck $checkstr
+        working-directory: go/src/github.com/openconfig/ygot
+
   finish:
     needs: build
     runs-on: ubuntu-latest
diff --git a/.gitignore b/.gitignore
index 140fada..246f57b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,1 +1,2 @@
 vendor/*
+.vscode/*
diff --git a/go.mod b/go.mod
index a5f4d5d..95d7fa3 100644
--- a/go.mod
+++ b/go.mod
@@ -10,7 +10,6 @@ require (
 	github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
 	github.com/openconfig/gnmi v0.0.0-20200414194230-1597cc0f2600
 	github.com/openconfig/goyang v0.0.0-20200328051049-f3d50fd25b33
-	github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3 // indirect
 	github.com/pmezard/go-difflib v1.0.0
 	google.golang.org/genproto v0.0.0-20200319113533-08878b785e9c
 	google.golang.org/grpc v1.28.0
diff --git a/go.sum b/go.sum
index 52a71df..a5a49aa 100644
--- a/go.sum
+++ b/go.sum
@@ -1,4 +1,5 @@
 cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
+github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 github.com/cenkalti/backoff/v4 v4.0.0/go.mod h1:eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg=
 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -14,12 +15,9 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
-github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
 github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
 github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
 github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
-github.com/golang/protobuf v1.4.0-rc.4 h1:+EOh4OY6tjM6ZueeUKinl1f0U2820HzQOuf1iqMnsks=
-github.com/golang/protobuf v1.4.0-rc.4/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
 github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0 h1:aRz0NBceriICVtjhCgKkDvl+RudKu1CT6h0ZvUTrNfE=
 github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -32,18 +30,12 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
-github.com/openconfig/gnmi v0.0.0-20200307010808-e7106f7f5493 h1:e/znXbq+Yiws97a4lJYlUeRw9OGxT2q27L4aMUb0GuM=
-github.com/openconfig/gnmi v0.0.0-20200307010808-e7106f7f5493/go.mod h1:jMSUQIR4z9WTtM58/QBHbElXAwbUnomFdty1aund1uY=
 github.com/openconfig/gnmi v0.0.0-20200414194230-1597cc0f2600 h1:EO0ADDEFlykRo0dVFbFglXO16iDoD60IxPJyttU49Ko=
 github.com/openconfig/gnmi v0.0.0-20200414194230-1597cc0f2600/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A=
 github.com/openconfig/goyang v0.0.0-20200115183954-d0a48929f0ea/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU=
-github.com/openconfig/goyang v0.0.0-20200309174518-a00bece872fc h1:W6XYKuH3mxF5WFhsSQOPPN9DRDba1xz9lbUbQR3uHkg=
-github.com/openconfig/goyang v0.0.0-20200309174518-a00bece872fc/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU=
 github.com/openconfig/goyang v0.0.0-20200328051049-f3d50fd25b33 h1:giwoPW7W3APrb2JUksjek+rAiSryYHMv+bzvh5UZRm8=
 github.com/openconfig/goyang v0.0.0-20200328051049-f3d50fd25b33/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU=
 github.com/openconfig/ygot v0.6.0/go.mod h1:o30svNf7O0xK+R35tlx95odkDmZWS9JyWWQSmIhqwAs=
-github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3 h1:YtFkrqsMEj7YqpIhRteVxJxCeC3jJBieuLr0d4C4rSA=
-github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@@ -52,6 +44,7 @@ golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPh
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
 golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
+golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0=
 golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -73,6 +66,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
 golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A=
 golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -93,9 +87,8 @@ google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLY
 google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
 google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
 google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
-google.golang.org/protobuf v1.20.1 h1:ESRXHgpUBG5D2I5mmsQIyYxB/tQIZfSZ8wLyFDf/N/U=
-google.golang.org/protobuf v1.20.1/go.mod h1:KqelGeouBkcbcuB3HCk4/YH2tmNLk6YSWA5LIWeI/lY=
 google.golang.org/protobuf v1.21.0 h1:qdOKuR/EIArgaWNjetjgTzgVTAZ+S/WXVrq9HW9zimw=
 google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
 honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc h1:/hemPrYIhOhy8zYrNj+069zDB68us2sMGsfkFJO0iZs=
 honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
diff --git a/staticcheck.conf b/staticcheck.conf
new file mode 100644
index 0000000..4c944b4
--- /dev/null
+++ b/staticcheck.conf
@@ -0,0 +1,1 @@
+# See documentation at https://staticcheck.io/docs/
diff --git a/util/gnmi.go b/util/gnmi.go
index b3ef5ed..95e9ab2 100644
--- a/util/gnmi.go
+++ b/util/gnmi.go
@@ -19,8 +19,8 @@ import (
 	"sort"
 	"strings"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/openconfig/goyang/pkg/yang"
+	"google.golang.org/protobuf/proto"
 
 	gpb "github.com/openconfig/gnmi/proto/gnmi"
 )
diff --git a/util/path.go b/util/path.go
index c5709dc..d2b9789 100644
--- a/util/path.go
+++ b/util/path.go
@@ -157,10 +157,10 @@ func removeXPATHPredicates(s string) (string, error) {
 			i += len(ss)
 		case si == -1 || ei == -1:
 			// This substring contained a mismatched pair of []s.
-			return "", fmt.Errorf("Mismatched brackets within substring %s of %s, [ pos: %d, ] pos: %d", ss, s, si, ei)
+			return "", fmt.Errorf("mismatched brackets within substring %s of %s, [ pos: %d, ] pos: %d", ss, s, si, ei)
 		case si > ei:
 			// This substring contained a ] before a [.
-			return "", fmt.Errorf("Incorrect ordering of [] within substring %s of %s, [ pos: %d, ] pos: %d", ss, s, si, ei)
+			return "", fmt.Errorf("incorrect ordering of [] within substring %s of %s, [ pos: %d, ] pos: %d", ss, s, si, ei)
 		default:
 			// This substring contained a matched set of []s.
 			b.WriteString(ss[0:si])
diff --git a/util/yang.go b/util/yang.go
index 8602df4..e184c22 100644
--- a/util/yang.go
+++ b/util/yang.go
@@ -237,10 +237,7 @@ func IsConfig(e *yang.Entry) bool {
 
 	// Reached the last element in the tree without explicit configuration
 	// being set.
-	if e.Config == yang.TSFalse {
-		return false
-	}
-	return true
+	return e.Config != yang.TSFalse
 }
 
 // isPathChild takes an input slice of strings representing a path and determines
diff --git a/ygen/genstate.go b/ygen/genstate.go
index d19aa97..dad90e3 100644
--- a/ygen/genstate.go
+++ b/ygen/genstate.go
@@ -153,7 +153,7 @@ func buildListKey(e *yang.Entry, compressOCPaths bool, resolveKeyTypeName func(k
 	if e.Key == "" {
 		// A null key is not valid if we have a config true list, so return an error
 		if util.IsConfig(e) {
-			return nil, []error{fmt.Errorf("No key specified for a config true list: %s", e.Name)}
+			return nil, []error{fmt.Errorf("no key specified for a config true list: %s", e.Name)}
 		}
 		// This is a keyless list so return an empty YangListAttr but no error, downstream
 		// mapping code should consider this to mean that this should be mapped into a
@@ -173,7 +173,7 @@ func buildListKey(e *yang.Entry, compressOCPaths bool, resolveKeyTypeName func(k
 		// corresponding to the leaf.
 		keyleaf, ok := e.Dir[k]
 		if !ok {
-			return nil, []error{fmt.Errorf("Key %s did not exist for %s", k, e.Name)}
+			return nil, []error{fmt.Errorf("key %s did not exist for %s", k, e.Name)}
 		}
 
 		if keyleaf.Type != nil {
@@ -192,7 +192,7 @@ func buildListKey(e *yang.Entry, compressOCPaths bool, resolveKeyTypeName func(k
 					// leafref.
 					refparts := strings.Split(keyleaf.Type.Path, "/")
 					if len(refparts) < 2 {
-						return nil, []error{fmt.Errorf("Key %s had an invalid path %s", k, keyleaf.Path())}
+						return nil, []error{fmt.Errorf("key %s had an invalid path %s", k, keyleaf.Path())}
 					}
 					// In the case of OpenConfig, the list key is specified to be under
 					// the 'config' or 'state' container of the list element (e). To this
@@ -203,14 +203,14 @@ func buildListKey(e *yang.Entry, compressOCPaths bool, resolveKeyTypeName func(k
 					d, ok := e.Dir[dir]
 					if !ok {
 						return nil, []error{
-							fmt.Errorf("Key %s had a leafref key (%s) in dir %s that did not exist (%v)",
+							fmt.Errorf("key %s had a leafref key (%s) in dir %s that did not exist (%v)",
 								k, keyleaf.Path(), dir, refparts),
 						}
 					}
 					targetLeaf := util.StripModulePrefix(refparts[len(refparts)-1])
 					if _, ok := d.Dir[targetLeaf]; !ok {
 						return nil, []error{
-							fmt.Errorf("Key %s had leafref key (%s) that did not exist at (%v)", k, keyleaf.Path(), refparts),
+							fmt.Errorf("key %s had leafref key (%s) that did not exist at (%v)", k, keyleaf.Path(), refparts),
 						}
 					}
 					keyleaf = d.Dir[targetLeaf]
diff --git a/ygen/protogen.go b/ygen/protogen.go
index 3ab451d..6152490 100644
--- a/ygen/protogen.go
+++ b/ygen/protogen.go
@@ -1268,7 +1268,7 @@ func enumInProtoUnionField(name string, etype *yang.YangType, annotateEnumNames
 	enums := map[string]*protoMsgEnum{}
 	for _, t := range etype.Type {
 		if util.IsSimpleEnumerationType(t) {
-			n := fmt.Sprintf("%s", yang.CamelCase(name))
+			n := yang.CamelCase(name)
 			enum, err := genProtoEnum(&yang.Entry{
 				Name: n,
 				Type: t,
diff --git a/ygot/diff.go b/ygot/diff.go
index 9bc4be2..878e139 100644
--- a/ygot/diff.go
+++ b/ygot/diff.go
@@ -20,10 +20,10 @@ import (
 	"sort"
 	"strings"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
 	"github.com/kylelemons/godebug/pretty"
 	"github.com/openconfig/ygot/util"
+	"google.golang.org/protobuf/proto"
 
 	gnmipb "github.com/openconfig/gnmi/proto/gnmi"
 )
@@ -45,9 +45,7 @@ func schemaPathTogNMIPath(path []string) *gnmipb.Path {
 // the v0.4.0 Elem field.
 func joingNMIPaths(parent *gnmipb.Path, child *gnmipb.Path) *gnmipb.Path {
 	p := proto.Clone(parent).(*gnmipb.Path)
-	for _, e := range child.Elem {
-		p.Elem = append(p.Elem, e)
-	}
+	p.Elem = append(p.Elem, child.Elem...)
 	return p
 }
 
@@ -258,7 +256,7 @@ func findSetLeaves(s GoStruct, opts ...DiffOpt) (map[*pathSpec]interface{}, erro
 		}
 		sort.Strings(keys)
 		key := strings.Join(keys, "/")
-		if _, ok := processedPaths[key]; ok == true {
+		if _, ok := processedPaths[key]; ok {
 			return
 		}
 		processedPaths[key] = true
@@ -298,9 +296,9 @@ func findSetLeaves(s GoStruct, opts ...DiffOpt) (map[*pathSpec]interface{}, erro
 // first is returned.
 func hasDiffPathOpt(opts []DiffOpt) *DiffPathOpt {
 	for _, o := range opts {
-		switch o.(type) {
+		switch v := o.(type) {
 		case *DiffPathOpt:
-			return o.(*DiffPathOpt)
+			return v
 		}
 	}
 	return nil
@@ -424,9 +422,7 @@ func Diff(original, modified GoStruct, opts ...DiffOpt) (*gnmipb.Notification, e
 		if !origMatched {
 			// This leaf was set in the original struct, but not in the modified
 			// struct, therefore it has been deleted.
-			for _, p := range origPath.gNMIPaths {
-				n.Delete = append(n.Delete, p)
-			}
+			n.Delete = append(n.Delete, origPath.gNMIPaths...)
 		}
 	}
 
diff --git a/ygot/helpers.go b/ygot/helpers.go
index 6cbd2ac..2010de6 100644
--- a/ygot/helpers.go
+++ b/ygot/helpers.go
@@ -63,6 +63,8 @@ func ToPtr(v interface{}) interface{} {
 	return n.Interface()
 }
 
+// BinaryToFloat32 converts the input bytes to a float32 assuming IEEE 754
+// representation. The input bytes should be of length 4.
 func BinaryToFloat32(in []byte) float32 {
 	return math.Float32frombits(binary.BigEndian.Uint32(in))
 }
diff --git a/ygot/pathstrings.go b/ygot/pathstrings.go
index 2948b23..4e68634 100644
--- a/ygot/pathstrings.go
+++ b/ygot/pathstrings.go
@@ -54,8 +54,10 @@ func PathToSchemaPath(path *gnmipb.Path) (string, error) {
 		return "", fmt.Errorf("received nil path in PathToSchemaPath")
 	}
 
+	//lint:ignore SA1019 Specifically handling deprecated gNMI Element fields.
 	if path.Element != nil {
 		var sp []string
+		//lint:ignore SA1019 Specifically handling deprecated gNMI Element fields.
 		for _, e := range path.Element {
 			elem, _, err := extractKV(e)
 			if err != nil {
@@ -89,7 +91,9 @@ func PathToStrings(path *gnmipb.Path) ([]string, error) {
 		return nil, fmt.Errorf("received nil path in PathToStrings")
 	}
 
+	//lint:ignore SA1019 Specifically handling deprecated gNMI Element fields.
 	if path.Element != nil {
+		//lint:ignore SA1019 Specifically handling deprecated gNMI Element fields.
 		return elementsToString(path.Element)
 	}
 
@@ -173,6 +177,7 @@ func StringToPath(path string, pathTypes ...PathType) (*gnmipb.Path, error) {
 				errs = util.AppendErr(errs, fmt.Errorf("error building string slice path: %v", err))
 				continue
 			}
+			//lint:ignore SA1019 Specifically handling deprecated gNMI Element fields.
 			pmsg.Element = gp.Element
 		}
 	}
@@ -203,6 +208,7 @@ func StringToStringSlicePath(path string) (*gnmipb.Path, error) {
 		if err != nil {
 			return nil, fmt.Errorf("error formatting path %q: %v", path, err)
 		}
+		//lint:ignore SA1019 Specifically handling deprecated gNMI Element fields.
 		gpath.Element = append(gpath.Element, fpath)
 	}
 
diff --git a/ygot/render.go b/ygot/render.go
index 791e899..a604493 100644
--- a/ygot/render.go
+++ b/ygot/render.go
@@ -22,11 +22,12 @@ import (
 	"sort"
 	"strings"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/mohae/deepcopy"
 	"github.com/openconfig/gnmi/errlist"
 	"github.com/openconfig/gnmi/value"
 	"github.com/openconfig/ygot/util"
+	"google.golang.org/protobuf/encoding/prototext"
+	"google.golang.org/protobuf/proto"
 
 	gnmipb "github.com/openconfig/gnmi/proto/gnmi"
 )
@@ -48,7 +49,7 @@ type path struct {
 
 func (p *path) String() string {
 	if p.p.isPathElemPath() {
-		return proto.MarshalTextString(&gnmipb.Path{Elem: p.p.pathElemPath})
+		return prototext.Format(&gnmipb.Path{Elem: p.p.pathElemPath})
 	}
 	return fmt.Sprintf("%v", p.p.pathElemPath)
 }
@@ -188,18 +189,18 @@ func (g *gnmiPath) SetIndex(i int, v interface{}) error {
 		return fmt.Errorf("invalid index, out of range, got: %d, length: %d", i, g.Len())
 	}
 
-	switch v.(type) {
+	switch v := v.(type) {
 	case string:
 		if !g.isStringSlicePath() {
 			return fmt.Errorf("cannot set index %d of %v to %v, wrong type %T, expected string", i, v, g, v)
 		}
-		g.stringSlicePath[i] = v.(string)
+		g.stringSlicePath[i] = v
 		return nil
 	case *gnmipb.PathElem:
 		if !g.isPathElemPath() {
 			return fmt.Errorf("cannot set index %d of %v to %v, wrong type %T, expected gnmipb.PathElem", i, v, g, v)
 		}
-		g.pathElemPath[i] = v.(*gnmipb.PathElem)
+		g.pathElemPath[i] = v
 		return nil
 	}
 	return fmt.Errorf("cannot set index %d of %v to %v, wrong type %T", i, v, g, v)
@@ -439,9 +440,7 @@ func mapValuePath(key, value reflect.Value, parentPath *gnmiPath) (*gnmiPath, er
 		}
 		// We copy the elements from the existing elementPath such that when updating
 		// it, then the elements are not modified when the paths are changed.
-		for _, e := range parentPath.stringSlicePath {
-			childPath.stringSlicePath = append(childPath.stringSlicePath, e)
-		}
+		childPath.stringSlicePath = append(childPath.stringSlicePath, parentPath.stringSlicePath...)
 		childPath.stringSlicePath = append(childPath.stringSlicePath, keyval)
 		return childPath, nil
 	}
diff --git a/ygot/struct_validation_map.go b/ygot/struct_validation_map.go
index f29296b..86250c1 100644
--- a/ygot/struct_validation_map.go
+++ b/ygot/struct_validation_map.go
@@ -643,8 +643,7 @@ func copyInterfaceField(dstField, srcField reflect.Value) error {
 		}
 	}
 
-	var d reflect.Value
-	d = reflect.New(s.Type())
+	d := reflect.New(s.Type())
 	if err := copyStruct(d.Elem(), s); err != nil {
 		return err
 	}
diff --git a/ytypes/leafref.go b/ytypes/leafref.go
index 5a3ed76..a3f379e 100644
--- a/ytypes/leafref.go
+++ b/ytypes/leafref.go
@@ -293,7 +293,6 @@ func matchesNodes(ni *util.NodeInfo, matchNodes []interface{}) (bool, error) {
 	}
 
 	for _, sourceNode := range sourceNodes {
-		match := false
 		for _, other := range matchNodes {
 			if util.IsValueNilOrDefault(other) {
 				continue
@@ -304,8 +303,7 @@ func matchesNodes(ni *util.NodeInfo, matchNodes []interface{}) (bool, error) {
 				util.DbgPrint("comparing leafref values %s vs %s", util.ValueStrDebug(sourceNode), util.ValueStrDebug(other))
 				if util.DeepEqualDerefPtrs(sourceNode, other) {
 					util.DbgPrint("values are equal")
-					match = true
-					break
+					return true, nil
 				}
 			case util.IsValueSlice(ov):
 				sourceNode := ni.FieldValue.Interface()
@@ -313,8 +311,7 @@ func matchesNodes(ni *util.NodeInfo, matchNodes []interface{}) (bool, error) {
 				for i := 0; i < ov.Len(); i++ {
 					if util.DeepEqualDerefPtrs(sourceNode, ov.Index(i).Interface()) {
 						util.DbgPrint("value exists in list")
-						match = true
-						break
+						return true, nil
 					}
 				}
 			case util.IsValueStructPtr(ov):
@@ -323,17 +320,13 @@ func matchesNodes(ni *util.NodeInfo, matchNodes []interface{}) (bool, error) {
 				ovv := ov.Elem().FieldByIndex([]int{0})
 				svv := ni.FieldValue.Elem().Elem().FieldByIndex([]int{0})
 				if cmp.Equal(ovv.Interface(), svv.Interface()) {
-					match = true
-					break
+					return true, nil
 				}
 			}
 		}
-		if !match {
-			return false, nil
-		}
 	}
 
-	return true, nil
+	return false, nil
 }
 
 // getDataTreeRoot returns the root NodeInfo element for the current node.
diff --git a/ytypes/list.go b/ytypes/list.go
index ec52ee3..030f3a5 100644
--- a/ytypes/list.go
+++ b/ytypes/list.go
@@ -223,9 +223,7 @@ func validateListSchema(schema *yang.Entry) error {
 			keysMissing[v] = true
 		}
 		for _, v := range schema.Dir {
-			if _, ok := keysMissing[v.Name]; ok {
-				delete(keysMissing, v.Name)
-			}
+			delete(keysMissing, v.Name)
 		}
 		if len(keysMissing) != 0 {
 			return fmt.Errorf("list %s has keys %v missing from required list of %v", schema.Name, keysMissing, keys)
@@ -336,7 +334,8 @@ func unmarshalList(schema *yang.Entry, parent interface{}, jsonList interface{},
 
 		switch {
 		case util.IsTypeMap(t):
-			newKey, err := makeKeyForInsert(schema, parent, newVal)
+			var newKey reflect.Value
+			newKey, err = makeKeyForInsert(schema, parent, newVal)
 			if err != nil {
 				return err
 			}
diff --git a/ytypes/node.go b/ytypes/node.go
index bad8474..c46150e 100644
--- a/ytypes/node.go
+++ b/ytypes/node.go
@@ -17,12 +17,12 @@ package ytypes
 import (
 	"reflect"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/openconfig/goyang/pkg/yang"
 	"github.com/openconfig/ygot/util"
 	"github.com/openconfig/ygot/ygot"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
+	"google.golang.org/protobuf/proto"
 
 	gpb "github.com/openconfig/gnmi/proto/gnmi"
 )
diff --git a/ytypes/util_schema.go b/ytypes/util_schema.go
index 1145fe8..8be8a1f 100644
--- a/ytypes/util_schema.go
+++ b/ytypes/util_schema.go
@@ -23,6 +23,8 @@ import (
 	"github.com/openconfig/ygot/util"
 )
 
+//lint:file-ignore U1000 Ignore all unused code, it represents generated code.
+
 // validateLengthSchema validates whether the given schema has a valid length
 // specification.
 func validateLengthSchema(schema *yang.Entry) error {
diff --git a/ytypes/validate.go b/ytypes/validate.go
index a99f449..66cd149 100644
--- a/ytypes/validate.go
+++ b/ytypes/validate.go
@@ -61,9 +61,9 @@ func Validate(schema *yang.Entry, value interface{}, opts ...ygot.ValidationOpti
 	// explicitly returning an error.
 	var leafrefOpt *LeafrefOptions
 	for _, o := range opts {
-		switch o.(type) {
+		switch v := o.(type) {
 		case *LeafrefOptions:
-			leafrefOpt = o.(*LeafrefOptions)
+			leafrefOpt = v
 		}
 	}
 


Test patch:
diff --git a/testcmp/cmp.go b/testcmp/cmp.go
index 8559449..6e554b1 100644
--- a/testcmp/cmp.go
+++ b/testcmp/cmp.go
@@ -23,12 +23,12 @@ import (
 	"reflect"
 
 	log "github.com/golang/glog"
-	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
 	"github.com/google/go-cmp/cmp/cmpopts"
 	"github.com/openconfig/ygot/testutil"
 	"github.com/openconfig/ygot/ygot"
 	"github.com/openconfig/ygot/ytypes"
+	"google.golang.org/protobuf/proto"
 	"google.golang.org/protobuf/testing/protocmp"
 
 	gnmipb "github.com/openconfig/gnmi/proto/gnmi"
diff --git a/testutil/testutil.go b/testutil/testutil.go
index d5edb60..4dd9e4f 100644
--- a/testutil/testutil.go
+++ b/testutil/testutil.go
@@ -22,10 +22,10 @@ import (
 	"reflect"
 	"sort"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
 	"github.com/google/go-cmp/cmp/cmpopts"
 	"github.com/openconfig/gnmi/value"
+	"google.golang.org/protobuf/proto"
 	"google.golang.org/protobuf/testing/protocmp"
 
 	gnmipb "github.com/openconfig/gnmi/proto/gnmi"
@@ -384,11 +384,18 @@ func PathLess(a, b *gnmipb.Path) bool {
 
 	// Handle comparison of paths that are based on the "element" rather than
 	// "elem".
+	// TODO(robjs): Remove handling of element fields when they are fully
+	// deprecated in gNMI.
+	//
+	//lint:ignore SA1019 Specifically handling deprecated gNMI Element fields.
 	for len(a.Element) != len(b.Element) {
+		//lint:ignore SA1019 Specifically handling deprecated gNMI Element fields.
 		return len(a.Element) > len(b.Element)
 	}
 
+	//lint:ignore SA1019 Specifically handling deprecated gNMI Element fields.
 	for i := 0; i < len(a.Element); i++ {
+		//lint:ignore SA1019 Specifically handling deprecated gNMI Element fields.
 		if ae, be := a.Element[i], b.Element[i]; ae != be {
 			return ae < be
 		}
diff --git a/util/gnmi_test.go b/util/gnmi_test.go
index 5743873..d570e0e 100644
--- a/util/gnmi_test.go
+++ b/util/gnmi_test.go
@@ -18,10 +18,11 @@ import (
 	"strings"
 	"testing"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
 	"github.com/openconfig/gnmi/errdiff"
 	"github.com/openconfig/goyang/pkg/yang"
+	"google.golang.org/protobuf/encoding/prototext"
+	"google.golang.org/protobuf/proto"
 
 	gpb "github.com/openconfig/gnmi/proto/gnmi"
 )
@@ -509,7 +510,7 @@ func TestTrimGNMIPathElemPrefix(t *testing.T) {
 	for _, tt := range tests {
 		t.Run(tt.desc, func(t *testing.T) {
 			if got := TrimGNMIPathElemPrefix(tt.inPath, tt.inPrefix); !proto.Equal(got, tt.want) {
-				t.Fatalf("did not get expected path, got: %s, want: %s", proto.MarshalTextString(got), proto.MarshalTextString(tt.want))
+				t.Fatalf("did not get expected path, got: %s, want: %s", prototext.Format(got), prototext.Format(tt.want))
 			}
 		})
 	}
@@ -545,7 +546,7 @@ func TestFindPathElemPrefix(t *testing.T) {
 
 	for _, tt := range tests {
 		if got := FindPathElemPrefix(tt.inPaths); !proto.Equal(got, tt.want) {
-			t.Errorf("%s: FindPathElemPrefix(%v): did not get expected prefix, got: %s, want: %s", tt.name, tt.inPaths, proto.MarshalTextString(got), proto.MarshalTextString(tt.want))
+			t.Errorf("%s: FindPathElemPrefix(%v): did not get expected prefix, got: %s, want: %s", tt.name, tt.inPaths, prototext.Format(got), prototext.Format(tt.want))
 		}
 	}
 }
diff --git a/util/path_test.go b/util/path_test.go
index 9084a05..4c5c802 100644
--- a/util/path_test.go
+++ b/util/path_test.go
@@ -474,7 +474,7 @@ func TestFindLeafRefSchema(t *testing.T) {
 			},
 		},
 		inPathStr: "/interfaces/interface[name=foo/bar",
-		wantErr:   "Mismatched brackets within substring /interfaces/interface[name=foo/bar of /interfaces/interface[name=foo/bar, [ pos: 21, ] pos: -1",
+		wantErr:   "mismatched brackets within substring /interfaces/interface[name=foo/bar of /interfaces/interface[name=foo/bar, [ pos: 21, ] pos: -1",
 	}, {
 		desc: "with xpath predicate",
 		inSchema: &yang.Entry{
diff --git a/util/reflect_test.go b/util/reflect_test.go
index 9440cb3..1f92ba3 100644
--- a/util/reflect_test.go
+++ b/util/reflect_test.go
@@ -1222,8 +1222,7 @@ func TestForEachField(t *testing.T) {
 
 	for _, tt := range tests {
 		outStr := ""
-		var errs Errors
-		errs = ForEachField(tt.schema, tt.parentStruct, tt.in, &outStr, tt.iterFunc)
+		var errs Errors = ForEachField(tt.schema, tt.parentStruct, tt.in, &outStr, tt.iterFunc)
 		if got, want := errs.String(), tt.wantErr; got != want {
 			diff, _ := testutil.GenerateUnifiedDiff(want, got)
 			t.Errorf("%s:\n%s", tt.desc, diff)
@@ -1332,8 +1331,7 @@ func TestForEachDataField(t *testing.T) {
 
 	for _, tt := range tests {
 		outStr := ""
-		var errs Errors
-		errs = ForEachDataField(tt.parentStruct, tt.in, &outStr, tt.iterFunc)
+		var errs Errors = ForEachDataField(tt.parentStruct, tt.in, &outStr, tt.iterFunc)
 		if got, want := errs.String(), tt.wantErr; got != want {
 			diff, _ := testutil.GenerateUnifiedDiff(want, got)
 			t.Errorf("%s: ForEachDataField(%v, %#v, ...): \n%s", tt.desc, tt.parentStruct, tt.in, diff)
diff --git a/ygen/codegen_test.go b/ygen/codegen_test.go
index 5933a78..bcbccc1 100644
--- a/ygen/codegen_test.go
+++ b/ygen/codegen_test.go
@@ -602,16 +602,14 @@ func TestSimpleStructs(t *testing.T) {
 		inFiles:             []string{filepath.Join(datapath, "empty.yang")},
 		wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/empty.formatted-txt"),
 	}, {
-		name:    "module with excluded modules",
-		inFiles: []string{filepath.Join(datapath, "excluded-module.yang")},
+		name:             "module with excluded modules",
+		inFiles:          []string{filepath.Join(datapath, "excluded-module.yang")},
+		inExcludeModules: []string{"excluded-module-two"},
 		inConfig: GeneratorConfig{
 			TransformationOptions: TransformationOpts{
 				GenerateFakeRoot: true,
 				FakeRootName:     "office",
 			},
-			ParseOptions: ParseOpts{
-				ExcludeModules: []string{"excluded-module-two"},
-			},
 		},
 		wantStructsCodeFile: filepath.Join(TestRoot, "testdata/structs/excluded-module.formatted-txt"),
 	}, {
@@ -736,6 +734,7 @@ func TestSimpleStructs(t *testing.T) {
 					tt.inConfig.Caller = "codegen-tests"
 				}
 				tt.inConfig.StoreRawSchema = true
+				tt.inConfig.ParseOptions.ExcludeModules = tt.inExcludeModules
 
 				cg := NewYANGCodeGenerator(&tt.inConfig)
 
diff --git a/ygen/enumgen_test.go b/ygen/enumgen_test.go
index 8948cb9..816b755 100644
--- a/ygen/enumgen_test.go
+++ b/ygen/enumgen_test.go
@@ -15,7 +15,6 @@
 package ygen
 
 import (
-	"encoding/json"
 	"fmt"
 	"testing"
 
@@ -1276,8 +1275,7 @@ func TestFindEnumSet(t *testing.T) {
 					}
 
 					if want.entry.Name != got.entry.Name {
-						j, _ := json.Marshal(got)
-						t.Errorf("extracted entry has wrong name: got %s, want: %s (%s)", got.entry.Name, want.entry.Name, string(j))
+						t.Errorf("extracted entry has wrong name: got %s, want: %s (%+v)", got.entry.Name, want.entry.Name, got)
 					}
 
 					if want.entry.Type.IdentityBase != nil {
diff --git a/ygen/protogen_test.go b/ygen/protogen_test.go
index 9b8762d..3a6626c 100644
--- a/ygen/protogen_test.go
+++ b/ygen/protogen_test.go
@@ -46,11 +46,7 @@ func protoMsgEq(a, b *protoMsg) bool {
 		return e
 	}
 
-	if !cmp.Equal(fieldMap(a.Fields), fieldMap(b.Fields)) {
-		return false
-	}
-
-	return true
+	return cmp.Equal(fieldMap(a.Fields), fieldMap(b.Fields))
 }
 
 func TestGenProto3Msg(t *testing.T) {
diff --git a/ygot/diff_test.go b/ygot/diff_test.go
index a5eafe8..dd8b186 100644
--- a/ygot/diff_test.go
+++ b/ygot/diff_test.go
@@ -20,12 +20,12 @@ import (
 	"strings"
 	"testing"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
 	"github.com/google/go-cmp/cmp/cmpopts"
 	"github.com/kylelemons/godebug/pretty"
 	"github.com/openconfig/ygot/testutil"
 	"github.com/openconfig/ygot/util"
+	"google.golang.org/protobuf/proto"
 
 	"github.com/openconfig/gnmi/errdiff"
 	gnmipb "github.com/openconfig/gnmi/proto/gnmi"
diff --git a/ygot/path_types_test.go b/ygot/path_types_test.go
index 1c75239..546eb26 100644
--- a/ygot/path_types_test.go
+++ b/ygot/path_types_test.go
@@ -17,8 +17,8 @@ package ygot
 import (
 	"testing"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
+	"google.golang.org/protobuf/proto"
 )
 
 func TestResolvePath(t *testing.T) {
diff --git a/ygot/pathstrings_test.go b/ygot/pathstrings_test.go
index 5a26473..408d560 100644
--- a/ygot/pathstrings_test.go
+++ b/ygot/pathstrings_test.go
@@ -18,10 +18,11 @@ import (
 	"strings"
 	"testing"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
 	"github.com/openconfig/gnmi/errdiff"
 	gnmipb "github.com/openconfig/gnmi/proto/gnmi"
+	"google.golang.org/protobuf/encoding/prototext"
+	"google.golang.org/protobuf/proto"
 )
 
 // TestPathToString validates the functionality provided by the PathToString
@@ -432,7 +433,7 @@ func TestStringToPath(t *testing.T) {
 		}
 
 		if strErr == nil && !proto.Equal(gotStructuredPath, tt.wantStructuredPath) {
-			t.Errorf("%s: StringToStructuredPath(%v): did not get expected structured path, got: %v, want: %v", tt.name, tt.in, proto.MarshalTextString(gotStructuredPath), proto.MarshalTextString(tt.wantStructuredPath))
+			t.Errorf("%s: StringToStructuredPath(%v): did not get expected structured path, got: %v, want: %v", tt.name, tt.in, prototext.Format(gotStructuredPath), prototext.Format(tt.wantStructuredPath))
 		}
 
 		if strErr != nil || sliceErr != nil {
@@ -440,14 +441,17 @@ func TestStringToPath(t *testing.T) {
 		}
 
 		wantCombined := proto.Clone(tt.wantStructuredPath).(*gnmipb.Path)
+
+		//lint:ignore SA1019 Specifically handling deprecated gNMI Element fields.
 		wantCombined.Element = append(wantCombined.Element, tt.wantStringSlicePath.Element...)
+
 		gotCombinedPath, combinedErr := StringToPath(tt.in, StringSlicePath, StructuredPath)
 		if combinedErr != nil && combinedErr.Error() != tt.wantCombinedErr {
 			t.Errorf("%s: StringToPath(%v, {StringSlicePath, StructuredPath}): did not get expected combined error, got: %v, want: %v", tt.name, tt.in, combinedErr, tt.wantCombinedErr)
 		}
 
 		if combinedErr == nil && !proto.Equal(gotCombinedPath, wantCombined) {
-			t.Errorf("%s: StringToPath(%v, {StringSlicePath, StructuredPath}): did not get expected combined path message, got: %v, want: %v", tt.name, tt.in, proto.MarshalTextString(gotCombinedPath), proto.MarshalTextString(wantCombined))
+			t.Errorf("%s: StringToPath(%v, {StringSlicePath, StructuredPath}): did not get expected combined path message, got: %v, want: %v", tt.name, tt.in, prototext.Format(gotCombinedPath), prototext.Format(wantCombined))
 		}
 
 	}
@@ -529,7 +533,7 @@ func TestPathToSchemaPath(t *testing.T) {
 	for _, tt := range tests {
 		got, err := PathToSchemaPath(tt.inPath)
 		if diff := errdiff.Substring(err, tt.wantErrSubstring); diff != "" {
-			t.Errorf("%s: PathToSchemaPath(%s): did not get expected error, %s", tt.name, proto.MarshalTextString(tt.inPath), diff)
+			t.Errorf("%s: PathToSchemaPath(%s): did not get expected error, %s", tt.name, prototext.Format(tt.inPath), diff)
 		}
 
 		if err != nil {
@@ -537,7 +541,7 @@ func TestPathToSchemaPath(t *testing.T) {
 		}
 
 		if got != tt.want {
-			t.Errorf("%s: PathToSchemaPath(%s): did not get expected path, got: %s, want: %s", tt.name, proto.MarshalTextString(tt.inPath), got, tt.want)
+			t.Errorf("%s: PathToSchemaPath(%s): did not get expected path, got: %s, want: %s", tt.name, prototext.Format(tt.inPath), got, tt.want)
 		}
 	}
 }
diff --git a/ygot/pathtranslate/pathtranslate_test.go b/ygot/pathtranslate/pathtranslate_test.go
index 661ffc5..8e3dbdb 100644
--- a/ygot/pathtranslate/pathtranslate_test.go
+++ b/ygot/pathtranslate/pathtranslate_test.go
@@ -17,10 +17,10 @@ package pathtranslate
 import (
 	"testing"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
 	"github.com/openconfig/gnmi/errdiff"
 	"github.com/openconfig/goyang/pkg/yang"
+	"google.golang.org/protobuf/proto"
 
 	gnmipb "github.com/openconfig/gnmi/proto/gnmi"
 )
diff --git a/ygot/render_test.go b/ygot/render_test.go
index 12b4a0e..01ded54 100644
--- a/ygot/render_test.go
+++ b/ygot/render_test.go
@@ -20,12 +20,13 @@ import (
 	"reflect"
 	"testing"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
 	"github.com/google/go-cmp/cmp/cmpopts"
 	"github.com/kylelemons/godebug/pretty"
 	"github.com/openconfig/gnmi/errdiff"
 	"github.com/openconfig/ygot/testutil"
+	"google.golang.org/protobuf/encoding/prototext"
+	"google.golang.org/protobuf/proto"
 	"google.golang.org/protobuf/testing/protocmp"
 
 	gnmipb "github.com/openconfig/gnmi/proto/gnmi"
@@ -288,7 +289,7 @@ func TestGNMIPathToProto(t *testing.T) {
 		}
 
 		if !proto.Equal(got, tt.wantProto) {
-			t.Errorf("%s: %v.ToProto, did not get expected return value, got: %s, want: %s", tt.name, tt.inPath, proto.MarshalTextString(got), proto.MarshalTextString(tt.wantProto))
+			t.Errorf("%s: %v.ToProto, did not get expected return value, got: %s, want: %s", tt.name, tt.inPath, prototext.Format(got), prototext.Format(tt.wantProto))
 		}
 	}
 }
@@ -728,12 +729,6 @@ type renderExampleUnionString struct {
 
 func (*renderExampleUnionString) IsRenderUnionExample() {}
 
-type renderExampleUnionInt8 struct {
-	Int8 int8
-}
-
-func (*renderExampleUnionInt8) IsRenderUnionExample() {}
-
 type renderExampleUnionInt64 struct {
 	Int64 int64
 }
@@ -1406,10 +1401,6 @@ type exampleBgpNeighborEnabledAddressFamiliesUnionUint64 struct {
 func (*exampleBgpNeighborEnabledAddressFamiliesUnionUint64) IsExampleBgpNeighborEnabledAddressFamiliesUnion() {
 }
 
-type exampleBgpNeighborEnabledAddressFamiliesUnionEnum struct {
-	E EnumTest
-}
-
 type exampleBgpNeighborEnabledAddressFamiliesUnionBinary struct {
 	Binary Binary
 }
@@ -1639,7 +1630,7 @@ func TestConstructJSON(t *testing.T) {
 		wantInternal map[string]interface{}
 		wantSame     bool
 		wantErr      bool
-		wantJsonErr  bool
+		wantJSONErr  bool
 	}{{
 		name: "invalidGoStruct",
 		in: &invalidGoStructChild{
@@ -2227,7 +2218,7 @@ func TestConstructJSON(t *testing.T) {
 				&errorAnnotation{AnnotationField: "chalk-hill"},
 			},
 		},
-		wantJsonErr: true,
+		wantJSONErr: true,
 	}, {
 		name: "error in annotation - unmarshalable",
 		in: &annotatedJSONTestStruct{
@@ -2236,7 +2227,7 @@ func TestConstructJSON(t *testing.T) {
 				&unmarshalableJSON{AnnotationField: "knights-valley"},
 			},
 		},
-		wantJsonErr: true,
+		wantJSONErr: true,
 	}, {
 		name:     "unset enum",
 		in:       &renderExample{EnumField: EnumTestUNSET},
@@ -2269,8 +2260,8 @@ func TestConstructJSON(t *testing.T) {
 			}
 
 			_, err = json.Marshal(gotietf)
-			if (err != nil) != tt.wantJsonErr {
-				t.Fatalf("json.Marshal(%v): got unexpected error: %v, want error: %v", gotietf, err, tt.wantJsonErr)
+			if (err != nil) != tt.wantJSONErr {
+				t.Fatalf("json.Marshal(%v): got unexpected error: %v, want error: %v", gotietf, err, tt.wantJSONErr)
 			}
 			if err != nil {
 				return
@@ -2291,8 +2282,8 @@ func TestConstructJSON(t *testing.T) {
 			}
 
 			_, err = json.Marshal(gotjson)
-			if (err != nil) != tt.wantJsonErr {
-				t.Fatalf("json.Marshal(%v): got unexpected error: %v, want error: %v", gotjson, err, tt.wantJsonErr)
+			if (err != nil) != tt.wantJSONErr {
+				t.Fatalf("json.Marshal(%v): got unexpected error: %v, want error: %v", gotjson, err, tt.wantJSONErr)
 			}
 			if err != nil {
 				return
diff --git a/ygot/struct_validation_map_test.go b/ygot/struct_validation_map_test.go
index ade2b29..1bb43d1 100644
--- a/ygot/struct_validation_map_test.go
+++ b/ygot/struct_validation_map_test.go
@@ -22,9 +22,9 @@ import (
 	"reflect"
 	"testing"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
 	"github.com/kylelemons/godebug/pretty"
+	"google.golang.org/protobuf/proto"
 
 	"github.com/openconfig/gnmi/errdiff"
 	gnmipb "github.com/openconfig/gnmi/proto/gnmi"
@@ -222,11 +222,8 @@ func (e badEnumTest) String() string {
 }
 
 func TestEnumFieldToString(t *testing.T) {
-	var i interface{}
-	i = EONE
-	if _, ok := i.(GoEnum); !ok {
-		t.Fatalf("TestEnumFieldToString: %T is not a valid GoEnum", i)
-	}
+	// EONE must be a valid GoEnum.
+	var _ GoEnum = EONE
 
 	tests := []struct {
 		name               string
diff --git a/ytypes/list_test.go b/ytypes/list_test.go
index 016c924..d3d8251 100644
--- a/ytypes/list_test.go
+++ b/ytypes/list_test.go
@@ -324,16 +324,10 @@ func TestValidateListStructKey(t *testing.T) {
 		Key2     *int32  `path:"key2"`
 		LeafName *string `path:"leaf-name"`
 	}
-	type BadElemStruct1 struct {
+	type BadElemStruct struct {
 		Key1     *string `path:"key1"`
 		LeafName *string `path:"leaf-name"`
 	}
-	type BadElemStruct2 struct {
-		Key1       *string `path:"key1"`
-		Key2       *int32  `path:"key2"`
-		ExtraField *string `path:"extra-name"`
-		LeafName   *string `path:"leaf-name"`
-	}
 
 	tests := []struct {
 		desc    string
@@ -363,7 +357,7 @@ func TestValidateListStructKey(t *testing.T) {
 		},
 		{
 			desc: "missing key",
-			val: map[KeyStruct]*BadElemStruct1{
+			val: map[KeyStruct]*BadElemStruct{
 				{"elem1_key_val", 0}: {
 					Key1:     ygot.String("elem1_key_val"),
 					LeafName: ygot.String("elem1_leaf_name"),
diff --git a/ytypes/node_test.go b/ytypes/node_test.go
index 51c9968..8e28cc7 100644
--- a/ytypes/node_test.go
+++ b/ytypes/node_test.go
@@ -20,11 +20,12 @@ import (
 	"reflect"
 	"testing"
 
-	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
 	"github.com/openconfig/gnmi/errdiff"
 	"github.com/openconfig/goyang/pkg/yang"
 	"github.com/openconfig/ygot/ygot"
+	"google.golang.org/protobuf/encoding/prototext"
+	"google.golang.org/protobuf/proto"
 
 	gpb "github.com/openconfig/gnmi/proto/gnmi"
 )
@@ -808,9 +809,9 @@ func treeNodesEqual(got, want []*TreeNode) error {
 		if !match {
 			paths := []string{}
 			for _, g := range got {
-				paths = append(paths, fmt.Sprintf("< %s | %#v >", proto.CompactTextString(g.Path), g))
+				paths = append(paths, fmt.Sprintf("< %s | %#v >", prototext.MarshalOptions{Multiline: false}.Format(g.Path), g))
 			}
-			return fmt.Errorf("no match for %#v (path: %s) in %v", w, proto.CompactTextString(w.Path), paths)
+			return fmt.Errorf("no match for %#v (path: %s) in %v", w, prototext.MarshalOptions{Multiline: false}.Format(w.Path), paths)
 		}
 	}
 	return nil
@@ -1867,10 +1868,6 @@ func TestRetrieveContainerListError(t *testing.T) {
 		},
 	}
 
-	type Root struct {
-		Ok *string `path:"ok"`
-	}
-
 	type NoTagRoot struct {
 		Ok    *string `path:"ok"`
 		NoTag *string
diff --git a/ytypes/util_test.go b/ytypes/util_test.go
index 3195cb1..27d1fa4 100644
--- a/ytypes/util_test.go
+++ b/ytypes/util_test.go
@@ -22,6 +22,8 @@ import (
 	"github.com/openconfig/ygot/ygot"
 )
 
+//lint:file-ignore U1000 Ignore all unused code, it represents generated code.
+
 func TestYangBuiltinTypeToGoType(t *testing.T) {
 	tests := []struct {
 		desc  string