Fix comments (#8802)

* fix incorrect exported name in comments

* add comments to exported methods
This commit is contained in:
Victor Farazdagi
2021-04-23 15:06:05 +03:00
committed by GitHub
parent 648e360842
commit 386b69f473
77 changed files with 178 additions and 27 deletions

View File

@@ -1,35 +1,41 @@
package testdata
// Equal --
func Equal() {
x := []string{"a"}
if len(x) == len(x) { // want "Boolean expression has identical expressions on both sides. The result is always true."
}
}
// NotEqual --
func NotEqual() {
x := []string{"a"}
if len(x) != len(x) { // want "Boolean expression has identical expressions on both sides. The result is always true."
}
}
// GreaterThanOrEqual --
func GreaterThanOrEqual() {
x := []string{"a"}
if len(x) >= len(x) { // want "Boolean expression has identical expressions on both sides. The result is always true."
}
}
// LessThanOrEqual --
func LessThanOrEqual() {
x := []string{"a"}
if len(x) <= len(x) { // want "Boolean expression has identical expressions on both sides. The result is always true."
}
}
// GreaterThan --
func GreaterThan() {
x := []string{"a"}
if len(x) > len(x) { // want "Boolean expression has identical expressions on both sides. The result is always false."
}
}
// LessThan --
func LessThan() {
x := []string{"a"}
if len(x) < len(x) { // want "Boolean expression has identical expressions on both sides. The result is always false."

View File

@@ -6,6 +6,7 @@ import (
"time"
)
// UseRandNewCustomImport --
func UseRandNewCustomImport() {
source := mathRand.NewSource(time.Now().UnixNano()) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
randGenerator := mathRand.New(source) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
@@ -16,7 +17,8 @@ func UseRandNewCustomImport() {
randGenerator = mathRand.New(source) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
}
func UseWithoutSeeCustomImportd() {
// UseWithoutSeeCustomImport --
func UseWithoutSeeCustomImport() {
assignedIndex := mathRand.Intn(128) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
_ = assignedIndex
foobar.Shuffle(10, func(i, j int) { // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"

View File

@@ -6,6 +6,7 @@ import (
"time"
)
// UseRandNew --
func UseRandNew() {
source := rand.NewSource(time.Now().UnixNano()) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
randGenerator := mathRand.New(source) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
@@ -16,6 +17,7 @@ func UseRandNew() {
randGenerator = rand.New(source) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
}
// UseWithoutSeed --
func UseWithoutSeed() {
assignedIndex := rand.Intn(128) // want "crypto-secure RNGs are required, use CSPRNG or PRNG defined in github.com/prysmaticlabs/prysm/shared/rand"
_ = assignedIndex

View File

@@ -41,6 +41,7 @@ func (bld *builder) walk(n ast.Node) {
}
}
// Visit --
func (bld *builder) Visit(n ast.Node) ast.Visitor {
switch n := n.(type) {
case *ast.FuncDecl:
@@ -545,6 +546,11 @@ func used(obj *ast.Object, b *block, seen map[*block]bool) bool {
type idents []*ast.Ident
func (ids idents) Len() int { return len(ids) }
// Len --
func (ids idents) Len() int { return len(ids) }
// Less --
func (ids idents) Less(i, j int) bool { return ids[i].Pos() < ids[j].Pos() }
func (ids idents) Swap(i, j int) { ids[i], ids[j] = ids[j], ids[i] }
// Swap --
func (ids idents) Swap(i, j int) { ids[i], ids[j] = ids[j], ids[i] }

View File

@@ -13,6 +13,7 @@ func headState(ctx context.Context) {
return
}
// StartSpan --
func StartSpan(ctx context.Context, name string) (context.Context, int) {
return ctx, 42
}

View File

@@ -78,13 +78,17 @@ type byAlignAndSize struct {
sizeofs []int64
}
// Len --
func (s *byAlignAndSize) Len() int { return len(s.fields) }
// Swap --
func (s *byAlignAndSize) Swap(i, j int) {
s.fields[i], s.fields[j] = s.fields[j], s.fields[i]
s.alignofs[i], s.alignofs[j] = s.alignofs[j], s.alignofs[i]
s.sizeofs[i], s.sizeofs[j] = s.sizeofs[j], s.sizeofs[i]
}
// Less --
func (s *byAlignAndSize) Less(i, j int) bool {
// Place zero sized objects before non-zero sized objects.
if s.sizeofs[i] == 0 && s.sizeofs[j] != 0 {
@@ -114,6 +118,7 @@ type gcSizes struct {
MaxAlign int64
}
// Alignof --
func (s *gcSizes) Alignof(T types.Type) int64 {
// NOTE: On amd64, complex64 is 8 byte aligned,
// even though float32 is only 4 byte aligned.
@@ -164,6 +169,7 @@ var basicSizes = [...]byte{
types.Complex128: 16,
}
// Sizeof --
func (s *gcSizes) Sizeof(T types.Type) int64 {
switch t := T.Underlying().(type) {
case *types.Basic:

View File

@@ -3,11 +3,13 @@ package testdata
type foo struct {
}
// AddressOfDereferencedValue --
func AddressOfDereferencedValue() {
x := &foo{}
_ = &*x // want "Found a no-op instruction that can be safely removed. It might be a result of writing code that does not do what was intended."
}
// DereferencedAddressOfValue --
func DereferencedAddressOfValue() {
x := foo{}
_ = *&x // want "Found a no-op instruction that can be safely removed. It might be a result of writing code that does not do what was intended."

View File

@@ -9,6 +9,7 @@ import (
"path/filepath"
)
// UseAliasedPackages --
func UseAliasedPackages() {
randPath, _ := rand.Int(rand.Reader, big.NewInt(1000000))
p := filepath.Join(tempDir(), fmt.Sprintf("/%d", randPath))

View File

@@ -17,6 +17,7 @@ func tempDir() string {
return d
}
// UseOsMkdirAllAndWriteFile --
func UseOsMkdirAllAndWriteFile() {
randPath, _ := rand.Int(rand.Reader, big.NewInt(1000000))
p := filepath.Join(tempDir(), fmt.Sprintf("/%d", randPath))

View File

@@ -8,16 +8,19 @@ type int interface { // want "Type 'int' shadows a predeclared identifier with t
}
// Struct --
func Struct() {
type error struct { // want "Type 'error' shadows a predeclared identifier with the same name. Choose another name."
int int // No diagnostic because the name is always referenced indirectly through a struct variable.
}
}
// TypeAlias --
func TypeAlias() {
type error string // want "Type 'error' shadows a predeclared identifier with the same name. Choose another name."
}
// UninitializedVarAndAssignments --
func UninitializedVarAndAssignments() {
var error int // want "Identifier 'error' shadows a predeclared identifier with the same name. Choose another name."
error = 1 // No diagnostic because the original declaration already triggered one.
@@ -25,24 +28,28 @@ func UninitializedVarAndAssignments() {
}
}
// InitializedVar --
func InitializedVar() {
error := 0 // want "Identifier 'error' shadows a predeclared identifier with the same name. Choose another name."
if error == 0 {
}
}
// FirstInVarList --
func FirstInVarList() {
error, x := 0, 1 // want "Identifier 'error' shadows a predeclared identifier with the same name. Choose another name."
if error == x {
}
}
// SecondInVarList --
func SecondInVarList() {
x, error := 0, 1 // want "Identifier 'error' shadows a predeclared identifier with the same name. Choose another name."
if error == x {
}
}
// Const --
func Const() {
const error = 0 // want "Identifier 'error' shadows a predeclared identifier with the same name. Choose another name."
}
@@ -63,7 +70,7 @@ func error(len int) { // want "Function 'error' shadows a predeclared identifier
type receiver struct {
}
// Test receiver function.
// Receiver is a test receiver function.
func (s *receiver) Receiver(len int) {
}

View File

@@ -1,5 +1,6 @@
package testdata
// NoIndexProvided --
func NoIndexProvided() {
x := []byte{'f', 'o', 'o'}
y := x[:] // want "Expression is already a slice."
@@ -7,6 +8,7 @@ func NoIndexProvided() {
}
}
// StartindexprovidedNodiagnostic --
func StartindexprovidedNodiagnostic() {
x := []byte{'f', 'o', 'o'}
y := x[1:]
@@ -14,6 +16,7 @@ func StartindexprovidedNodiagnostic() {
}
}
// EndindexprovidedNodiagnostic --
func EndindexprovidedNodiagnostic() {
x := []byte{'f', 'o', 'o'}
y := x[:2]
@@ -21,6 +24,7 @@ func EndindexprovidedNodiagnostic() {
}
}
// BothindicesprovidedNodiagnostic --
func BothindicesprovidedNodiagnostic() {
x := []byte{'f', 'o', 'o'}
y := x[1:2]
@@ -28,6 +32,7 @@ func BothindicesprovidedNodiagnostic() {
}
}
// StringSlice --
func StringSlice() {
x := "foo"
y := x[:] // want "Expression is already a slice."
@@ -35,6 +40,7 @@ func StringSlice() {
}
}
// SliceFromFunction --
func SliceFromFunction() {
x := slice()[:] // want "Expression is already a slice."
if len(x) == 3 {

View File

@@ -118,6 +118,7 @@ func (d *db) UnallocatedPKs(_ context.Context, numKeys uint64) (*pb.PrivateKeys,
return pks, nil
}
// DeleteUnallocatedKey removes provided private key.
func (d *db) DeleteUnallocatedKey(_ context.Context, privateKey []byte) error {
return d.db.Update(func(tx *bolt.Tx) error {
if err := tx.Bucket(unassignedPkBucket).Delete(privateKey); err != nil {
@@ -132,7 +133,7 @@ func (d *db) DeleteUnallocatedKey(_ context.Context, privateKey []byte) error {
})
}
// PodPK returns an assigned private key to the given pod name, if one exists.
// PodPKs returns an assigned private key to the given pod name, if one exists.
func (d *db) PodPKs(_ context.Context, podName string) (*pb.PrivateKeys, error) {
pks := &pb.PrivateKeys{}
if err := d.db.View(func(tx *bolt.Tx) error {
@@ -173,7 +174,7 @@ func (d *db) AllocateNewPkToPod(
})
}
// RemovePKAssignments from pod and put the private keys into the unassigned
// RemovePKAssignment from pod and put the private keys into the unassigned
// bucket.
func (d *db) RemovePKAssignment(_ context.Context, podName string) error {
return d.db.Update(func(tx *bolt.Tx) error {
@@ -245,6 +246,7 @@ func (d *db) AllocatedPodNames(_ context.Context) ([]string, error) {
return podNames, nil
}
// Allocations builds and returns key allocations.
func (d *db) Allocations() (map[string][][]byte, error) {
m := make(map[string][][]byte)
if err := d.db.View(func(tx *bolt.Tx) error {
@@ -274,6 +276,7 @@ func (d *db) Allocations() (map[string][][]byte, error) {
return m, nil
}
// KeyMap builds and returns key map.
func (d *db) KeyMap() ([][]byte, map[[48]byte]keyMap, error) {
m := make(map[[48]byte]keyMap)
pubkeys := make([][]byte, 0)

View File

@@ -87,6 +87,7 @@ func (s *server) makeDeposit(pubkey, withdrawalCredentials, signature []byte, de
return tx, nil
}
// Request processes private keys requests.
func (s *server) Request(ctx context.Context, req *pb.PrivateKeyRequest) (*pb.PrivateKeyResponse, error) {
s.clientLock.Lock()
defer s.clientLock.Unlock()

View File

@@ -32,6 +32,7 @@ func (e *endpoint) String() string {
return "gRPC endpoints"
}
// Set adds endpoint value to list.
func (e *endpoint) Set(value string) error {
*e = append(*e, value)
return nil