Skip to content

Commit e272586

Browse files
authored
Set up linters and 'Hello world' code (#1)
1 parent d053275 commit e272586

File tree

8 files changed

+818
-2
lines changed

8 files changed

+818
-2
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ jobs:
1313

1414
- run:
1515
name: Run lint checks
16-
command: echo "Will run lint checks once there are lint checks to run"
16+
command: |
17+
make lint
1718
1819
workflows:
1920
version: 2

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
# Settings files for JetBrains IDEs
2-
.idea
2+
/.idea
3+
4+
# Vim swap files
5+
*.swp
6+
7+
# Project-specific $GOBIN
8+
/.gobin
9+
10+
# Empty file touched by `make deps`
11+
/deps

.golangci.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
run:
2+
timeout: 5m
3+
4+
issues:
5+
exclude-use-default: false
6+
7+
exclude-rules:
8+
- linters:
9+
- golint
10+
text: "should have a package comment, unless it's in another file for this package"
11+
- linters:
12+
- golint
13+
text: "should not use dot imports"
14+
- linters:
15+
- golint
16+
text: "returns unexported type .* which can be annoying to use"
17+
- linters:
18+
- golint
19+
text: "error strings should not be capitalized or end with punctuation or a newline"
20+
21+
linters-settings:
22+
golint:
23+
min-confidence: 0
24+
govet:
25+
enable-all: true
26+
disable:
27+
- shadow
28+
settings:
29+
printf: # analyzer name, run `go tool vet help` to see all analyzers
30+
funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
31+
- Print
32+
- Printf
33+
- Println
34+
- Debug
35+
- Debugf
36+
- Info
37+
- Infof
38+
- Warn
39+
- Warnf
40+
- Error
41+
- Errorf
42+
gocritic:
43+
enabled-tags:
44+
- diagnostic
45+
- experimental
46+
- opinionated
47+
- performance
48+
- style
49+
disabled-checks:
50+
- dupImport # https://github.com/go-critic/go-critic/issues/845
51+
- commentFormatting
52+
- octalLiteral
53+
- unnamedResult
54+
- unnecessaryDefer
55+
- importShadow
56+
- emptyStringTest
57+
nolintlint:
58+
allow-leading-space: false # require machine-readable nolint directives (i.e. with no leading space)
59+
allow-unused: false # report any unused nolint directives
60+
require-explanation: false # don't require an explanation for nolint directives
61+
require-specific: true # require nolint directives to be specific about which linter is being skipped
62+
63+
linters:
64+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
65+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
66+
disable-all: true
67+
enable:
68+
- asciicheck
69+
# - bodyclose
70+
# - deadcode
71+
# - depguard
72+
# - dogsled
73+
# - dupl
74+
# - errcheck
75+
# - funlen
76+
# - gochecknoglobals
77+
# - gochecknoinits
78+
# - gocognit
79+
# - goconst
80+
- exportloopref
81+
- gocritic
82+
# - gocyclo
83+
# - godot
84+
# - godox
85+
# - goerr113
86+
- gofmt
87+
- goimports
88+
- golint
89+
# - gomnd
90+
# - goprintffuncname
91+
# - gosec
92+
- gosimple
93+
- govet
94+
- ineffassign
95+
# - interfacer
96+
# - lll
97+
# - maligned
98+
# - misspell
99+
- nakedret
100+
# - nestif
101+
- nolintlint
102+
# - prealloc
103+
- rowserrcheck
104+
# - scopelint
105+
# - staticcheck
106+
# - structcheck
107+
# - stylecheck
108+
# - testpackage
109+
# - typecheck
110+
- unconvert
111+
- unparam
112+
# - unused
113+
# - varcheck
114+
# - whitespace
115+
# - wsl

Makefile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
.PHONY: none
3+
none:
4+
5+
6+
deps: go.mod
7+
@echo "+ $@"
8+
@go mod tidy
9+
@go mod download
10+
@go mod verify
11+
@touch deps
12+
13+
14+
#####################################################################
15+
###### Binaries we depend on ############
16+
#####################################################################
17+
18+
GOBIN := $(CURDIR)/.gobin
19+
PATH := $(GOBIN):$(PATH)
20+
# Makefile on Mac doesn't pass this updated PATH to the shell
21+
# and so without the following line, the shell does not end up
22+
# trying commands in $(GOBIN) first.
23+
# See https://stackoverflow.com/a/36226784/3690207
24+
SHELL := env PATH=$(PATH) /bin/bash
25+
26+
GOLANGCILINT_BIN := $(GOBIN)/golangci-lint
27+
$(GOLANGCILINT_BIN): deps
28+
@echo "+ $@"
29+
go install github.com/golangci/golangci-lint/cmd/golangci-lint
30+
31+
STATICCHECK_BIN := $(GOBIN)/staticcheck
32+
$(STATICCHECK_BIN): deps
33+
@echo "+ $@"
34+
@go install honnef.co/go/tools/cmd/staticcheck
35+
36+
###########
37+
## Lint ##
38+
###########
39+
40+
.PHONY: golangci-lint
41+
golangci-lint: $(GOLANGCILINT_BIN)
42+
ifdef CI
43+
@echo '+ $@'
44+
@echo 'The environment indicates we are in CI; running linters in check mode.'
45+
@echo 'If this fails, run `make lint`.'
46+
golangci-lint run
47+
else
48+
golangci-lint run --fix
49+
endif
50+
51+
.PHONY: staticcheck
52+
staticcheck: $(STATICCHECK_BIN)
53+
staticcheck -checks=all ./...
54+
55+
.PHONY: lint
56+
lint: golangci-lint staticcheck

cmd/kubelinter/kube-linter.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func main() {
8+
fmt.Println("This is kube-linter. It does not do anything yet!")
9+
}

go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module golang.stackrox.io/kube-linter
2+
3+
go 1.14
4+
5+
require (
6+
github.com/golangci/golangci-lint v1.30.0
7+
honnef.co/go/tools v0.0.1-2020.1.5
8+
)

0 commit comments

Comments
 (0)