Skip to content
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
79 changes: 53 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,39 +117,66 @@ gomplate.png: gomplate.svg
cloudconvert -f png -c density=288 $^

lint:
gometalinter --vendor --disable-all \
--enable=gosec \
--enable=goconst \
--enable=gocyclo \
--enable=golint \
--enable=gotypex \
--enable=ineffassign \
--enable=vet \
--enable=vetshadow \
--enable=misspell \
--enable=goimports \
--enable=gofmt \
./...
gometalinter --vendor --skip tests --disable-all \
--enable=deadcode \
./...

slow-lint:
gometalinter -j $(LINT_PROCS) --vendor --skip tests --deadline 120s \
--disable gotype \
golangci-lint run --disable-all \
--enable depguard \
--enable dupl \
--enable goconst \
--enable gocritic \
--enable gocyclo \
--enable gofmt \
--enable goimports \
--enable golint \
--enable gosec \
--enable gosimple \
--enable govet \
--enable ineffassign \
--enable maligned \
--enable misspell \
./...
gometalinter -j $(LINT_PROCS) --vendor --deadline 120s \
--disable gotype \
--disable megacheck \
--disable deadcode \
--enable nakedret \
--enable prealloc \
--enable staticcheck \
--enable structcheck \
--enable stylecheck \
--enable typecheck \
--enable unconvert \
--enable varcheck

golangci-lint run --tests false --disable-all \
--enable deadcode \
--enable errcheck \
--enable interfacer \
--enable scopelint \
--enable unused

golangci-lint run --build-tags integration \
--disable-all \
--enable deadcode \
--enable depguard \
--enable dupl \
--enable gochecknoinits \
--enable gocritic \
--enable gocyclo \
--enable gofmt \
--enable goimports \
--enable golint \
--enable gosec \
--enable gosimple \
--enable govet \
--enable ineffassign \
--enable maligned \
--enable misspell \
--enable nakedret \
--enable prealloc \
--enable scopelint \
--enable staticcheck \
--enable structcheck \
--enable stylecheck \
--enable typecheck \
--enable unconvert \
--enable unparam \
--enable unused \
--enable varcheck \
./tests/integration
megacheck -tags integration ./tests/integration

.PHONY: gen-changelog clean test build-x compress-all build-release build test-integration-docker gen-docs lint clean-images clean-containers docker-images
.DELETE_ON_ERROR:
Expand Down
2 changes: 1 addition & 1 deletion aws/kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (k *KMS) Decrypt(ciphertext string) (string, error) {
return "", err
}
input := &kms.DecryptInput{
CiphertextBlob: []byte(ciphertextBlob),
CiphertextBlob: ciphertextBlob,
}
output, err := k.Client.Decrypt(input)
if err != nil {
Expand Down
12 changes: 5 additions & 7 deletions cmd/gomplate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func validateOpts(cmd *cobra.Command, args []string) error {
}

if len(opts.InputFiles) != len(opts.OutputFiles) {
return fmt.Errorf("Must provide same number of --out (%d) as --file (%d) options", len(opts.OutputFiles), len(opts.InputFiles))
return fmt.Errorf("must provide same number of --out (%d) as --file (%d) options", len(opts.OutputFiles), len(opts.InputFiles))
}

if cmd.Flag("input-dir").Changed && (cmd.Flag("in").Changed || cmd.Flag("file").Changed) {
Expand Down Expand Up @@ -77,12 +77,10 @@ func postRunExec(cmd *cobra.Command, args []string) error {
signal.Notify(sigs)
go func() {
// Pass signals to the sub-process
select {
case sig := <-sigs:
if c.Process != nil {
// nolint: gosec
c.Process.Signal(sig)
}
sig := <-sigs
if c.Process != nil {
// nolint: gosec
_ = c.Process.Signal(sig)
}
}()

Expand Down
14 changes: 8 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ func (o *Config) String() string {
o.defaults()

c := "input: "
if o.Input != "" {
switch {
case o.Input != "":
c += "<arg>"
} else if o.InputDir != "" {
case o.InputDir != "":
c += o.InputDir
} else {
default:
c += strings.Join(o.InputFiles, ", ")
}

Expand All @@ -80,11 +81,12 @@ func (o *Config) String() string {
}

c += "\noutput: "
if o.InputDir != "" && o.OutputDir != "." {
switch {
case o.InputDir != "" && o.OutputDir != ".":
c += o.OutputDir
} else if o.OutputMap != "" {
case o.OutputMap != "":
c += o.OutputMap
} else {
default:
c += strings.Join(o.OutputFiles, ", ")
}

Expand Down
16 changes: 8 additions & 8 deletions data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,20 @@ func parseCSV(args ...string) ([][]string, []string, error) {

func csvParseArgs(args ...string) (in, delim string, hdr []string) {
delim = ","
if len(args) == 1 {
switch len(args) {
case 1:
in = args[0]
}
if len(args) == 2 {
case 2:
in = args[1]
if len(args[0]) == 1 {
switch len(args[0]) {
case 1:
delim = args[0]
} else if len(args[0]) == 0 {
case 0:
hdr = []string{}
} else {
default:
hdr = strings.Split(args[0], delim)
}
}
if len(args) == 3 {
case 3:
delim = args[0]
hdr = strings.Split(args[1], delim)
in = args[2]
Expand Down
2 changes: 1 addition & 1 deletion data/datasource_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestReadFile(t *testing.T) {
source.fs = fs
actual, err = readFile(source, "foo.txt")
assert.NoError(t, err)
assert.Equal(t, []byte(content), actual)
assert.Equal(t, content, actual)
mime, err = source.mimeType()
assert.NoError(t, err)
assert.Equal(t, "application/json", mime)
Expand Down
31 changes: 0 additions & 31 deletions data/datasource_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,37 +162,6 @@ func TestParseHeaderArgs(t *testing.T) {
assert.Equal(t, expected, parsed)
}

func TestHTTPFileWithSubPath(t *testing.T) {
server, client := setupHTTP(200, "application/json; charset=utf-8", `{"hello": "world"}`)
defer server.Close()

sources := make(map[string]*Source)
sources["foo"] = &Source{
Alias: "foo",
URL: &url.URL{
Scheme: "http",
Host: "example.com",
Path: "/foo",
},
hc: client,
}
data := &Data{
Sources: sources,
}

expected := map[string]interface{}{
"hello": "world",
}

actual, err := data.Datasource("foo")
assert.NoError(t, err)
assert.Equal(t, must(marshalObj(expected, json.Marshal)), must(marshalObj(actual, json.Marshal)))

actual, err = data.Datasource(server.URL)
assert.NoError(t, err)
assert.Equal(t, must(marshalObj(expected, json.Marshal)), must(marshalObj(actual, json.Marshal)))
}

func TestBuildURL(t *testing.T) {
expected := "https://example.com/index.html"
base := mustParseURL(expected)
Expand Down
10 changes: 6 additions & 4 deletions data/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/stretchr/testify/assert"
)

const osWindows = "windows"

func TestNewData(t *testing.T) {
d, err := NewData(nil, nil)
assert.NoError(t, err)
Expand Down Expand Up @@ -63,7 +65,7 @@ func TestParseSourceWithAlias(t *testing.T) {
assert.True(t, s.URL.IsAbs())
assert.Equal(t, "/otherdir/foo.json", s.URL.Path)

if runtime.GOOS == "windows" {
if runtime.GOOS == osWindows {
s, err = parseSource("data=foo.json")
assert.NoError(t, err)
assert.Equalf(t, byte(':'), s.URL.Path[1], "Path was %s", s.URL.Path)
Expand Down Expand Up @@ -111,7 +113,7 @@ func TestDatasource(t *testing.T) {
fs := afero.NewMemMapFs()
var uPath string
var f afero.File
if runtime.GOOS == "windows" {
if runtime.GOOS == osWindows {
_ = fs.Mkdir("C:\\tmp", 0777)
f, _ = fs.Create("C:\\tmp\\" + fname)
_, _ = f.Write(contents)
Expand Down Expand Up @@ -158,7 +160,7 @@ func TestDatasourceReachable(t *testing.T) {
fs := afero.NewMemMapFs()
var uPath string
var f afero.File
if runtime.GOOS == "windows" {
if runtime.GOOS == osWindows {
_ = fs.Mkdir("C:\\tmp", 0777)
f, _ = fs.Create("C:\\tmp\\" + fname)
uPath = "C:/tmp/" + fname
Expand Down Expand Up @@ -205,7 +207,7 @@ func TestInclude(t *testing.T) {

var uPath string
var f afero.File
if runtime.GOOS == "windows" {
if runtime.GOOS == osWindows {
_ = fs.Mkdir("C:\\tmp", 0777)
f, _ = fs.Create("C:\\tmp\\" + fname)
uPath = "C:/tmp/" + fname
Expand Down
8 changes: 5 additions & 3 deletions data/datasource_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ func readVault(source *Source, args ...string) (data []byte, err error) {
}

source.mediaType = jsonMimetype
if len(params) > 0 {
switch {
case len(params) > 0:
data, err = source.vc.Write(p, params)
} else if strings.HasSuffix(p, "/") {
case strings.HasSuffix(p, "/"):
source.mediaType = jsonArrayMimetype
data, err = source.vc.List(p)
} else {
default:
data, err = source.vc.Read(p)
}
if err != nil {
return nil, err
}

if len(data) == 0 {
return nil, errors.Errorf("no value found for path %s", p)
}
Expand Down
2 changes: 1 addition & 1 deletion env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ func (f woFile) Read([]byte) (n int, err error) {
return 0, ErrWriteOnly
}

var ErrWriteOnly = errors.New("Filesystem is write-only")
var ErrWriteOnly = errors.New("filesystem is write-only")
2 changes: 1 addition & 1 deletion funcs/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (f *MathFuncs) Div(a, b interface{}) (interface{}, error) {
divisor := conv.ToFloat64(a)
dividend := conv.ToFloat64(b)
if dividend == 0 {
return 0, fmt.Errorf("Error: division by 0")
return 0, fmt.Errorf("error: division by 0")
}
return divisor / dividend, nil
}
Expand Down
7 changes: 2 additions & 5 deletions funcs/uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

const (
uuidPattern = "^[[:xdigit:]]{8}-(?:[[:xdigit:]]{4}-){3}[[:xdigit:]]{12}$"
uuidV1Pattern = "^[[:xdigit:]]{8}-[[:xdigit:]]{4}-1[[:xdigit:]]{3}-[89ab][[:xdigit:]]{3}-[[:xdigit:]]{12}$"
uuidV4Pattern = "^[[:xdigit:]]{8}-[[:xdigit:]]{4}-4[[:xdigit:]]{3}-[89ab][[:xdigit:]]{3}-[[:xdigit:]]{12}$"
)
Expand Down Expand Up @@ -36,8 +35,7 @@ func TestNil(t *testing.T) {

func TestIsValid(t *testing.T) {
u := UUIDNS()
var in interface{}
in = false
in := interface{}(false)
i, err := u.IsValid(in)
assert.NoError(t, err)
assert.False(t, i)
Expand All @@ -63,8 +61,7 @@ func TestIsValid(t *testing.T) {

func TestParse(t *testing.T) {
u := UUIDNS()
var in interface{}
in = false
in := interface{}(false)
_, err := u.Parse(in)
assert.Error(t, err)

Expand Down
2 changes: 2 additions & 0 deletions gomplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (g *gomplate) runTemplate(t *tplate) error {
return err
}

// nolint: gocritic
switch t.target.(type) {
case io.Closer:
if t.target != os.Stdout {
Expand Down Expand Up @@ -179,6 +180,7 @@ func mappingNamer(outMap string, g *gomplate) func(string) (string, error) {
return "", err
}
ctx := &context{}
// nolint: gocritic
switch c := g.context.(type) {
case *context:
for k, v := range *c {
Expand Down
2 changes: 1 addition & 1 deletion math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Seq(start, end, step int64) []int64 {
}

// adjust the end so it aligns exactly (avoids infinite loop!)
end = end - (end-start)%step
end -= (end - start) % step

seq := []int64{start}
last := start
Expand Down
3 changes: 1 addition & 2 deletions random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ const defaultSet = "-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstu
// StringRE - Generate a random string that matches a given regular
// expression. Defaults to "[a-zA-Z0-9_.-]"
func StringRE(count int, match string) (r string, err error) {
var chars []rune
chars = []rune(defaultSet)
var chars = []rune(defaultSet)
if match != "" {
chars, err = matchChars(match)
if err != nil {
Expand Down
Loading