Repository: chanzuckerberg/fogg
Pull request #525 (2021-02-10 23:03:18)

go linting pass
Add a bunch more linters and make them pass.




Patch:
diff --git a/.golangci.yml b/.golangci.yml
index 2ed441a1..ae83cf54 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -1,12 +1,22 @@
-run:
-  skip-files:
-    - cmd/exp_examine.go
-    - cmd/exp_entropy.go
-    - exp/examine/local.go
-    - exp/examine/util.go
-  linters:
-    enable:
-      - gofmt
-      - whitespace
-      - unparam
-      - scopelint
+linters:
+  enable:
+    - asciicheck
+    - bodyclose
+    - deadcode
+    - dupl
+    - errcheck
+    - exportloopref
+    - gocyclo
+    - gofmt
+    - goimports
+    - golint
+    - megacheck
+    - misspell
+    - nolintlint
+    - rowserrcheck
+    - scopelint
+    - structcheck
+    - unconvert
+    - unparam
+    - varcheck
+    - whitespace
diff --git a/apply/apply.go b/apply/apply.go
index 4a1bdccf..2352ee83 100644
--- a/apply/apply.go
+++ b/apply/apply.go
@@ -103,23 +103,23 @@ func checkToolVersions(fs afero.Fs, current string) (bool, string, error) {
 		return false, "", errs.WrapUser(e, "unable to read .fogg-version file")
 	}
 	repoVersion := strings.TrimSpace(string(b))
-	changed, e := versionIsChanged(repoVersion, current)
-	return changed, repoVersion, e
+	changed := versionIsChanged(repoVersion, current)
+	return changed, repoVersion, nil
 }
 
-func versionIsChanged(repo string, tool string) (bool, error) {
+func versionIsChanged(repo string, tool string) bool {
 	repoVersion, repoSha, repoDirty := util.ParseVersion(repo)
 	toolVersion, toolSha, toolDirty := util.ParseVersion(tool)
 
 	if repoDirty || toolDirty {
-		return true, nil
+		return true
 	}
 
 	if (repoSha != "" || toolSha != "") && repoSha != toolSha {
-		return true, nil
+		return true
 	}
 
-	return toolVersion.NE(repoVersion), nil
+	return toolVersion.NE(repoVersion)
 }
 
 func applyRepo(fs afero.Fs, p *plan.Plan, repoTemplates, commonTemplates *packr.Box) error {
@@ -197,7 +197,6 @@ func applyEnvs(fs afero.Fs, p *plan.Plan, envBox *packr.Box, componentBoxes map[
 					return errs.WrapUser(e, "unable to apply module invocation")
 				}
 			}
-
 		}
 	}
 	return nil
@@ -205,7 +204,6 @@ func applyEnvs(fs afero.Fs, p *plan.Plan, envBox *packr.Box, componentBoxes map[
 
 func applyTree(dest afero.Fs, source *packr.Box, common *packr.Box, targetBasePath string, subst interface{}) (e error) {
 	return source.Walk(func(path string, sourceFile packr.File) error {
-
 		extension := filepath.Ext(path)
 		target := getTargetPath(targetBasePath, path)
 		targetExtension := filepath.Ext(target)
@@ -222,7 +220,6 @@ func applyTree(dest afero.Fs, source *packr.Box, common *packr.Box, targetBasePa
 					return errs.WrapUser(e, "unable to format HCL")
 				}
 			}
-
 		} else if extension == ".touch" {
 			e = touchFile(dest, target)
 			if e != nil {
@@ -240,7 +237,6 @@ func applyTree(dest afero.Fs, source *packr.Box, common *packr.Box, targetBasePa
 			}
 			logrus.Infof("%s removed", target)
 		} else if extension == ".ln" {
-
 			linkTargetBytes, err := ioutil.ReadAll(sourceFile)
 			if err != nil {
 				return errs.WrapUserf(err, "could not read source file %#v", sourceFile)
@@ -466,22 +462,19 @@ func linkFile(fs afero.Fs, name, target string) error {
 		return errs.NewInternal("can't cast to afero.SymLinker")
 	}
 
-	relativePath, err := filepathRel(name, target)
-	logrus.Debugf("relative link %s err %#v", relativePath, err)
-	if err != nil {
-		return err
-	}
+	relativePath := filepathRel(name, target)
+	logrus.Debugf("relative link %s", relativePath)
 
 	logrus.Debugf("removing link at %s", name)
-	err = fs.Remove(name)
+	err := fs.Remove(name)
 	logrus.Debugf("error removing file %s (probably ok): %s", name, err)
 
 	_, err = linker.SymlinkIfPossible(relativePath, name)
 	return err
 }
 
-func filepathRel(path, name string) (string, error) {
+func filepathRel(path, name string) string {
 	dirs := strings.Count(path, "/")
 	fullPath := fmt.Sprintf("%s/%s", strings.Repeat("../", dirs), name)
-	return filepath.Clean(fullPath), nil
+	return filepath.Clean(fullPath)
 }
diff --git a/cmd/components_paths.go b/cmd/components_paths.go
index e0cbac0c..5136d2d7 100644
--- a/cmd/components_paths.go
+++ b/cmd/components_paths.go
@@ -58,6 +58,7 @@ var componentsListCmd = &cobra.Command{
 				fmt.Printf("terraform/envs/%s/%s\n", e.Env, c.Name)
 			}
 		}
+
 		return nil
 	},
 }
diff --git a/cmd/exp_aws_config.go b/cmd/exp_aws_config.go
index 1cbc9b40..b4d93ab8 100644
--- a/cmd/exp_aws_config.go
+++ b/cmd/exp_aws_config.go
@@ -31,7 +31,6 @@ var awsConfigCmd = &cobra.Command{
 	Short: "Generates an ~/.aws/config from your fogg.yml",
 	Long:  "This command will help generate a ~/.aws/config from your fogg.yml",
 	RunE: func(cmd *cobra.Command, args []string) error {
-
 		// Set up fs
 		pwd, err := os.Getwd()
 		if err != nil {
@@ -92,6 +91,7 @@ var awsConfigCmd = &cobra.Command{
 			// No AWS provider, skip this account
 			if account.Providers == nil || account.Providers.AWS == nil {
 				logrus.Infof("Skipping %s because no AWS providers detected", name)
+
 				continue
 			}
 
diff --git a/cmd/exp_entropy.go b/cmd/exp_entropy.go
index 74d7b814..35476a6d 100644
--- a/cmd/exp_entropy.go
+++ b/cmd/exp_entropy.go
@@ -36,7 +36,7 @@ output in LogFmt format.`,
 	},
 }
 
-func entropyRun(cmd *cobra.Command, args []string) error {
+func entropyRun(cmd *cobra.Command, _ []string) error {
 	planFilePath, err := cmd.Flags().GetString("plan-file")
 	if err != nil {
 		return fmt.Errorf("could not read plan-file flag: %w", err)
diff --git a/cmd/fmt.go b/cmd/fmt.go
index e3199f0e..bfd6ce0e 100644
--- a/cmd/fmt.go
+++ b/cmd/fmt.go
@@ -22,7 +22,6 @@ var fmtCmd = &cobra.Command{
 	Long:          "",
 	SilenceErrors: true, // If we don't silence here, cobra will print them. But we want to do that in cmd/root.go
 	RunE: func(cmd *cobra.Command, args []string) error {
-
 		fs, err := pwdFs()
 		if err != nil {
 			return err
diff --git a/cmd/migrate.go b/cmd/migrate.go
index 90169c4e..1054d021 100644
--- a/cmd/migrate.go
+++ b/cmd/migrate.go
@@ -20,7 +20,6 @@ var migrateCommand = &cobra.Command{
 	Short: "Runs all possible fogg migrations",
 	Long:  "This command will run all applicable updates to fogg configuration.",
 	RunE: func(cmd *cobra.Command, args []string) error {
-
 		// Set up fs
 		pwd, err := os.Getwd()
 		if err != nil {
diff --git a/cmd/plan.go b/cmd/plan.go
index dbcd47a4..7356fbd7 100644
--- a/cmd/plan.go
+++ b/cmd/plan.go
@@ -17,7 +17,6 @@ var planCmd = &cobra.Command{
 	Long:          "plan will read fogg.yml or fogg.yml, use that to generate a plan and print that plan out. It will make no changes.",
 	SilenceErrors: true, // If we don't silence here, cobra will print them. But we want to do that in cmd/root.go
 	RunE: func(cmd *cobra.Command, args []string) error {
-
 		var e error
 		// Set up fs
 		fs, e := pwdFs()
diff --git a/cmd/root.go b/cmd/root.go
index 10efa865..81848135 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -75,7 +75,7 @@ func Execute() {
 		case *errs.Internal:
 			fmt.Printf("%s:\nThis may be a bug, please report it.\n\n %s", red("INTERNAL ERROR"), e.Error())
 		default:
-			fmt.Printf("%s: %s", red("UNKOWN ERROR"), err)
+			fmt.Printf("%s: %s", red("UNKNOWN ERROR"), err)
 			os.Exit(1)
 		}
 	}
diff --git a/cmd/setup.go b/cmd/setup.go
index 76be4e8a..54c0ccb1 100644
--- a/cmd/setup.go
+++ b/cmd/setup.go
@@ -13,7 +13,7 @@ func init() {
 
 var setupCmd = &cobra.Command{
 	Use:           "setup",
-	Short:         "Setup dependencies for curent working directory",
+	Short:         "Setup dependencies for current working directory",
 	SilenceErrors: true,
 	RunE: func(cmd *cobra.Command, args []string) error {
 		fs, config, err := bootstrapCmd(cmd)
diff --git a/cmd/util.go b/cmd/util.go
index 20b5d7ea..0fb03302 100644
--- a/cmd/util.go
+++ b/cmd/util.go
@@ -63,7 +63,6 @@ func openFs() (afero.Fs, error) {
 }
 
 func bootstrapCmd(cmd *cobra.Command) (afero.Fs, *v2.Config, error) {
-
 	fs, err := openFs()
 	if err != nil {
 		return nil, nil, err
diff --git a/config/v2/config.go b/config/v2/config.go
index 3e92b763..3b9d6609 100644
--- a/config/v2/config.go
+++ b/config/v2/config.go
@@ -267,7 +267,7 @@ type componentInfo struct {
 }
 
 // PathToComponentType given a path, return information about that component
-func (c Config) PathToComponentType(path string) (componentInfo, error) {
+func (c Config) PathToComponentType(path string) (componentInfo, error) { //nolint
 	t := componentInfo{}
 
 	path = strings.TrimRight(path, "/")
@@ -341,7 +341,7 @@ func (c *Config) Generate(r *rand.Rand, size int) reflect.Value {
 		return &str
 	}
 
-	randBoolPtr := func(r *rand.Rand, s int) *bool {
+	randBoolPtr := func(r *rand.Rand) *bool {
 		b := r.Float32() > 0.5
 		return &b
 	}
@@ -392,13 +392,12 @@ func (c *Config) Generate(r *rand.Rand, size int) reflect.Value {
 					Profile:   randStringPtr(r, s),
 					Version:   randStringPtr(r, s),
 				}
-			} else {
-				return &AWSProvider{
-					AccountID: &accountID,
-					Region:    randStringPtr(r, s),
-					Role:      randStringPtr(r, s),
-					Version:   randStringPtr(r, s),
-				}
+			}
+			return &AWSProvider{
+				AccountID: &accountID,
+				Region:    randStringPtr(r, s),
+				Role:      randStringPtr(r, s),
+				Version:   randStringPtr(r, s),
 			}
 		}
 		return nil
@@ -415,14 +414,14 @@ func (c *Config) Generate(r *rand.Rand, size int) reflect.Value {
 		return nil
 	}
 
-	randHerokuProvider := func(r *rand.Rand, s int) *HerokuProvider {
+	randHerokuProvider := func(r *rand.Rand) *HerokuProvider {
 		if r.Float32() < 0.5 {
 			return &HerokuProvider{}
 		}
 		return nil
 	}
 
-	randDatadogProvider := func(r *rand.Rand, s int) *DatadogProvider {
+	randDatadogProvider := func(r *rand.Rand) *DatadogProvider {
 		if r.Float32() < 0.5 {
 			return &DatadogProvider{}
 		}
@@ -455,8 +454,8 @@ func (c *Config) Generate(r *rand.Rand, size int) reflect.Value {
 				Snowflake: randSnowflakeProvider(r, s),
 				Okta:      randOktaProvider(r, s),
 				Bless:     randBlessProvider(r, s),
-				Heroku:    randHerokuProvider(r, s),
-				Datadog:   randDatadogProvider(r, s),
+				Heroku:    randHerokuProvider(r),
+				Datadog:   randDatadogProvider(r),
 			},
 			TerraformVersion: randStringPtr(r, s),
 		}
@@ -466,7 +465,7 @@ func (c *Config) Generate(r *rand.Rand, size int) reflect.Value {
 			if r.Float32() < 0.5 {
 				c.Tools.TravisCI = &TravisCI{
 					CommonCI: CommonCI{
-						Enabled:     randBoolPtr(r, s),
+						Enabled:     randBoolPtr(r),
 						TestBuckets: randIntPtr(r, s),
 					},
 				}
@@ -498,7 +497,6 @@ func (c *Config) Generate(r *rand.Rand, size int) reflect.Value {
 		conf.Accounts[acctName] = Account{
 			Common: randCommon(r, size),
 		}
-
 	}
 
 	conf.Envs = map[string]Env{}
@@ -519,7 +517,6 @@ func (c *Config) Generate(r *rand.Rand, size int) reflect.Value {
 			}
 		}
 		conf.Envs[envName] = e
-
 	}
 
 	return reflect.ValueOf(conf)
diff --git a/config/v2/resolvers.go b/config/v2/resolvers.go
index c352f4eb..af5466f2 100644
--- a/config/v2/resolvers.go
+++ b/config/v2/resolvers.go
@@ -82,9 +82,8 @@ func ResolveStringMap(getter func(Common) map[string]string, commons ...Common)
 // ResolveAWSProvider will return an AWSProvder iff one of the required fields is set somewhere in
 // the set of Common config objects passed in. Otherwise it will return nil.
 func ResolveAWSProvider(commons ...Common) *AWSProvider {
-
 	var profile, region, role, version *string
-	var accountId *json.Number
+	var accountID *json.Number
 	var additionalRegions []string
 
 	for _, c := range commons {
@@ -111,7 +110,7 @@ func ResolveAWSProvider(commons ...Common) *AWSProvider {
 			}
 
 			if p.AccountID != nil {
-				accountId = p.AccountID
+				accountID = p.AccountID
 			}
 
 			if p.AdditionalRegions != nil {
@@ -128,7 +127,7 @@ func ResolveAWSProvider(commons ...Common) *AWSProvider {
 			Version: version,
 
 			// optional fields
-			AccountID:         accountId,
+			AccountID:         accountID,
 			AdditionalRegions: additionalRegions,
 		}
 	}
@@ -137,7 +136,6 @@ func ResolveAWSProvider(commons ...Common) *AWSProvider {
 
 // ResolveBackend returns the Backend configuration for a given component, after applying all inheritance rules
 func ResolveBackend(commons ...Common) *Backend {
-
 	var kind, accountID, bucket, dynamoTable, profile, region, hostName, organization, role *string
 
 	kind = util.StrPtr("s3")
@@ -286,9 +284,8 @@ func ResolveHerokuProvider(commons ...Common) *HerokuProvider {
 		return &HerokuProvider{
 			Version: version,
 		}
-	} else {
-		return p
 	}
+	return p
 }
 
 func ResolveDatadogProvider(commons ...Common) *DatadogProvider {
@@ -306,9 +303,8 @@ func ResolveDatadogProvider(commons ...Common) *DatadogProvider {
 		return &DatadogProvider{
 			Version: version,
 		}
-	} else {
-		return p
 	}
+	return p
 }
 
 func ResolveTfeProvider(commons ...Common) *TfeProvider {
@@ -332,7 +328,6 @@ func ResolveTfeProvider(commons ...Common) *TfeProvider {
 				hostname = t.Hostname
 			}
 		}
-
 	}
 
 	return &TfeProvider{
@@ -475,13 +470,6 @@ func BackendBucketGetter(comm Common) *string {
 	return nil
 }
 
-func BackendAccountIdGetter(comm Common) *string {
-	if comm.Backend != nil {
-		return comm.Backend.AccountID
-	}
-	return nil
-}
-
 func BackendRegionGetter(comm Common) *string {
 	if comm.Backend != nil {
 		return comm.Backend.Region
diff --git a/config/v2/validation.go b/config/v2/validation.go
index 1a626cea..c293172f 100644
--- a/config/v2/validation.go
+++ b/config/v2/validation.go
@@ -101,7 +101,6 @@ func ValidateBackend(backend *Backend, component string) error {
 	}
 
 	if *backend.Kind == "s3" {
-
 		if backend.Bucket == nil {
 			errs = multierror.Append(errs, fmt.Errorf("when backend kind == 's3', bucket is required (component %s)", component))
 		}
@@ -123,7 +122,6 @@ func ValidateBackend(backend *Backend, component string) error {
 	}
 
 	if *backend.Kind == "remote" {
-
 		if backend.HostName == nil {
 			errs = multierror.Append(errs, fmt.Errorf("when backend kind == 'remote', host_name is required (component %s)", component))
 		}
diff --git a/exp/examine/local.go b/exp/examine/local.go
index 6c187a19..cbbf9b1a 100644
--- a/exp/examine/local.go
+++ b/exp/examine/local.go
@@ -8,10 +8,6 @@ import (
 	"github.com/spf13/afero"
 )
 
-const apiHostname = "https://registry.terraform.io"
-const apiVersion = "/v1"
-const resourceType = "/modules/"
-
 //**Local refers to any files located within your local file system**
 
 //GetLocalModules retrieves all terraform modules within a given directory
diff --git a/exp/examine/util.go b/exp/examine/util.go
index f1490fb1..e81717e1 100644
--- a/exp/examine/util.go
+++ b/exp/examine/util.go
@@ -60,9 +60,6 @@ type Submodule struct {
 }
 
 const githubURL = "github.com"
-const awsRegistry = "terraform-aws-modules/"
-const cztack = "/chanzuckerberg/cztack/"
-const protocol = "https://"
 const tagPattern = "ref="
 
 //GetFromGithub Retrieves modules that are available through github
diff --git a/plan/ci.go b/plan/ci.go
index 7609e1dd..0cdade33 100644
--- a/plan/ci.go
+++ b/plan/ci.go
@@ -47,6 +47,7 @@ func (c *CIConfig) populateBuckets(numBuckets int) *CIConfig {
 		bucket := i % numBuckets
 		c.TestBuckets[bucket] = append(c.TestBuckets[bucket], proj)
 	}
+
 	return c
 }
 
@@ -160,7 +161,6 @@ func (p *Plan) buildTravisCIConfig(c *v2.Config, foggVersion string) TravisCICon
 	numBuckets := 1
 	if c.Defaults.Tools != nil &&
 		c.Defaults.Tools.TravisCI != nil {
-
 		if c.Defaults.Tools.TravisCI.TestBuckets != nil &&
 			*c.Defaults.Tools.TravisCI.TestBuckets > 0 {
 			numBuckets = *c.Defaults.Tools.TravisCI.TestBuckets
@@ -241,7 +241,6 @@ func (p *Plan) buildCircleCIConfig(c *v2.Config, foggVersion string) CircleCICon
 	sshFingerprints := []string{}
 
 	if c.Defaults.Tools != nil && c.Defaults.Tools.CircleCI != nil {
-
 		if c.Defaults.Tools.CircleCI.TestBuckets != nil &&
 			*c.Defaults.Tools.CircleCI.TestBuckets > 0 {
 			numBuckets = *c.Defaults.Tools.CircleCI.TestBuckets
@@ -258,7 +257,6 @@ func (p *Plan) buildCircleCIConfig(c *v2.Config, foggVersion string) CircleCICon
 }
 
 func (p *Plan) buildGitHubActionsConfig(c *v2.Config, foggVersion string) GitHubActionsCIConfig {
-
 	var env map[string]string
 
 	if c.Defaults.Tools != nil && c.Defaults.Tools.GitHubActionsCI != nil {
@@ -331,7 +329,6 @@ func (p *Plan) buildGitHubActionsConfig(c *v2.Config, foggVersion string) GitHub
 
 	numBuckets := 1
 	if c.Defaults.Tools != nil && c.Defaults.Tools.GitHubActionsCI != nil {
-
 		if c.Defaults.Tools.GitHubActionsCI.TestBuckets != nil &&
 			*c.Defaults.Tools.GitHubActionsCI.TestBuckets > 0 {
 			numBuckets = *c.Defaults.Tools.GitHubActionsCI.TestBuckets
diff --git a/plan/plan.go b/plan/plan.go
index a5663fb1..7edeaad6 100644
--- a/plan/plan.go
+++ b/plan/plan.go
@@ -82,7 +82,6 @@ func (c CIComponent) generateCIConfig(
 	provider *AWSProvider,
 	projName string,
 	projDir string) *CIConfig {
-
 	if !c.Enabled {
 		return nil
 	}
@@ -252,7 +251,7 @@ type Env struct {
 	EKS        *v2.EKSConfig        `yaml:"eks"`
 }
 
-// TfLint containts a plan for running tflint
+// TfLint contains a plan for running tflint
 type TfLint struct {
 	Enabled bool `yaml:"enabled"`
 }
@@ -399,7 +398,6 @@ func (p *Plan) buildEnvs(conf *v2.Config) (map[string]Env, error) {
 		envPlan.Env = envName
 
 		for componentName, componentConf := range conf.Envs[envName].Components {
-
 			componentPlan := Component{
 				Kind: componentConf.Kind,
 			}
diff --git a/plugins/custom_plugin.go b/plugins/custom_plugin.go
index 27c9ea14..88ec16ba 100644
--- a/plugins/custom_plugin.go
+++ b/plugins/custom_plugin.go
@@ -90,7 +90,7 @@ func (cp *CustomPlugin) install(
 		return err
 	}
 
-	file, err := cp.fetch(pluginName, fullURL)
+	file, err := cp.fetch(fullURL)
 	if err != nil {
 		return err
 	}
@@ -131,7 +131,7 @@ func (cp *CustomPlugin) WithCache(cache *diskv.Diskv) *CustomPlugin {
 }
 
 // fetch fetches the custom plugin at URL
-func (cp *CustomPlugin) fetch(pluginName string, url string) (io.ReadCloser, error) {
+func (cp *CustomPlugin) fetch(url string) (io.ReadCloser, error) {
 	h := sha256.New()
 	_, err := h.Write([]byte(url))
 	if err != nil {
@@ -289,7 +289,7 @@ func (cp *CustomPlugin) processZip(fs afero.Fs, reader io.Reader, targetDir stri
 					return errs.WrapUser(err, "zip: could not mkdirs")
 				}
 			} else {
-				destFile, err := fs.OpenFile(fpath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.FileMode(f.Mode()))
+				destFile, err := fs.OpenFile(fpath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, f.Mode())
 				if err != nil {
 					return errs.WrapUserf(err, "zip: could not open destination file for %s", fpath)
 				}
diff --git a/util/maps.go b/util/maps.go
index 4b3a4279..99a4b734 100644
--- a/util/maps.go
+++ b/util/maps.go
@@ -6,7 +6,6 @@ import (
 )
 
 func SortedMapKeys(in interface{}) []string {
-
 	v := reflect.ValueOf(in)
 	if v.Kind() == reflect.Map {
 		var keys []string
diff --git a/util/module_storage.go b/util/module_storage.go
index a842d1fe..091aaed1 100644
--- a/util/module_storage.go
+++ b/util/module_storage.go
@@ -13,7 +13,6 @@ import (
 )
 
 func DownloadModule(fs afero.Fs, cacheDir, source string) (string, error) {
-
 	// We want to do these operations from the root of our working repository.
 	// In the case where we have a BaseFs we pull out its root. Otherwise use `pwd`.
 	var pwd string
diff --git a/util/template.go b/util/template.go
index d8cf0bfe..d2716cfb 100644
--- a/util/template.go
+++ b/util/template.go
@@ -74,7 +74,6 @@ func OpenTemplate(label string, source io.Reader, commonTemplates *packr.Box) (*
 		t, err = t.Parse(s)
 
 		return err
-
 	})
 
 	if err != nil {


Test patch:
diff --git a/apply/apply_test.go b/apply/apply_test.go
index 87fc868b..3464318d 100644
--- a/apply/apply_test.go
+++ b/apply/apply_test.go
@@ -329,10 +329,12 @@ func TestGetTargetPath(t *testing.T) {
 		{"foo", "fogg.tf.tmpl", "foo/fogg.tf"},
 	}
 	for _, test := range data {
+		tt := test
+
 		t.Run(test.source, func(t *testing.T) {
 			r := require.New(t)
-			out := getTargetPath(test.base, test.source)
-			r.Equal(test.output, out)
+			out := getTargetPath(tt.base, tt.source)
+			r.Equal(tt.output, out)
 		})
 	}
 }
@@ -378,11 +380,13 @@ func TestCalculateLocalPath(t *testing.T) {
 	}
 
 	for _, test := range data {
+		tt := test
+
 		t.Run("", func(t *testing.T) {
 			r := require.New(t)
-			p, e := calculateModuleAddressForSource(test.path, test.moduleAddress)
+			p, e := calculateModuleAddressForSource(tt.path, tt.moduleAddress)
 			r.Nil(e)
-			r.Equal(test.expected, p)
+			r.Equal(tt.expected, p)
 		})
 	}
 }
@@ -404,19 +408,21 @@ var versionTests = []struct {
 }
 
 func TestCheckToolVersions(t *testing.T) {
-	for _, tc := range versionTests {
+	for _, test := range versionTests {
+		tt := test
+
 		t.Run("", func(t *testing.T) {
 			r := require.New(t)
 			fs, d, err := util.TestFs()
 			r.NoError(err)
 			defer os.RemoveAll(d)
 
-			err = writeFile(fs, ".fogg-version", tc.current)
+			err = writeFile(fs, ".fogg-version", tt.current)
 			r.NoError(err)
 
-			v, _, e := checkToolVersions(fs, tc.tool)
+			v, _, e := checkToolVersions(fs, tt.tool)
 			r.NoError(e)
-			r.Equal(tc.result, v)
+			r.Equal(tt.result, v)
 		})
 	}
 }
@@ -425,10 +431,11 @@ func TestVersionIsChanged(t *testing.T) {
 	r := require.New(t)
 
 	for _, test := range versionTests {
+		tt := test
+
 		t.Run("", func(t *testing.T) {
-			b, e := versionIsChanged(test.current, test.tool)
-			r.NoError(e)
-			r.Equal(test.result, b)
+			b := versionIsChanged(tt.current, tt.tool)
+			r.Equal(tt.result, b)
 		})
 	}
 }
@@ -460,20 +467,16 @@ func Test_filepathRel(t *testing.T) {
 		path string
 	}
 	tests := []struct {
-		name    string
-		args    args
-		want    string
-		wantErr bool
+		name string
+		args args
+		want string
 	}{
-		{"terraform.d", args{"terraform/accounts/idseq/terraform.d", "terraform.d"}, "../../../terraform.d", false},
+		{"terraform.d", args{"terraform/accounts/idseq/terraform.d", "terraform.d"}, "../../../terraform.d"},
 	}
-	for _, tt := range tests {
+	for _, test := range tests {
+		tt := test
 		t.Run(tt.name, func(t *testing.T) {
-			got, err := filepathRel(tt.args.name, tt.args.path)
-			if (err != nil) != tt.wantErr {
-				t.Errorf("filepathRel() error = %v, wantErr %v", err, tt.wantErr)
-				return
-			}
+			got := filepathRel(tt.args.name, tt.args.path)
 			if got != tt.want {
 				t.Errorf("filepathRel() = %v, want %v", got, tt.want)
 			}
diff --git a/apply/golden_file_test.go b/apply/golden_file_test.go
index d3ad1a40..f76bf3e6 100644
--- a/apply/golden_file_test.go
+++ b/apply/golden_file_test.go
@@ -19,7 +19,6 @@ import (
 var updateGoldenFiles = flag.Bool("update", false, "when set, rewrite the golden files")
 
 func TestIntegration(t *testing.T) {
-
 	var testCases = []struct {
 		fileName string
 	}{
@@ -35,11 +34,13 @@ func TestIntegration(t *testing.T) {
 		{"tfe_provider_yaml"},
 	}
 
-	for _, tc := range testCases {
-		t.Run(tc.fileName, func(t *testing.T) {
+	for _, test := range testCases {
+		tt := test
+
+		t.Run(tt.fileName, func(t *testing.T) {
 			r := require.New(t)
 
-			testdataFs := afero.NewBasePathFs(afero.NewOsFs(), filepath.Join(util.ProjectRoot(), "testdata", tc.fileName))
+			testdataFs := afero.NewBasePathFs(afero.NewOsFs(), filepath.Join(util.ProjectRoot(), "testdata", tt.fileName))
 
 			if *updateGoldenFiles {
 				// delete all files except fogg.yml
diff --git a/config/config_test.go b/config/config_test.go
index 256d309b..cbccc926 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -40,7 +40,8 @@ func Test_detectVersion(t *testing.T) {
 	fs, _, err := util.TestFs()
 	r.NoError(err)
 
-	for _, tt := range tests {
+	for _, test := range tests {
+		tt := test
 		t.Run(tt.name, func(t *testing.T) {
 			var got int
 			var err error
diff --git a/config/v2/resolvers_test.go b/config/v2/resolvers_test.go
index 8d990be8..bc8b84f1 100644
--- a/config/v2/resolvers_test.go
+++ b/config/v2/resolvers_test.go
@@ -27,7 +27,8 @@ func TestResolveTfLint(t *testing.T) {
 		{&fal, &tru, &tru},
 		{&fal, &fal, &fal},
 	}
-	for _, tt := range data {
+	for _, test := range data {
+		tt := test
 		t.Run("", func(t *testing.T) {
 			def := v2.Common{Tools: &v2.Tools{TfLint: &v2.TfLint{Enabled: tt.def}}}
 			over := v2.Common{Tools: &v2.Tools{TfLint: &v2.TfLint{Enabled: tt.over}}}
diff --git a/config/v2/validation_test.go b/config/v2/validation_test.go
index 451268ad..58b6f096 100644
--- a/config/v2/validation_test.go
+++ b/config/v2/validation_test.go
@@ -61,7 +61,8 @@ func TestValidateOwnersComponent(t *testing.T) {
 		{"all unset", "", "", "", false, 1},
 	}
 
-	for _, tt := range cases {
+	for _, test := range cases {
+		tt := test
 		t.Run(tt.label, func(t *testing.T) {
 			r := require.New(t)
 			c := confComponentOwner(tt.def, tt.env, tt.comp)
@@ -77,22 +78,21 @@ func TestValidateOwnersComponent(t *testing.T) {
 }
 
 func TestValidateBackends(t *testing.T) {
-
 	var cases = []struct {
-		kind     string
-		genValid bool
-		wantErr  bool
+		kind    string
+		wantErr bool
 	}{
-		{"invalid", false, true},
-		{"s3", true, false},
-		{"remote", true, false},
+		{"invalid", true},
+		{"s3", false},
+		{"remote", false},
 	}
 
-	for _, tt := range cases {
+	for _, test := range cases {
+		tt := test
 		t.Run(tt.kind, func(t *testing.T) {
 			r := require.New(t)
 
-			c := confBackendKind(t, tt.kind, tt.genValid)
+			c := confBackendKind(t, tt.kind)
 			_, err := c.Validate()
 			if tt.wantErr {
 				r.Error(err)
@@ -103,7 +103,7 @@ func TestValidateBackends(t *testing.T) {
 	}
 }
 
-func confBackendKind(t *testing.T, kind string, generateValid bool) Config {
+func confBackendKind(t *testing.T, kind string) Config {
 	r := require.New(t)
 	base := Config{
 		Version: 2,
@@ -216,9 +216,8 @@ func TestResolveStringArray(t *testing.T) {
 }
 
 func TestValidateAWSProvider(t *testing.T) {
-
 	validProfile := &AWSProvider{
-		AccountID: util.JsonNumberPtr(123456),
+		AccountID: util.JSONNumberPtr(123456),
 		Profile:   util.StrPtr("my-profile"),
 		Region:    util.StrPtr("us-sw-12"),
 		Version:   util.StrPtr("1.1.1"),
@@ -226,7 +225,7 @@ func TestValidateAWSProvider(t *testing.T) {
 
 	invalidNothing := &AWSProvider{}
 	invalidBoth := &AWSProvider{
-		AccountID: util.JsonNumberPtr(123456),
+		AccountID: util.JSONNumberPtr(123456),
 		Profile:   util.StrPtr("my-profile-name"),
 		Role:      util.StrPtr("my-role-name"),
 		Region:    util.StrPtr("us-sw-12"),
@@ -234,7 +233,7 @@ func TestValidateAWSProvider(t *testing.T) {
 	}
 
 	validRole := &AWSProvider{
-		AccountID: util.JsonNumberPtr(123456),
+		AccountID: util.JSONNumberPtr(123456),
 		Role:      util.StrPtr("my-role-name"),
 		Region:    util.StrPtr("us-sw-12"),
 		Version:   util.StrPtr("1.1.1"),
@@ -254,7 +253,8 @@ func TestValidateAWSProvider(t *testing.T) {
 		{"valid role", args{validRole, "valid-role"}, false},
 		{"invalid both", args{invalidBoth, "invalid-both"}, true},
 	}
-	for _, tt := range tests {
+	for _, test := range tests {
+		tt := test
 		t.Run(tt.name, func(t *testing.T) {
 			if err := ValidateAWSProvider(tt.args.p, tt.args.component); (err != nil) != tt.wantErr {
 				t.Errorf("ValidateAWSProvider() error = %v, wantErr %v", err, tt.wantErr)
@@ -264,7 +264,6 @@ func TestValidateAWSProvider(t *testing.T) {
 }
 
 func TestConfig_ValidateAWSProviders(t *testing.T) {
-
 	tests := []struct {
 		fileName string
 		wantErr  bool
@@ -273,7 +272,8 @@ func TestConfig_ValidateAWSProviders(t *testing.T) {
 		{"v2_minimal_valid_yaml", false},
 		{"v2_invalid_aws_provider_yaml", true},
 	}
-	for _, tt := range tests {
+	for _, test := range tests {
+		tt := test
 		t.Run(tt.fileName, func(t *testing.T) {
 			r := require.New(t)
 			fs, _, e := util.TestFs()
@@ -302,7 +302,8 @@ func TestConfig_ValidateTravis(t *testing.T) {
 	}{
 		{"v2_invalid_travis_command_yaml", true},
 	}
-	for _, tt := range tests {
+	for _, test := range tests {
+		tt := test
 		t.Run(tt.fileName, func(t *testing.T) {
 			r := require.New(t)
 			fs, _, e := util.TestFs()
@@ -369,7 +370,8 @@ func TestValidateBackend(t *testing.T) {
 		{"valid-remote", validRemote, false},
 		{"invalid-remote", invalidRemote, true},
 	}
-	for _, tt := range tests {
+	for _, test := range tests {
+		tt := test
 		t.Run(tt.name, func(t *testing.T) {
 			if err := ValidateBackend(tt.backend, tt.name); (err != nil) != tt.wantErr {
 				t.Errorf("ValidateBackend() error = %v, wantErr %v", err, tt.wantErr)
diff --git a/exp/examine/latest.go b/exp/examine/latest.go
index 1dff451f..fa1cf2bd 100644
--- a/exp/examine/latest.go
+++ b/exp/examine/latest.go
@@ -19,7 +19,7 @@ func LatestModuleVersions(fs afero.Fs, module *tfconfig.Module) ([]ModuleWrapper
 
 	for _, moduleCall := range module.ModuleCalls {
 		if strings.HasPrefix(moduleCall.Source, githubURL) { //If the resource is from github then retrieve from custom url
-			resource, err = createGitUrl(moduleCall)
+			resource, err = createGitURL(moduleCall)
 			if err != nil {
 				return nil, errs.WrapUserf(err, "Could not generate url for %s latest module", moduleCall.Source)
 			}
@@ -38,8 +38,8 @@ func LatestModuleVersions(fs afero.Fs, module *tfconfig.Module) ([]ModuleWrapper
 	return latestModules, nil
 }
 
-//createGitUrl retrieves the latest release version and creates an HTTP accessible link
-func createGitUrl(moduleCall *tfconfig.ModuleCall) (string, error) {
+//createGitURL retrieves the latest release version and creates an HTTP accessible link
+func createGitURL(moduleCall *tfconfig.ModuleCall) (string, error) {
 	splitString := strings.Split(moduleCall.Source, "/")
 	owner, repo := splitString[1], splitString[2]
 
diff --git a/exp/examine/latest_test.go b/exp/examine/latest_test.go
index 0e175fcd..522209c3 100644
--- a/exp/examine/latest_test.go
+++ b/exp/examine/latest_test.go
@@ -35,7 +35,7 @@ func TestCreateGitUrl(t *testing.T) {
 	r.NoError(err)
 	r.NotNil(module)
 
-	url, err := createGitUrl(module.ModuleCalls["parameters-policy"])
+	url, err := createGitURL(module.ModuleCalls["parameters-policy"])
 	r.NoError(err)
 	r.NotEmpty(url)
 }
diff --git a/exp/state/remote_state_test.go b/exp/state/remote_state_test.go
index 191f246c..3c6a0e86 100644
--- a/exp/state/remote_state_test.go
+++ b/exp/state/remote_state_test.go
@@ -18,7 +18,8 @@ func Test_collectRemoteStateReferences(t *testing.T) {
 	}{
 		{"main", args{"testdata"}, []string{"one", "two", "three", "four", "five", "six"}, false},
 	}
-	for _, tt := range tests {
+	for _, test := range tests {
+		tt := test
 		t.Run(tt.name, func(t *testing.T) {
 			r := require.New(t)
 			got, err := collectRemoteStateReferences(tt.args.path)
diff --git a/plan/ci_test.go b/plan/ci_test.go
index 55670c9e..670bcb6c 100644
--- a/plan/ci_test.go
+++ b/plan/ci_test.go
@@ -58,7 +58,7 @@ func Test_buildTravisCI_Profiles(t *testing.T) {
 				TerraformVersion: util.StrPtr("0.1.0"),
 				Providers: &v2.Providers{
 					AWS: &v2.AWSProvider{
-						AccountID: util.JsonNumberPtr(123),
+						AccountID: util.JSONNumberPtr(123),
 						Region:    util.StrPtr("us-west-2"),
 						Profile:   util.StrPtr("foo"),
 						Version:   util.StrPtr("0.12.0"),
@@ -114,7 +114,7 @@ func Test_buildTravisCI_TestBuckets(t *testing.T) {
 				TerraformVersion: util.StrPtr("0.1.0"),
 				Providers: &v2.Providers{
 					AWS: &v2.AWSProvider{
-						AccountID: util.JsonNumberPtr(123),
+						AccountID: util.JSONNumberPtr(123),
 						Region:    util.StrPtr("us-west-2"),
 						Profile:   util.StrPtr("foo"),
 						Version:   util.StrPtr("0.12.0"),
@@ -170,7 +170,7 @@ func Test_buildCircleCI_Profiles(t *testing.T) {
 				TerraformVersion: util.StrPtr("0.1.0"),
 				Providers: &v2.Providers{
 					AWS: &v2.AWSProvider{
-						AccountID: util.JsonNumberPtr(123),
+						AccountID: util.JSONNumberPtr(123),
 						Region:    util.StrPtr("us-west-2"),
 						Profile:   util.StrPtr("foo"),
 						Version:   util.StrPtr("0.12.0"),
@@ -225,7 +225,7 @@ func Test_buildCircleCI_ProfilesDisabled(t *testing.T) {
 				TerraformVersion: util.StrPtr("0.1.0"),
 				Providers: &v2.Providers{
 					AWS: &v2.AWSProvider{
-						AccountID: util.JsonNumberPtr(123),
+						AccountID: util.JSONNumberPtr(123),
 						Region:    util.StrPtr("us-west-2"),
 						Profile:   util.StrPtr("foo"),
 						Version:   util.StrPtr("0.12.0"),
diff --git a/plan/plan_quick_test.go b/plan/plan_quick_test.go
index d201fea2..1520f197 100644
--- a/plan/plan_quick_test.go
+++ b/plan/plan_quick_test.go
@@ -11,7 +11,6 @@ import (
 )
 
 func TestValidConfigNoPanic(t *testing.T) {
-
 	// return false if valid + panic
 	assertion := func(conf *v2.Config) bool {
 		// fmt.Printf("GOT %#v\n\n", pretty.Sprint(conf))
@@ -34,7 +33,6 @@ func TestValidConfigNoPanic(t *testing.T) {
 			if err != nil {
 				panic(err)
 			}
-
 		} else {
 			fmt.Println("invalid")
 			fmt.Printf("err %s\n", err)
@@ -42,7 +40,6 @@ func TestValidConfigNoPanic(t *testing.T) {
 
 		// config isn't valid so we don't care if we panic or not
 		return true
-
 	}
 	if err := quick.Check(assertion, &quick.Config{MaxCount: 100}); err != nil {
 		t.Error(err)
diff --git a/plan/plan_test.go b/plan/plan_test.go
index 30059d47..d52c4dfe 100644
--- a/plan/plan_test.go
+++ b/plan/plan_test.go
@@ -196,12 +196,12 @@ func TestTfeProvider(t *testing.T) {
 		r.True(c.Providers.Tfe.Enabled)
 	}
 
-	disabled := func(c ComponentCommon, enabled bool) {
+	disabled := func(c ComponentCommon) {
 		r.NotNil(c)
 		r.Nil(c.Providers.Tfe)
 	}
 
 	enabled(plan.Global.ComponentCommon)
 	enabled(plan.Accounts["foo"].ComponentCommon)
-	disabled(plan.Envs["bar"].Components["bam"].ComponentCommon, false)
+	disabled(plan.Envs["bar"].Components["bam"].ComponentCommon)
 }
diff --git a/plugins/custom_plugin_test.go b/plugins/custom_plugin_test.go
index 0c39f9f3..e1bc5392 100644
--- a/plugins/custom_plugin_test.go
+++ b/plugins/custom_plugin_test.go
@@ -83,7 +83,7 @@ func TestCustomPluginTarStripComponents(t *testing.T) {
 	cache := plugins.GetPluginCache(cacheDir)
 
 	files := []string{"a/test.txt", "terraform-provider-testing"}
-	expected_files := []string{"test.txt", ""}
+	expectedFiles := []string{"test.txt", ""}
 	dirs := []string{"a"}
 	tarPath := generateTar(t, files, dirs)
 	defer os.Remove(tarPath)
@@ -111,7 +111,7 @@ func TestCustomPluginTarStripComponents(t *testing.T) {
 		return nil
 	}))
 
-	for idx, file := range expected_files {
+	for idx, file := range expectedFiles {
 		// files we expect to skip
 		if file == "" {
 			filePath := path.Join(plugins.CustomPluginDir, files[idx])
@@ -277,7 +277,6 @@ func generateZip(t *testing.T, files []string) string {
 	defer zipWriter.Close()
 
 	for _, file := range files {
-
 		header := &zip.FileHeader{
 			Name: file,
 		}
@@ -308,7 +307,8 @@ func TestTemplate(t *testing.T) {
 		{"os_arch", args{"{{.OS}}_{{.Arch}}", "bar", "bam"}, "bar_bam", false},
 		{"bad template", args{"{{.asdf", "bar", "bam"}, "", true},
 	}
-	for _, tt := range tests {
+	for _, test := range tests {
+		tt := test
 		t.Run(tt.name, func(t *testing.T) {
 			got, err := plugins.Template(tt.args.url, tt.args.arch, tt.args.os)
 			if (err != nil) != tt.wantErr {
diff --git a/templates/templates_test.go b/templates/templates_test.go
index d584f4c6..c13e6c3b 100644
--- a/templates/templates_test.go
+++ b/templates/templates_test.go
@@ -24,7 +24,8 @@ func TestOpenTemplate(t *testing.T) {
 		{"foo", args{temps.Components[v2.ComponentKindTerraform], "Makefile.tmpl"}, false},
 	}
 
-	for _, tt := range tests {
+	for _, test := range tests {
+		tt := test
 		t.Run(tt.name, func(t *testing.T) {
 			r := require.New(t)
 			f, err := tt.args.box.Open(tt.args.path)
diff --git a/util/maps_test.go b/util/maps_test.go
index 926bab4d..169ae913 100644
--- a/util/maps_test.go
+++ b/util/maps_test.go
@@ -16,7 +16,8 @@ func TestSortedMapKeys(t *testing.T) {
 	}{
 		{"basic", args{map[string]string{"foo": "bar"}}, []string{"foo"}},
 	}
-	for _, tt := range tests {
+	for _, test := range tests {
+		tt := test
 		t.Run(tt.name, func(t *testing.T) {
 			if got := SortedMapKeys(tt.args.in); !reflect.DeepEqual(got, tt.want) {
 				t.Errorf("SortedMapKeys() = %v, want %v", got, tt.want)
diff --git a/util/testing.go b/util/testing.go
index b9a4577c..d13ee8a8 100644
--- a/util/testing.go
+++ b/util/testing.go
@@ -15,7 +15,7 @@ func Intptr(i int64) *int64 {
 	return &i
 }
 
-func JsonNumberPtr(i int) *json.Number {
+func JSONNumberPtr(i int) *json.Number {
 	j := json.Number(strconv.Itoa(i))
 	return &j
 }
diff --git a/util/version_test.go b/util/version_test.go
index 1112a31b..a2839af8 100644
--- a/util/version_test.go
+++ b/util/version_test.go
@@ -20,14 +20,15 @@ func TestParse(t *testing.T) {
 		{"0.1.0-abcdef", "0.1.0", "abcdef", false},
 		{"0.1.0-abcdef.dirty", "0.1.0", "abcdef", true},
 	}
-	for _, tc := range testCases {
+	for _, test := range testCases {
+		tt := test
 		t.Run("", func(t *testing.T) {
-			v, sha, dirty := ParseVersion(tc.input)
-			semVersion, e := semver.Parse(tc.version)
+			v, sha, dirty := ParseVersion(tt.input)
+			semVersion, e := semver.Parse(tt.version)
 			r.NoError(e)
 			r.Equal(semVersion, v)
-			r.Equal(tc.sha, sha)
-			r.Equal(tc.dirty, dirty)
+			r.Equal(tt.sha, sha)
+			r.Equal(tt.dirty, dirty)
 		})
 	}
 }