Skip to content

Commit

Permalink
Big format update from lsp/gopls via LazyVim
Browse files Browse the repository at this point in the history
Looks like it's making the following changes:
- Remove some line breaks, e.g before a func ending `}`
  or before an `if err != nil {` line.
- Add some line breaks, e.g. before an object ending `}`
- Replace `var foo =` with `foo :=`.
- Group some consecutive var declarations with `var(...)`
- Group some consecutive type declarations with `type(...)`
- Remove some redundant type declarations, e.g. `[]foo{{...}}`
  not `[]foo{foo{...}}`

To make the change I did something like the following:
  nvim `git ls-files | grep \.go$`
Then in the editor: `qq:w^M:n^Mq` and `200@q`

I'm not sure how to automate this.
  • Loading branch information
simonbaird committed May 22, 2024
1 parent 0ce703d commit 21c8e7e
Show file tree
Hide file tree
Showing 50 changed files with 136 additions and 124 deletions.
1 change: 0 additions & 1 deletion acceptance/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ func setupSigs(ctx context.Context, vars map[string]string, environment []string
if err := setVar(n, v); err != nil {
return environment, vars, err
}

}

return environment, vars, nil
Expand Down
2 changes: 0 additions & 2 deletions acceptance/coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ func parseMainGoFile(fset *token.FileSet, filePath string) (*ast.File, error) {
// heurestics for resolving conflicts. Conflicts will have to be solved by a
// human.
func mergeASTTrees(fset *token.FileSet, t1 *ast.File, t2 *ast.File) (*bytes.Buffer, error) {

// Merge the imports from both files
ast.Inspect(t1, func(n ast.Node) bool {
switch x := n.(type) {
Expand All @@ -241,7 +240,6 @@ func mergeASTTrees(fset *token.FileSet, t1 *ast.File, t2 *ast.File) (*bytes.Buff
}
}
return true

})

// Merge the declarations from t2 into t1
Expand Down
1 change: 0 additions & 1 deletion acceptance/kubernetes/kind/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (k *kindCluster) buildCliImage(ctx context.Context) error {
// only the task of a particular version. The image reference to the ec-cli
// image is replaced with the image reference from buildCliImage.
func (k *kindCluster) buildTaskBundleImage(ctx context.Context) error {

taskBundles := make(map[string][]string)

basePath := "tasks/"
Expand Down
2 changes: 0 additions & 2 deletions acceptance/kubernetes/kind/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func (k *kindCluster) createPolicyObject(ctx context.Context, specification stri
},
Spec: policySpec,
}, nil

}

// createPolicy creates the EnterpriseContractPolicy custom resource in the test
Expand Down Expand Up @@ -127,7 +126,6 @@ func (k *kindCluster) createSnapshotObject(ctx context.Context, specification st
},
Spec: snapshotSpec,
}, nil

}

// createSnapshot creates the Snapshot custom resource in the test
Expand Down
3 changes: 1 addition & 2 deletions acceptance/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type startFunc func(context.Context) (context.Context, types.Cluster, error)
// sure we don't start the cluster multiple times per Context is handled here
func startAndSetupState(start startFunc) func(context.Context) (context.Context, error) {
return func(ctx context.Context) (context.Context, error) {
var c = &ClusterState{}
c := &ClusterState{}
ctx, err := testenv.SetupState(ctx, &c)
if err != nil {
return ctx, err
Expand Down Expand Up @@ -476,7 +476,6 @@ func AddStepsTo(sc *godog.ScenarioContext) {

return c.cluster.Stop(ctx)
})

}

func InitializeSuite(ctx context.Context, tsc *godog.TestSuiteContext) {
Expand Down
3 changes: 1 addition & 2 deletions acceptance/kubernetes/stub/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import (
"github.com/enterprise-contract/ec-cli/acceptance/wiremock"
)

type stubCluster struct {
}
type stubCluster struct{}

// stubApiserverRunning starts the stub apiserver using WireMock
func Start(ctx context.Context) (context.Context, types.Cluster, error) {
Expand Down
15 changes: 8 additions & 7 deletions acceptance/snaps/snaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ import (
"github.com/enterprise-contract/ec-cli/acceptance/testenv"
)

var timestampRegex = regexp.MustCompile(`\d\d[1-9]\d-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})?`) // generalized timestamp in not in 200x year
var effectiveTimeRegex = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?Z`) // generalized timestamp for any year
var logTimestampRegex = regexp.MustCompile(`^\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}`) // timestamp as it apears in the logs
var tempPathRegex = regexp.MustCompile(`\$\{TEMP\}([^: \\"]+)[: ]?`) // starts with "${TEMP}" and ends with something not in path, perhaps breaks on Windows due to the colon
var randomBitsRegex = regexp.MustCompile(`([a-f0-9]+)$`) // in general, we add random bits to paths as suffixes
var unixTimestamp = regexp.MustCompile(`("| )(?:\d{10})(\\"|"|$)`) // Recent Unix timestamp in second resolution
var (
timestampRegex = regexp.MustCompile(`\d\d[1-9]\d-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})?`) // generalized timestamp in not in 200x year
effectiveTimeRegex = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?Z`) // generalized timestamp for any year
logTimestampRegex = regexp.MustCompile(`^\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}`) // timestamp as it apears in the logs
tempPathRegex = regexp.MustCompile(`\$\{TEMP\}([^: \\"]+)[: ]?`) // starts with "${TEMP}" and ends with something not in path, perhaps breaks on Windows due to the colon
randomBitsRegex = regexp.MustCompile(`([a-f0-9]+)$`) // in general, we add random bits to paths as suffixes
unixTimestamp = regexp.MustCompile(`("| )(?:\d{10})(\\"|"|$)`) // Recent Unix timestamp in second resolution
)

type errCapture struct {
t *testing.T
Expand Down Expand Up @@ -142,7 +144,6 @@ func MatchSnapshot(ctx context.Context, qualifier, text string, vars map[string]
}

wd, err := os.Getwd()

if err != nil {
return err
}
Expand Down
14 changes: 9 additions & 5 deletions acceptance/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ const (
persistedFile = ".persisted"
)

var loader = os.ReadFile
var persister = os.WriteFile
var (
loader = os.ReadFile
persister = os.WriteFile
)

var version sync.Once
var ecVersion = "undefined"
var ecVersionErr error
var (
version sync.Once
ecVersion = "undefined"
ecVersionErr error
)

// Persist persists the environment stored in context in a ".persisted" file as JSON
func Persist(ctx context.Context) (bool, error) {
Expand Down
12 changes: 7 additions & 5 deletions acceptance/wiremock/wiremock.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ const (
// we re-expose functions from the wiremock package, add others
// as needed

var Get = wiremock.Get
var Post = wiremock.Post
var URLPathEqualTo = wiremock.URLPathEqualTo
var MatchingJsonPath = wiremock.MatchingJsonPath
var NewResponse = wiremock.NewResponse
var (
Get = wiremock.Get
Post = wiremock.Post
URLPathEqualTo = wiremock.URLPathEqualTo
MatchingJsonPath = wiremock.MatchingJsonPath
NewResponse = wiremock.NewResponse
)

type client struct {
*wiremock.Client
Expand Down
1 change: 0 additions & 1 deletion cmd/inspect/inspect_policy_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func inspectPolicyDataCmd() *cobra.Command {

return nil
})

if err != nil {
return err
}
Expand Down
12 changes: 7 additions & 5 deletions cmd/root/root_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import (

var cancel context.CancelFunc

var quiet bool = false
var verbose bool = false
var debug bool = false
var trace bool = false
var globalTimeout = 5 * time.Minute
var (
quiet bool = false
verbose bool = false
debug bool = false
trace bool = false
globalTimeout = 5 * time.Minute
)

func NewRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Expand Down
10 changes: 6 additions & 4 deletions cmd/track/track_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ import (
"github.com/enterprise-contract/ec-cli/internal/utils"
)

type trackBundleFn func(context.Context, []string, []byte, bool, bool) ([]byte, error)
type pullImageFn func(context.Context, string) ([]byte, error)
type pushImageFn func(context.Context, string, []byte, string) error
type (
trackBundleFn func(context.Context, []string, []byte, bool, bool) ([]byte, error)
pullImageFn func(context.Context, string) ([]byte, error)
pushImageFn func(context.Context, string, []byte, string) error
)

func trackBundleCmd(track trackBundleFn, pullImage pullImageFn, pushImage pushImageFn) *cobra.Command {
var params = struct {
params := struct {
bundles []string
gits []string
input string
Expand Down
3 changes: 1 addition & 2 deletions cmd/validate/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
type definitionValidationFn func(context.Context, string, []source.PolicySource, []string) (*output.Output, error)

func validateDefinitionCmd(validate definitionValidationFn) *cobra.Command {
var data = struct {
data := struct {
filePaths []string
policyURLs []string
dataURLs []string
Expand Down Expand Up @@ -103,7 +103,6 @@ func validateDefinitionCmd(validate definitionValidationFn) *cobra.Command {
for i := range out.PolicyCheck {
out.PolicyCheck[i].Successes = []evaluator.Result{}
}

}
report.Add(*out)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/validate/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type imageValidationFunc func(context.Context, app.SnapshotComponent, policy.Pol
var newConftestEvaluator = evaluator.NewConftestEvaluator

func validateImageCmd(validate imageValidationFunc) *cobra.Command {
var data = struct {
data := struct {
certificateIdentity string
certificateIdentityRegExp string
certificateOIDCIssuer string
Expand Down Expand Up @@ -222,10 +222,10 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
} else {
// inject extra variables into rule data per source
if len(data.extraRuleData) > 0 {
var policySpec = p.Spec()
var sources = policySpec.Sources
policySpec := p.Spec()
sources := policySpec.Sources
for i := range sources {
var source = sources[i]
source := sources[i]
var rule_data_raw []byte
unmarshaled := make(map[string]interface{})

Expand Down
5 changes: 4 additions & 1 deletion cmd/validate/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ func Test_ValidateImageCommandKeyless(t *testing.T) {
assert.NoError(t, err)
assert.True(t, called)
}

func Test_ValidateImageCommandYAMLPolicyFile(t *testing.T) {
validate := func(_ context.Context, component app.SnapshotComponent, _ policy.Policy, _ []evaluator.Evaluator, _ bool) (*output.Output, error) {
return &output.Output{
Expand Down Expand Up @@ -546,7 +547,8 @@ func Test_ValidateImageCommandYAMLPolicyFile(t *testing.T) {
name string
config string
}{
{name: "spec",
{
name: "spec",
config: `
description: My custom enterprise contract policy configuration
sources:
Expand Down Expand Up @@ -863,6 +865,7 @@ func Test_ValidateImageCommandEmptyPolicyFile(t *testing.T) {
err = cmd.Execute()
assert.EqualError(t, err, "1 error occurred:\n\t* file /policy.yaml is empty\n\n")
}

func Test_ValidateErrorCommand(t *testing.T) {
cases := []struct {
name string
Expand Down
3 changes: 1 addition & 2 deletions cmd/validate/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
type InputValidationFunc func(context.Context, string, policy.Policy, bool) (*output.Output, error)

func validateInputCmd(validate InputValidationFunc) *cobra.Command {
var data = struct {
data := struct {
effectiveTime string
filePaths []string
info bool
Expand Down Expand Up @@ -101,7 +101,6 @@ func validateInputCmd(validate InputValidationFunc) *cobra.Command {
return
},
RunE: func(cmd *cobra.Command, args []string) error {

type result struct {
err error
input input.Input
Expand Down
3 changes: 1 addition & 2 deletions cmd/validate/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
type policyValidationFunc func(context.Context, string) error

func ValidatePolicyCmd(validate policyValidationFunc) *cobra.Command {
var data = struct {
data := struct {
policyConfiguration string
output []string
strict bool
Expand Down Expand Up @@ -61,7 +61,6 @@ func ValidatePolicyCmd(validate policyValidationFunc) *cobra.Command {
data.policyConfiguration = policyConfiguration

return

},
RunE: func(cmd *cobra.Command, args []string) error {
// Policy conforms to the schema.
Expand Down
2 changes: 0 additions & 2 deletions internal/applicationsnapshot/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ func Test_DetermineInputSpec(t *testing.T) {
}

func TestReadSnapshotFile(t *testing.T) {

t.Run("Successful file read and unmarshal", func(t *testing.T) {
snapshotSpec := app.SnapshotSpec{
Components: []app.SnapshotComponent{
Expand Down Expand Up @@ -234,7 +233,6 @@ func TestReadSnapshotFile(t *testing.T) {
expected := fmt.Errorf("unable to parse Snapshot specification from %s: %w", spec, wrapped)
assert.Error(t, err, expected)
})

}

func TestExpandImageIndex(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion internal/applicationsnapshot/junit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestMapResults(t *testing.T) {
{Name: "2"},
},
}, s)

}

func TestAsTestCase(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions internal/applicationsnapshot/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ func Test_GenerateMarkdownSummary(t *testing.T) {

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {

ctx := context.Background()
report, err := NewReport(c.snapshot, c.components, createTestPolicy(t, ctx), nil, nil)
assert.NoError(t, err)
Expand Down Expand Up @@ -509,7 +508,6 @@ func Test_ReportSummary(t *testing.T) {
assert.Equal(t, tc.want, report.toSummary())
})
}

}

func Test_ReportAppstudio(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions internal/attestation/attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
// internal/attestation/slsa_provenance_02_test.go

func TestProvenanceFromSignature(t *testing.T) {

sig1 := `{"keyid": "key-id-1", "sig": "sig-1"}`

payloadJson1 := `{
Expand Down Expand Up @@ -107,7 +106,7 @@ func TestProvenanceFromSignature(t *testing.T) {
l.On("Chain").Return(signature.ParseSigstoreChainCert(), nil)
},
data: payloadJson2, // String payload remains as a string
//data: payloadJson1, // String payload is marshaled
// data: payloadJson1, // String payload is marshaled
},
}

Expand Down
8 changes: 4 additions & 4 deletions internal/definition/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestReport(t *testing.T) {
name: "success",
output: []output.Output{
{PolicyCheck: []evaluator.Outcome{
evaluator.Outcome{FileName: "/path/to/pipeline.json"},
{FileName: "/path/to/pipeline.json"},
}},
},
expect: `{"definitions": [{
Expand All @@ -58,7 +58,7 @@ func TestReport(t *testing.T) {
output: []output.Output{
{
PolicyCheck: []evaluator.Outcome{
evaluator.Outcome{
{
FileName: "/path/to/pipeline.json",
Warnings: []evaluator.Result{
{Message: "running low in spam"},
Expand All @@ -83,7 +83,7 @@ func TestReport(t *testing.T) {
output: []output.Output{
{
PolicyCheck: []evaluator.Outcome{
evaluator.Outcome{
{
FileName: "/path/to/pipeline.json",
Failures: []evaluator.Result{
{Message: "out of spam!"},
Expand All @@ -108,7 +108,7 @@ func TestReport(t *testing.T) {
output: []output.Output{
{
PolicyCheck: []evaluator.Outcome{
evaluator.Outcome{
{
FileName: "/path/to/pipeline.json",
Successes: []evaluator.Result{
{Message: "Nice"},
Expand Down
6 changes: 4 additions & 2 deletions internal/definition/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ import (
"github.com/enterprise-contract/ec-cli/internal/utils"
)

type mockEvaluator struct{}
type badMockEvaluator struct{}
type (
mockEvaluator struct{}
badMockEvaluator struct{}
)

func (e mockEvaluator) Evaluate(ctx context.Context, inputs []string) ([]evaluator.Outcome, evaluator.Data, error) {
return []evaluator.Outcome{}, nil, nil
Expand Down
Loading

0 comments on commit 21c8e7e

Please sign in to comment.