Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: recursive gofmt #2504

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cmd/help_fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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=<value>
// <description>
//
// --name=<value>
// <description>
//
// 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
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
24 changes: 14 additions & 10 deletions server/core/config/raw/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server/core/config/raw/workflow_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion server/core/locking/locking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion server/core/runtime/policy/conftest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion server/core/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 8 additions & 5 deletions server/core/terraform/terraform_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions server/events/comment_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
12 changes: 8 additions & 4 deletions server/events/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions server/events/vcs/azuredevops_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/")
Expand Down
2 changes: 0 additions & 2 deletions server/events/webhooks/mocks/mock_slack_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/events/working_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions server/jobs/project_command_output_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion server/logging/simple_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion server/recovery/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
40 changes: 21 additions & 19 deletions server/static/bindata_assetfs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion testdrive/testdrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 19 additions & 18 deletions testing/temp_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down