Skip to content

Commit

Permalink
Add format make target (#170)
Browse files Browse the repository at this point in the history
* fix linting

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* add format make target

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* add developing reference to format target

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

---------

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
  • Loading branch information
wagoodman authored Apr 12, 2023
1 parent 2d5a65d commit 8602f1a
Show file tree
Hide file tree
Showing 60 changed files with 168 additions and 118 deletions.
2 changes: 1 addition & 1 deletion DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ After cloning the following step can help you get setup:
1. run `make bootstrap` to download go mod dependencies, create the `/.tmp` dir, and download helper utilities.
2. run `make help` to view the selection of developer commands in the Makefile

The main make tasks for common static analysis and testing are `lint`, `lint-fix`, `unit`, and `integration`.
The main make tasks for common static analysis and testing are `lint`, `format`, `lint-fix`, `unit`, and `integration`.

See `make help` for all the current make tasks.

Expand Down
27 changes: 21 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ TEMP_DIR = ./.tmp

# Command templates #################################
LINT_CMD = $(TEMP_DIR)/golangci-lint run --tests=false --config .golangci.yaml
GOIMPORTS_CMD := $(TEMP_DIR)/gosimports -local github.com/anchore

# Tool versions #################################
GOLANGCILINT_VERSION := v1.51.0
GOSIMPORTS_VERSION := v0.3.5
GOLANGCILINT_VERSION := v1.52.2
GOSIMPORTS_VERSION := v0.3.8
BOUNCER_VERSION := v0.4.0
CHRONICLE_VERSION := v0.5.1
CHRONICLE_VERSION := v0.6.0

# Formatting variables #################################
BOLD := $(shell tput -T linux bold)
Expand Down Expand Up @@ -91,16 +92,30 @@ static-analysis: check-licenses lint
.PHONY: lint
lint: ## Run gofmt + golangci lint checks
$(call title,Running linters)
# ensure there are no go fmt differences
@printf "files with gofmt issues: [$(shell gofmt -l -s .)]\n"
@test -z "$(shell gofmt -l -s .)"

# run all golangci-lint rules
$(LINT_CMD)
@[ -z "$(shell $(GOIMPORTS_CMD) -d .)" ] || (echo "goimports needs to be fixed" && false)

# go tooling does not play well with certain filename characters, ensure the common cases don't result in future "go get" failures
$(eval MALFORMED_FILENAMES := $(shell find . | grep -v tar-cache | grep -e ':'))
@bash -c "[[ '$(MALFORMED_FILENAMES)' == '' ]] || (printf '\nfound unsupported filename characters:\n$(MALFORMED_FILENAMES)\n\n' && false)"


.PHONY: format
format: ## Auto-format all source code
$(call title,Running formatters)
gofmt -w -s .
$(GOIMPORTS_CMD) -w .
go mod tidy

.PHONY: lint-fix
lint-fix: ## Auto-format all source code + run golangci lint fixers
lint-fix: format ## Auto-format all source code + run golangci lint fixers
$(call title,Running lint fixers)
gofmt -w -s .
$(LINT_CMD) --fix
go mod tidy

.PHONY: check-licenses
check-licenses:
Expand Down
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"fmt"
"runtime"

"github.com/anchore/go-logger"
"github.com/wagoodman/go-partybus"

"github.com/anchore/go-logger"
"github.com/anchore/stereoscope/internal/bus"
dockerClient "github.com/anchore/stereoscope/internal/docker"
"github.com/anchore/stereoscope/internal/log"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/anchore/stereoscope/pkg/image/docker"
"github.com/anchore/stereoscope/pkg/image/oci"
"github.com/anchore/stereoscope/pkg/image/sif"
"github.com/wagoodman/go-partybus"
)

var rootTempDirGenerator = file.NewTempDirGenerator("stereoscope")
Expand Down
6 changes: 4 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package stereoscope

import (
"github.com/anchore/stereoscope/pkg/image"
"testing"

"github.com/scylladb/go-set/i8set"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"

"github.com/anchore/stereoscope/pkg/image"
)

func Test_setPlatform(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions examples/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import (
"context"
"fmt"
"io"
"os"

"github.com/anchore/go-logger"
"github.com/anchore/go-logger/adapter/logrus"

"os"

"github.com/anchore/stereoscope"
"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/filetree/filenode"
Expand Down
3 changes: 2 additions & 1 deletion internal/podman/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"os"
"time"

"github.com/anchore/stereoscope/internal/log"
"github.com/docker/docker/client"
"github.com/pkg/errors"

"github.com/anchore/stereoscope/internal/log"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion internal/podman/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
"strconv"
"time"

"github.com/anchore/stereoscope/internal/log"
"github.com/docker/docker/pkg/homedir"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/knownhosts"

"github.com/anchore/stereoscope/internal/log"
)

type sshClientConfig struct {
Expand Down
3 changes: 2 additions & 1 deletion internal/string_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package internal

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestStringSet_Size(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/event/parsers/parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package parsers
import (
"fmt"

"github.com/anchore/stereoscope/pkg/image/docker"
"github.com/wagoodman/go-partybus"
"github.com/wagoodman/go-progress"

"github.com/anchore/stereoscope/pkg/event"
"github.com/anchore/stereoscope/pkg/image"
"github.com/wagoodman/go-partybus"
"github.com/wagoodman/go-progress"
"github.com/anchore/stereoscope/pkg/image/docker"
)

type ErrBadPayload struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/file/id_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package file

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestIDSet_Size(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/file/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"path/filepath"
"time"

"github.com/anchore/stereoscope/internal/log"

"github.com/sylabs/squashfs"

"github.com/anchore/stereoscope/internal/log"
)

// Metadata represents all file metadata of interest (used today for in-tar file resolution).
Expand Down
3 changes: 1 addition & 2 deletions pkg/file/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (
"testing"
"time"

"github.com/go-test/deep"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/go-test/deep"
)

func TestFileMetadataFromTar(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/file/mime_type_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package file

import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io"
"os"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_MIMEType(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/file/path_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package file

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestPathSet_Size(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/file/resolution_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package file

import (
"github.com/stretchr/testify/assert"
"sort"
"testing"

"github.com/stretchr/testify/assert"
)

func TestResolution_Less(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/file/tarutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"os"
"path/filepath"

"github.com/anchore/stereoscope/internal/log"
"github.com/pkg/errors"

"github.com/anchore/stereoscope/internal/log"
)

const perFileReadLimit = 2 * GB
Expand Down
3 changes: 2 additions & 1 deletion pkg/filetree/depth_first_path_walker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"strings"
"testing"

"github.com/go-test/deep"

"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/filetree/filenode"
"github.com/go-test/deep"
)

func dfsTestTree(t *testing.T) (*FileTree, map[string]*file.Reference) {
Expand Down
5 changes: 2 additions & 3 deletions pkg/filetree/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import (
"sort"
"strings"

"github.com/scylladb/go-set/strset"

"github.com/bmatcuk/doublestar/v4"
"github.com/scylladb/go-set/iset"
"github.com/scylladb/go-set/strset"

"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/filetree/filenode"
"github.com/anchore/stereoscope/pkg/tree"
"github.com/anchore/stereoscope/pkg/tree/node"
"github.com/bmatcuk/doublestar/v4"
)

var ErrRemovingRoot = errors.New("cannot remove the root path (`/`) from the FileTree")
Expand Down
5 changes: 2 additions & 3 deletions pkg/filetree/filetree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import (
"fmt"
"testing"

"github.com/scylladb/go-set/strset"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/scylladb/go-set/strset"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/filetree/filenode"
"github.com/stretchr/testify/assert"
)

func TestFileTree_AddPath(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/filetree/glob.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"path/filepath"
"time"

"github.com/anchore/stereoscope/pkg/filetree/filenode"

"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/filetree/filenode"
)

// basic interface assertion
Expand Down
3 changes: 2 additions & 1 deletion pkg/filetree/glob_parser_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package filetree

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func Test_parseGlob(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/filetree/glob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"sort"
"testing"

"github.com/go-test/deep"

"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/filetree/filenode"
"github.com/go-test/deep"
)

func TestFileInfoAdapter(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/filetree/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"strings"
"sync"

"github.com/anchore/stereoscope/internal/log"

"github.com/anchore/stereoscope/pkg/file"
"github.com/becheran/wildmatch-go"
"github.com/scylladb/go-set/strset"

"github.com/anchore/stereoscope/internal/log"
"github.com/anchore/stereoscope/pkg/file"
)

type Index interface {
Expand Down
3 changes: 2 additions & 1 deletion pkg/filetree/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
package filetree

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"

"github.com/anchore/stereoscope/pkg/file"
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/filetree/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"path"
"sort"

"github.com/bmatcuk/doublestar/v4"

"github.com/anchore/stereoscope/internal/log"
"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/filetree/filenode"
"github.com/anchore/stereoscope/pkg/tree/node"

"github.com/anchore/stereoscope/pkg/file"
"github.com/bmatcuk/doublestar/v4"
)

// Searcher is a facade for searching a file tree with optional indexing support.
Expand Down
5 changes: 3 additions & 2 deletions pkg/filetree/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"fmt"
"testing"

"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/filetree/filenode"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/filetree/filenode"
)

func Test_searchContext_SearchByPath(t *testing.T) {
Expand Down
Loading

0 comments on commit 8602f1a

Please sign in to comment.