From 4b3847f3a84fbb73d8269b1ccaf25b73e8bdca24 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Wed, 7 Sep 2022 20:35:30 -0400 Subject: [PATCH] lint: `gofmt -w -s .` Signed-off-by: Rui Chen --- cmd/help_fmt.go | 6 ++- main.go | 4 +- .../events/events_controller_e2e_test.go | 9 +++-- server/core/config/raw/step.go | 24 ++++++----- server/core/config/raw/workflow_step.go | 2 +- server/core/locking/locking.go | 4 +- server/core/runtime/policy/conftest_client.go | 3 +- server/core/runtime/runtime.go | 3 +- server/core/terraform/terraform_client.go | 13 +++--- server/events/comment_parser.go | 13 +++--- server/events/models/models.go | 12 ++++-- server/events/vcs/azuredevops_client.go | 5 ++- .../webhooks/mocks/mock_slack_client.go | 2 - server/events/working_dir.go | 2 +- server/jobs/project_command_output_handler.go | 4 +- server/logging/simple_logger.go | 4 +- server/recovery/recovery.go | 4 +- server/static/bindata_assetfs.go | 40 ++++++++++--------- testdrive/testdrive.go | 4 +- testing/temp_files.go | 37 ++++++++--------- 20 files changed, 111 insertions(+), 84 deletions(-) diff --git a/cmd/help_fmt.go b/cmd/help_fmt.go index e13d47d617..b4d5608270 100644 --- a/cmd/help_fmt.go +++ b/cmd/help_fmt.go @@ -11,8 +11,10 @@ import ( // usageTmpl returns a cobra-compatible usage template that will be printed // during the help output. // This template prints help like: -// --name= -// +// +// --name= +// +// // We use it over the default template so that the output it easier to read. func usageTmpl(stringFlags map[string]stringFlag, intFlags map[string]intFlag, boolFlags map[string]boolFlag) string { var flagNames []string diff --git a/main.go b/main.go index 8af908c476..764bdd8617 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,9 @@ // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an AS IS BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/server/controllers/events/events_controller_e2e_test.go b/server/controllers/events/events_controller_e2e_test.go index 7ccab8c9a2..6d56f52f28 100644 --- a/server/controllers/events/events_controller_e2e_test.go +++ b/server/controllers/events/events_controller_e2e_test.go @@ -1373,11 +1373,12 @@ func ensureRunning014(t *testing.T) { } // versionRegex extracts the version from `terraform version` output. -// Terraform v0.12.0-alpha4 (2c36829d3265661d8edbd5014de8090ea7e2a076) -// => 0.12.0-alpha4 // -// Terraform v0.11.10 -// => 0.11.10 +// Terraform v0.12.0-alpha4 (2c36829d3265661d8edbd5014de8090ea7e2a076) +// => 0.12.0-alpha4 +// +// Terraform v0.11.10 +// => 0.11.10 var versionRegex = regexp.MustCompile("Terraform v(.*?)(\\s.*)?\n") var versionConftestRegex = regexp.MustCompile("Version: (.*?)(\\s.*)?\n") diff --git a/server/core/config/raw/step.go b/server/core/config/raw/step.go index 28e860fd25..a32a0e60c4 100644 --- a/server/core/config/raw/step.go +++ b/server/core/config/raw/step.go @@ -28,19 +28,23 @@ const ( // Step represents a single action/command to perform. In YAML, it can be set as // 1. A single string for a built-in command: -// - init -// - plan -// - policy_check +// - init +// - plan +// - policy_check +// // 2. A map for an env step with name and command or value -// - env: -// name: test -// command: echo 312 -// value: value +// - env: +// name: test +// command: echo 312 +// value: value +// // 3. A map for a built-in command and extra_args: -// - plan: -// extra_args: [-var-file=staging.tfvars] +// - plan: +// extra_args: [-var-file=staging.tfvars] +// // 4. A map for a custom run command: -// - run: my custom command +// - run: my custom command +// // Here we parse step in the most generic fashion possible. See fields for more // details. type Step struct { diff --git a/server/core/config/raw/workflow_step.go b/server/core/config/raw/workflow_step.go index 5e89405c63..32218468ac 100644 --- a/server/core/config/raw/workflow_step.go +++ b/server/core/config/raw/workflow_step.go @@ -14,7 +14,7 @@ import ( // WorkflowHook represents a single action/command to perform. In YAML, // it can be set as // A map for a custom run commands: -// - run: my custom command +// - run: my custom command type WorkflowHook struct { StringVal map[string]string } diff --git a/server/core/locking/locking.go b/server/core/locking/locking.go index f001b2b2ae..c0e34a9900 100644 --- a/server/core/locking/locking.go +++ b/server/core/locking/locking.go @@ -3,7 +3,9 @@ // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an AS IS BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/server/core/runtime/policy/conftest_client.go b/server/core/runtime/policy/conftest_client.go index 16a9329776..6731983766 100644 --- a/server/core/runtime/policy/conftest_client.go +++ b/server/core/runtime/policy/conftest_client.go @@ -69,8 +69,9 @@ func (c ConftestTestCommandArgs) build() ([]string, error) { return commandArgs, nil } -//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_conftest_client.go SourceResolver // SourceResolver resolves the policy set to a local fs path +// +//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_conftest_client.go SourceResolver type SourceResolver interface { Resolve(policySet valid.PolicySet) (string, error) } diff --git a/server/core/runtime/runtime.go b/server/core/runtime/runtime.go index c82b9bc8f9..3104fddec0 100644 --- a/server/core/runtime/runtime.go +++ b/server/core/runtime/runtime.go @@ -50,8 +50,9 @@ type StatusUpdater interface { UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string) error } -//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_runner.go Runner // Runner mirrors events.StepRunner as a way to bring it into this package +// +//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_runner.go Runner type Runner interface { Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) } diff --git a/server/core/terraform/terraform_client.go b/server/core/terraform/terraform_client.go index b359b841e4..d2abe26145 100644 --- a/server/core/terraform/terraform_client.go +++ b/server/core/terraform/terraform_client.go @@ -3,7 +3,9 @@ // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an AS IS BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -90,11 +92,12 @@ type Downloader interface { } // versionRegex extracts the version from `terraform version` output. -// Terraform v0.12.0-alpha4 (2c36829d3265661d8edbd5014de8090ea7e2a076) -// => 0.12.0-alpha4 // -// Terraform v0.11.10 -// => 0.11.10 +// Terraform v0.12.0-alpha4 (2c36829d3265661d8edbd5014de8090ea7e2a076) +// => 0.12.0-alpha4 +// +// Terraform v0.11.10 +// => 0.11.10 var versionRegex = regexp.MustCompile("Terraform v(.*?)(\\s.*)?\n") // NewClientWithDefaultVersion creates a new terraform client and pre-fetches the default version diff --git a/server/events/comment_parser.go b/server/events/comment_parser.go index 64fe841ddc..48af12d7bd 100644 --- a/server/events/comment_parser.go +++ b/server/events/comment_parser.go @@ -96,12 +96,12 @@ type CommentParseResult struct { // Parse parses the comment as an Atlantis command. // // Valid commands contain: -// - The initial "executable" name, 'run' or 'atlantis' or '@GithubUser' -// where GithubUser is the API user Atlantis is running as. -// - Then a command: 'plan', 'apply', 'unlock', 'version, 'approve_policies', -// or 'help'. -// - Then optional flags, then an optional separator '--' followed by optional -// extra flags to be appended to the terraform plan/apply command. +// - The initial "executable" name, 'run' or 'atlantis' or '@GithubUser' +// where GithubUser is the API user Atlantis is running as. +// - Then a command: 'plan', 'apply', 'unlock', 'version, 'approve_policies', +// or 'help'. +// - Then optional flags, then an optional separator '--' followed by optional +// extra flags to be appended to the terraform plan/apply command. // // Examples: // - atlantis help @@ -112,7 +112,6 @@ type CommentParseResult struct { // - atlantis unlock // - atlantis version // - atlantis approve_policies -// func (e *CommentParser) Parse(rawComment string, vcsHost models.VCSHostType) CommentParseResult { comment := strings.TrimSpace(rawComment) diff --git a/server/events/models/models.go b/server/events/models/models.go index 7da8b57b48..da007eb877 100644 --- a/server/events/models/models.go +++ b/server/events/models/models.go @@ -3,7 +3,9 @@ // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an AS IS BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -68,7 +70,8 @@ func (r Repo) ID() string { // NewRepo constructs a Repo object. repoFullName is the owner/repo form, // cloneURL can be with or without .git at the end // ex. https://github.com/runatlantis/atlantis.git OR -// https://github.com/runatlantis/atlantis +// +// https://github.com/runatlantis/atlantis func NewRepo(vcsHostType VCSHostType, repoFullName string, cloneURL string, vcsUser string, vcsToken string) (Repo, error) { if repoFullName == "" { return Repo{}, errors.New("repoFullName can't be empty") @@ -335,8 +338,9 @@ func NewVCSHostType(t string) (VCSHostType, error) { // name segments. If the repoFullName is malformed, may return empty // strings for owner or repo. // Ex. runatlantis/atlantis => (runatlantis, atlantis) -// gitlab/subgroup/runatlantis/atlantis => (gitlab/subgroup/runatlantis, atlantis) -// azuredevops/project/atlantis => (azuredevops/project, atlantis) +// +// gitlab/subgroup/runatlantis/atlantis => (gitlab/subgroup/runatlantis, atlantis) +// azuredevops/project/atlantis => (azuredevops/project, atlantis) func SplitRepoFullName(repoFullName string) (owner string, repo string) { lastSlashIdx := strings.LastIndex(repoFullName, "/") if lastSlashIdx == -1 || lastSlashIdx == len(repoFullName)-1 { diff --git a/server/events/vcs/azuredevops_client.go b/server/events/vcs/azuredevops_client.go index 531b99d2d0..c8aaa52b26 100644 --- a/server/events/vcs/azuredevops_client.go +++ b/server/events/vcs/azuredevops_client.go @@ -362,8 +362,9 @@ func (g *AzureDevopsClient) MarkdownPullLink(pull models.PullRequest) (string, e // repoFullName format owner/project/repo. // // Ex. runatlantis/atlantis => (runatlantis, atlantis) -// gitlab/subgroup/runatlantis/atlantis => (gitlab/subgroup/runatlantis, atlantis) -// azuredevops/project/atlantis => (azuredevops, project, atlantis) +// +// gitlab/subgroup/runatlantis/atlantis => (gitlab/subgroup/runatlantis, atlantis) +// azuredevops/project/atlantis => (azuredevops, project, atlantis) func SplitAzureDevopsRepoFullName(repoFullName string) (owner string, project string, repo string) { firstSlashIdx := strings.Index(repoFullName, "/") lastSlashIdx := strings.LastIndex(repoFullName, "/") diff --git a/server/events/webhooks/mocks/mock_slack_client.go b/server/events/webhooks/mocks/mock_slack_client.go index 29f82ed829..825d3387d2 100644 --- a/server/events/webhooks/mocks/mock_slack_client.go +++ b/server/events/webhooks/mocks/mock_slack_client.go @@ -142,8 +142,6 @@ func (c *MockSlackClient_TokenIsSet_OngoingVerification) GetCapturedArguments() func (c *MockSlackClient_TokenIsSet_OngoingVerification) GetAllCapturedArguments() { } - - func (verifier *VerifierMockSlackClient) PostMessage(channel string, applyResult webhooks.ApplyResult) *MockSlackClient_PostMessage_OngoingVerification { params := []pegomock.Param{channel, applyResult} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PostMessage", params, verifier.timeout) diff --git a/server/events/working_dir.go b/server/events/working_dir.go index 515f41af68..6ede427ff6 100644 --- a/server/events/working_dir.go +++ b/server/events/working_dir.go @@ -79,7 +79,7 @@ type FileWorkspace struct { // path to the root of the cloned repo. It also returns // a boolean indicating if we should warn users that the branch we're // merging into has been updated since we cloned it. -//If the repo already exists and is at +// If the repo already exists and is at // the right commit it does nothing. This is to support running commands in // multiple dirs of the same repo without deleting existing plans. func (w *FileWorkspace) Clone( diff --git a/server/jobs/project_command_output_handler.go b/server/jobs/project_command_output_handler.go index afd1837c6c..9b1e8ff131 100644 --- a/server/jobs/project_command_output_handler.go +++ b/server/jobs/project_command_output_handler.go @@ -179,7 +179,7 @@ func (p *AsyncProjectCommandOutputHandler) addChan(ch chan string, jobID string) p.receiverBuffersLock.Unlock() } -//Add log line to buffer and send to all current channels +// Add log line to buffer and send to all current channels func (p *AsyncProjectCommandOutputHandler) writeLogLine(jobID string, line string) { p.receiverBuffersLock.Lock() for ch := range p.receiverBuffers[jobID] { @@ -205,7 +205,7 @@ func (p *AsyncProjectCommandOutputHandler) writeLogLine(jobID string, line strin p.projectOutputBuffersLock.Unlock() } -//Remove channel, so client no longer receives Terraform output +// Remove channel, so client no longer receives Terraform output func (p *AsyncProjectCommandOutputHandler) Deregister(jobID string, ch chan string) { p.logger.Debug("Removing channel for %s", jobID) p.receiverBuffersLock.Lock() diff --git a/server/logging/simple_logger.go b/server/logging/simple_logger.go index e9e6eb1d35..d6271da150 100644 --- a/server/logging/simple_logger.go +++ b/server/logging/simple_logger.go @@ -3,7 +3,9 @@ // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an AS IS BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/server/recovery/recovery.go b/server/recovery/recovery.go index 1039ef7503..950ab7c883 100644 --- a/server/recovery/recovery.go +++ b/server/recovery/recovery.go @@ -3,7 +3,9 @@ // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an AS IS BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/server/static/bindata_assetfs.go b/server/static/bindata_assetfs.go index c4fdbfb5cc..978ea861ba 100644 --- a/server/static/bindata_assetfs.go +++ b/server/static/bindata_assetfs.go @@ -356,11 +356,13 @@ var _bindata = map[string]func() (*asset, error){ // directory embedded in the file by go-bindata. // For example if you run go-bindata on data/... and data contains the // following hierarchy: -// data/ -// foo.txt -// img/ -// a.png -// b.png +// +// data/ +// foo.txt +// img/ +// a.png +// b.png +// // then AssetDir("data") would return []string{"foo.txt", "img"} // AssetDir("data/img") would return []string{"a.png", "b.png"} // AssetDir("foo.txt") and AssetDir("notexist") would return an error @@ -393,22 +395,22 @@ type bintree struct { } var _bintree = &bintree{nil, map[string]*bintree{ - "static": &bintree{nil, map[string]*bintree{ - "css": &bintree{nil, map[string]*bintree{ - "custom.css": &bintree{staticCssCustomCss, map[string]*bintree{}}, - "normalize.css": &bintree{staticCssNormalizeCss, map[string]*bintree{}}, - "skeleton.css": &bintree{staticCssSkeletonCss, map[string]*bintree{}}, - "xterm.css": &bintree{staticCssXtermCss, map[string]*bintree{}}, + "static": {nil, map[string]*bintree{ + "css": {nil, map[string]*bintree{ + "custom.css": {staticCssCustomCss, map[string]*bintree{}}, + "normalize.css": {staticCssNormalizeCss, map[string]*bintree{}}, + "skeleton.css": {staticCssSkeletonCss, map[string]*bintree{}}, + "xterm.css": {staticCssXtermCss, map[string]*bintree{}}, }}, - "images": &bintree{nil, map[string]*bintree{ - "atlantis-icon.png": &bintree{staticImagesAtlantisIconPng, map[string]*bintree{}}, - "atlantis-icon_512.png": &bintree{staticImagesAtlantisIcon_512Png, map[string]*bintree{}}, + "images": {nil, map[string]*bintree{ + "atlantis-icon.png": {staticImagesAtlantisIconPng, map[string]*bintree{}}, + "atlantis-icon_512.png": {staticImagesAtlantisIcon_512Png, map[string]*bintree{}}, }}, - "js": &bintree{nil, map[string]*bintree{ - "jquery-3.5.1.min.js": &bintree{staticJsJquery351MinJs, map[string]*bintree{}}, - "xterm-4.9.0.js": &bintree{staticJsXterm490Js, map[string]*bintree{}}, - "xterm-addon-attach-0.6.0.js": &bintree{staticJsXtermAddonAttach060Js, map[string]*bintree{}}, - "xterm-addon-fit-0.4.0.js": &bintree{staticJsXtermAddonFit040Js, map[string]*bintree{}}, + "js": {nil, map[string]*bintree{ + "jquery-3.5.1.min.js": {staticJsJquery351MinJs, map[string]*bintree{}}, + "xterm-4.9.0.js": {staticJsXterm490Js, map[string]*bintree{}}, + "xterm-addon-attach-0.6.0.js": {staticJsXtermAddonAttach060Js, map[string]*bintree{}}, + "xterm-addon-fit-0.4.0.js": {staticJsXtermAddonFit040Js, map[string]*bintree{}}, }}, }}, }} diff --git a/testdrive/testdrive.go b/testdrive/testdrive.go index 814966bbd2..c2e5e80a50 100644 --- a/testdrive/testdrive.go +++ b/testdrive/testdrive.go @@ -3,7 +3,9 @@ // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an AS IS BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/testing/temp_files.go b/testing/temp_files.go index 3ee8b062c4..8584de4594 100644 --- a/testing/temp_files.go +++ b/testing/temp_files.go @@ -8,8 +8,9 @@ import ( // TempDir creates a temporary directory and returns its path along // with a cleanup function to be called via defer, ex: -// dir, cleanup := TempDir() -// defer cleanup() +// +// dir, cleanup := TempDir() +// defer cleanup() func TempDir(t *testing.T) (string, func()) { tmpDir, err := os.MkdirTemp("", "") Ok(t, err) @@ -25,23 +26,23 @@ func TempDir(t *testing.T) (string, func()) { // It returns the path to the temp directory containing the defined // structure and a cleanup function to delete the directory. // Example usage: -// versionConfig := ` -// terraform { -// required_version = "= 0.12.8" -// } -// ` -// tmpDir, cleanup := DirStructure(t, map[string]interface{}{ -// "pulldir": map[string]interface{}{ -// "project1": map[string]interface{}{ -// "main.tf": nil, -// }, -// "project2": map[string]interface{}{, -// "main.tf": versionConfig, -// }, -// }, -// }) -// defer cleanup() // +// versionConfig := ` +// terraform { +// required_version = "= 0.12.8" +// } +// ` +// tmpDir, cleanup := DirStructure(t, map[string]interface{}{ +// "pulldir": map[string]interface{}{ +// "project1": map[string]interface{}{ +// "main.tf": nil, +// }, +// "project2": map[string]interface{}{, +// "main.tf": versionConfig, +// }, +// }, +// }) +// defer cleanup() func DirStructure(t *testing.T, structure map[string]interface{}) (string, func()) { tmpDir, cleanup := TempDir(t) dirStructureGo(t, tmpDir, structure)