Skip to content

Commit

Permalink
lint pass (chanzuckerberg#246)
Browse files Browse the repository at this point in the history
lint passSwitch to golangci-lint + clean up findings.

### Summary

This started as a pass to clean up any lint findings, but found that I also needed to switch from gometalinter (which is slow and deprecated) to golangci-lint.

### Test Plan

`make lint test`

### References

* https://github.com/alecthomas/gometalinter
* https://github.com/golangci/golangci-lint
  • Loading branch information
ryanking authored and palasha committed Apr 7, 2020
1 parent a041103 commit 12f2807
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 57 deletions.
7 changes: 0 additions & 7 deletions .gometalinter.json

This file was deleted.

9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ setup: ## setup development dependencies
go get -u github.com/gobuffalo/packr/...
go install github.com/gobuffalo/packr/packr
curl -L https://raw.githubusercontent.com/chanzuckerberg/bff/master/download.sh | sh
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh

lint: ## run the fast go linters
gometalinter --vendor --fast ./...

lint-slow: ## run all linters, even the slow ones
gometalinter --vendor --deadline 120s ./...
golangci-lint run
.PHONY: lint

packr: ## run the packr tool to generate our static files
packr clean -v
Expand Down Expand Up @@ -73,4 +72,4 @@ update-golden-files: dep ## update the golden files in testdata
go test -v -run TestIntegration ./apply/ -update
.PHONY: update-golden-files

.PHONY: build clean coverage test install lint lint-slow packr release help setup
.PHONY: build clean coverage test install packr release help setup
10 changes: 6 additions & 4 deletions apply/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestApplyTemplateBasicNewDirectory(t *testing.T) {
defer os.RemoveAll(d)

nonexistentDir := getNonExistentDirectoryName()
defer dest.RemoveAll(nonexistentDir)
defer dest.RemoveAll(nonexistentDir) //nolint
path := filepath.Join(nonexistentDir, "bar")
overrides := struct{ Foo string }{"foo"}

Expand Down Expand Up @@ -136,7 +136,8 @@ func TestTouchFile(t *testing.T) {
a.NoError(err)
defer os.RemoveAll(d2)

writeFile(fs, "asdf", "jkl")
err = writeFile(fs, "asdf", "jkl")
a.NoError(err)

r, e = readFile(fs, "asdf")
a.Nil(e)
Expand All @@ -156,7 +157,7 @@ func TestTouchFileNonExistentDirectory(t *testing.T) {
defer os.RemoveAll(d)

nonexistentDir := getNonExistentDirectoryName()
defer dest.RemoveAll(nonexistentDir)
defer dest.RemoveAll(nonexistentDir) //nolint
e := touchFile(dest, filepath.Join(nonexistentDir, "foo"))
a.Nil(e)
r, e := readFile(dest, filepath.Join(nonexistentDir, "foo"))
Expand Down Expand Up @@ -400,7 +401,8 @@ func TestCheckToolVersions(t *testing.T) {
a.NoError(err)
defer os.RemoveAll(d)

writeFile(fs, ".fogg-version", tc.current)
err = writeFile(fs, ".fogg-version", tc.current)
a.NoError(err)

v, _, e := checkToolVersions(fs, tc.tool)
a.NoError(e)
Expand Down
6 changes: 3 additions & 3 deletions apply/golden_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestIntegration(t *testing.T) {
a.NoError(e)
configMode, e := testdataFs.Stat("fogg.json")
a.NoError(e)
afero.WriteFile(fs, "fogg.json", configContents, configMode.Mode())
a.NoError(afero.WriteFile(fs, "fogg.json", configContents, configMode.Mode()))

conf, e := config.FindAndReadConfig(fs, "fogg.json")
a.NoError(e)
Expand All @@ -75,7 +75,7 @@ func TestIntegration(t *testing.T) {
e = apply.Apply(fs, conf, templates.Templates, true)
a.NoError(e)

afero.Walk(testdataFs, ".", func(path string, info os.FileInfo, err error) error {
a.NoError(afero.Walk(testdataFs, ".", func(path string, info os.FileInfo, err error) error {
log.Debug("================================================")
log.Debug(path)
if !info.Mode().IsRegular() {
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestIntegration(t *testing.T) {
a.Equal(f1, f2)
}
return nil
})
}))
}
})
}
Expand Down
9 changes: 6 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ func TestFindAndReadConfig(t *testing.T) {
return nil, e
}
_, e = f.Write(v)
if e != nil {
return nil, e
}
}
return fs, nil
}
Expand All @@ -297,19 +300,19 @@ func TestFindAndReadConfig(t *testing.T) {
"config.json": v1,
})
a.NoError(e)
defer f1.RemoveAll(".")
defer f1.RemoveAll(".") //nolint

f2, e := fs(map[string][]byte{
"config.json": v2,
})
a.NoError(e)
defer f2.RemoveAll(".")
defer f2.RemoveAll(".") //nolint

fErr, e := fs(map[string][]byte{
"config.json": []byte(`{"version": 7}`),
})
a.NoError(e)
defer fErr.RemoveAll(".")
defer fErr.RemoveAll(".") //nolint

_, e = FindAndReadConfig(f1, "config.json")
a.NoError(e)
Expand Down
2 changes: 1 addition & 1 deletion exp/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func generatePlan(planPath string) error {
cmd.Stdout = os.Stdout
err := cmd.Run()
if err != nil {
errors.Wrap(err, "Could not run make init")
return errors.Wrap(err, "Could not run make init")
}

cmd = exec.Command("make", "run")
Expand Down
21 changes: 0 additions & 21 deletions plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,27 +305,6 @@ func resolveExtraVars(vars ...map[string]string) map[string]string {
return resolved
}

func resolveRequired(def *string, override *string) string {
if override != nil && *override != "" {
return *override
}
return *def
}

func resolveRequiredInt(def int64, override *int64) int64 {
if override != nil {
return *override
}
return def
}

func resolveOptionalInt(def *int64, override *int64) *int64 {
if override != nil {
return override
}
return def
}

func resolveAccounts(accounts map[string]v2.Account) map[string]int64 {
a := make(map[string]int64)
for name, account := range accounts {
Expand Down
9 changes: 4 additions & 5 deletions plan/plan_quick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import (
"github.com/chanzuckerberg/fogg/plan"
)

func add(x, y int) int {
return x + y
}

func TestValidConfigNoPanic(t *testing.T) {

// return false if valid + panic
Expand All @@ -34,7 +30,10 @@ func TestValidConfigNoPanic(t *testing.T) {
return true
}()

plan.Eval(conf)
_, err = plan.Eval(conf)
if err != nil {
panic(err)
}

} else {
fmt.Println("invalid")
Expand Down
16 changes: 8 additions & 8 deletions plugins/custom_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func TestCustomPluginTar(t *testing.T) {
customPlugin.SetTargetPath(plugins.CustomPluginDir)
a.Nil(customPlugin.Install(fs, pluginName))

afero.Walk(fs, "", func(path string, info os.FileInfo, err error) error {
a.NoError(afero.Walk(fs, "", func(path string, info os.FileInfo, err error) error {
a.Nil(err)
return nil
})
}))

for _, file := range files {
filePath := path.Join(plugins.CustomPluginDir, file)
Expand Down Expand Up @@ -95,10 +95,10 @@ func TestCustomPluginTarStripComponents(t *testing.T) {
customPlugin.SetTargetPath(plugins.CustomPluginDir)
a.Nil(customPlugin.Install(fs, pluginName))

afero.Walk(fs, "", func(path string, info os.FileInfo, err error) error {
a.NoError(afero.Walk(fs, "", func(path string, info os.FileInfo, err error) error {
a.Nil(err)
return nil
})
}))

for idx, file := range expected_files {
// files we expect to skip
Expand Down Expand Up @@ -146,10 +146,10 @@ func TestCustomPluginZip(t *testing.T) {
customPlugin.SetTargetPath(plugins.CustomPluginDir)
a.Nil(customPlugin.Install(fs, pluginName))

afero.Walk(fs, "", func(path string, info os.FileInfo, err error) error {
a.NoError(afero.Walk(fs, "", func(path string, info os.FileInfo, err error) error {
a.Nil(err)
return nil
})
}))

for _, file := range files {
filePath := path.Join(plugins.CustomPluginDir, file)
Expand Down Expand Up @@ -186,10 +186,10 @@ func TestCustomPluginBin(t *testing.T) {
customPlugin.SetTargetPath(plugins.CustomPluginDir)
a.Nil(customPlugin.Install(fs, pluginName))

afero.Walk(fs, "", func(path string, info os.FileInfo, err error) error {
a.NoError(afero.Walk(fs, "", func(path string, info os.FileInfo, err error) error {
a.Nil(err)
return nil
})
}))

customPluginPath := path.Join(plugins.CustomPluginDir, pluginName)
f, err := fs.Open(customPluginPath)
Expand Down

0 comments on commit 12f2807

Please sign in to comment.