mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Enable Gofmt Linting via Golang-CI Lint to Allow for Generic Code in Prysm (#11205)
* converting to generic * enable gofmt linting * enable gofmt Co-authored-by: James He <james@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
25d87dd27b
commit
ed07359573
5
.github/actions/gofmt/Dockerfile
vendored
5
.github/actions/gofmt/Dockerfile
vendored
@ -1,5 +0,0 @@
|
||||
FROM cytopia/gofmt
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
12
.github/actions/gofmt/action.yml
vendored
12
.github/actions/gofmt/action.yml
vendored
@ -1,12 +0,0 @@
|
||||
name: 'Gofmt checker'
|
||||
description: 'Checks that all project files have been properly formatted.'
|
||||
inputs:
|
||||
path:
|
||||
description: 'Path to check'
|
||||
required: true
|
||||
default: './'
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.path }}
|
15
.github/actions/gofmt/entrypoint.sh
vendored
15
.github/actions/gofmt/entrypoint.sh
vendored
@ -1,15 +0,0 @@
|
||||
#!/bin/sh -l
|
||||
set -e
|
||||
|
||||
cd $GITHUB_WORKSPACE
|
||||
|
||||
# Check if any files are not formatted.
|
||||
nonformatted="$(gofmt -l $1 2>&1)"
|
||||
|
||||
# Return if `go fmt` passes.
|
||||
[ -z "$nonformatted" ] && exit 0
|
||||
|
||||
# Notify of issues with formatting.
|
||||
echo "Following files need to be properly formatted:"
|
||||
echo "$nonformatted"
|
||||
exit 1
|
6
.github/workflows/go.yml
vendored
6
.github/workflows/go.yml
vendored
@ -18,12 +18,6 @@ jobs:
|
||||
id: gomodtidy
|
||||
uses: ./.github/actions/gomodtidy
|
||||
|
||||
- name: Gofmt checker
|
||||
id: gofmt
|
||||
uses: ./.github/actions/gofmt
|
||||
with:
|
||||
path: ./
|
||||
|
||||
- name: GoImports checker
|
||||
id: goimports
|
||||
uses: Jerome1337/goimports-action@v1.0.2
|
||||
|
@ -11,6 +11,7 @@ run:
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- gofmt
|
||||
- deadcode
|
||||
- errcheck
|
||||
- gosimple
|
||||
|
@ -365,12 +365,12 @@ func IsInSlots(a types.Slot, b []types.Slot) bool {
|
||||
}
|
||||
|
||||
// Unique returns an array with duplicates filtered based on the type given
|
||||
func Unique(a []string) []string {
|
||||
func Unique[T comparable](a []T) []T {
|
||||
if a == nil || len(a) <= 1 {
|
||||
return a
|
||||
}
|
||||
found := map[string]bool{}
|
||||
result := make([]string, len(a))
|
||||
found := map[T]bool{}
|
||||
result := make([]T, len(a))
|
||||
end := 0
|
||||
for i := 0; i < len(a); i++ {
|
||||
if !found[a[i]] {
|
||||
|
@ -591,7 +591,11 @@ func TestIsInSlots(t *testing.T) {
|
||||
|
||||
func TestUnique(t *testing.T) {
|
||||
t.Run("string", func(t *testing.T) {
|
||||
result := slice.Unique([]string{"a", "b", "a"})
|
||||
result := slice.Unique[string]([]string{"a", "b", "a"})
|
||||
require.DeepEqual(t, []string{"a", "b"}, result)
|
||||
})
|
||||
t.Run("uint64", func(t *testing.T) {
|
||||
result := slice.Unique[uint64]([]uint64{1, 2, 1})
|
||||
require.DeepEqual(t, []uint64{1, 2}, result)
|
||||
})
|
||||
}
|
||||
|
@ -468,7 +468,7 @@ func web3SignerConfig(cliCtx *cli.Context) (*remoteweb3signer.SetupConfig, error
|
||||
pks = publicKeysSlice
|
||||
}
|
||||
if len(pks) > 0 {
|
||||
pks = slice.Unique(pks)
|
||||
pks = slice.Unique[string](pks)
|
||||
var validatorKeys [][48]byte
|
||||
for _, key := range pks {
|
||||
decodedKey, decodeErr := hexutil.Decode(key)
|
||||
|
Loading…
Reference in New Issue
Block a user