Content-Length: 14165 | pFad | http://github.com/coder/coder/pull/3.patch
thub.com
From c8788afcc0ff7d382f0c3a3faef135844cae695a Mon Sep 17 00:00:00 2001
From: Kyle Carberry
Date: Tue, 4 Jan 2022 15:53:19 +0000
Subject: [PATCH 1/6] chore: Add golangci-lint and codecov
---
.golangci.yaml | 258 ++++++++++++++++++++++++++++++++++++++++++
.vscode/settings.json | 16 +++
codecov.yml | 20 ++++
3 files changed, 294 insertions(+)
create mode 100644 .golangci.yaml
create mode 100644 .vscode/settings.json
create mode 100644 codecov.yml
diff --git a/.golangci.yaml b/.golangci.yaml
new file mode 100644
index 0000000000000..140df27953294
--- /dev/null
+++ b/.golangci.yaml
@@ -0,0 +1,258 @@
+# See https://golangci-lint.run/usage/configuration/
+# Over time we should try tightening some of these.
+
+linters-settings:
+ gocognit:
+ min-complexity: 46 # Min code complexity (def 30).
+
+ goconst:
+ min-len: 4 # Min length of string consts (def 3).
+ min-occurrences: 3 # Min number of const occurrences (def 3).
+
+ gocritic:
+ enabled-checks:
+ # - appendAssign
+ # - appendCombine
+ - argOrder
+ # - assignOp
+ # - badCall
+ - badCond
+ - badLock
+ - badRegexp
+ - boolExprSimplify
+ # - builtinShadow
+ - builtinShadowDecl
+ - captLocal
+ - caseOrder
+ - codegenComment
+ # - commentedOutCode
+ - commentedOutImport
+ # - commentFormatting
+ - defaultCaseOrder
+ - deferUnlambda
+ # - deprecatedComment
+ # - docStub
+ - dupArg
+ - dupBranchBody
+ - dupCase
+ - dupImport
+ - dupSubExpr
+ # - elseif
+ - emptyFallthrough
+ # - emptyStringTest
+ # - equalFold
+ # - evalOrder
+ # - exitAfterDefer
+ # - exposedSyncMutex
+ # - filepathJoin
+ - flagDeref
+ - flagName
+ - hexLiteral
+ # - httpNoBody
+ # - hugeParam
+ # - ifElseChain
+ # - importShadow
+ - indexAlloc
+ - initClause
+ # - ioutilDeprecated
+ - mapKey
+ - methodExprCall
+ # - nestingReduce
+ - newDeref
+ - nilValReturn
+ # - octalLiteral
+ - offBy1
+ # - paramTypeCombine
+ # - preferStringWriter
+ # - preferWriteByte
+ # - ptrToRefParam
+ # - rangeExprCopy
+ # - rangeValCopy
+ - regexpMust
+ - regexpPattern
+ # - regexpSimplify
+ - ruleguard
+ - singleCaseSwitch
+ - sloppyLen
+ # - sloppyReassign
+ - sloppyTypeAssert
+ - sortSlice
+ # - sprintfQuotedString
+ - sqlQuery
+ # - stringConcatSimplify
+ # - stringXbytes
+ # - suspiciousSorting
+ - switchTrue
+ - truncateCmp
+ - typeAssertChain
+ # - typeDefFirst
+ - typeSwitchVar
+ # - typeUnparen
+ - underef
+ # - unlabelStmt
+ # - unlambda
+ # - unnamedResult
+ # - unnecessaryBlock
+ # - unnecessaryDefer
+ # - unslice
+ - valSwap
+ - weakCond
+ # - whyNoLint
+ # - wrapperFunc
+ # - yodaStyleExpr
+ settings:
+ ruleguard:
+ failOn: all
+ rules: "${configDir}/lib/go/lintrules/*.go"
+
+ goimports:
+ local-prefixes: coder.com,cdr.dev,go.coder.com,github.com/cdr,github.com/coder
+
+ gocyclo:
+ min-complexity: 50
+
+ importas:
+ no-unaliased: true
+ alias:
+ - pkg: k8s.io/api/(\w+)/(v[\w\d]+)
+ alias: ${1}${2}
+
+ - pkg: k8s.io/apimachinery/pkg/apis/meta/(v[\w\d]+)
+ alias: meta${1}
+
+ - pkg: k8s.io/client-go/kubernetes/typed/(\w+)/(v[\w\d]+)
+ alias: ${1}${2}client
+
+ - pkg: k8s.io/metrics/pkg/apis/metrics/(v[\w\d]+)
+ alias: metrics${1}
+
+ - pkg: github.com/docker/docker/api/types
+ alias: dockertypes
+
+ - pkg: github.com/docker/docker/client
+ alias: dockerclient
+
+ misspell:
+ locale: US
+
+ nestif:
+ min-complexity: 4 # Min complexity of if statements (def 5, goal 4)
+
+ revive:
+ # see https://github.com/mgechev/revive#available-rules for details.
+ ignore-generated-header: true
+ severity: warning
+ rules:
+ - name: atomic
+ - name: bare-return
+ - name: blank-imports
+ - name: bool-literal-in-expr
+ - name: call-to-gc
+ - name: confusing-naming
+ - name: confusing-results
+ - name: constant-logical-expr
+ - name: context-as-argument
+ - name: context-keys-type
+ - name: deep-exit
+ - name: defer
+ - name: dot-imports
+ - name: duplicated-imports
+ - name: early-return
+ - name: empty-block
+ - name: empty-lines
+ - name: error-naming
+ - name: error-return
+ - name: error-strings
+ - name: errorf
+ - name: exported
+ - name: flag-parameter
+ - name: get-return
+ - name: identical-branches
+ - name: if-return
+ - name: import-shadowing
+ - name: increment-decrement
+ - name: indent-error-flow
+ - name: modifies-parameter
+ - name: modifies-value-receiver
+ - name: package-comments
+ - name: range
+ - name: range-val-address
+ - name: range-val-in-closure
+ - name: receiver-naming
+ - name: redefines-builtin-id
+ - name: string-of-int
+ - name: struct-tag
+ - name: superfluous-else
+ - name: time-naming
+ - name: unconditional-recursion
+ - name: unexported-naming
+ - name: unexported-return
+ - name: unhandled-error
+ - name: unnecessary-stmt
+ - name: unreachable-code
+ - name: unused-parameter
+ - name: unused-receiver
+ - name: var-declaration
+ - name: var-naming
+ - name: waitgroup-by-value
+
+issues:
+ # Rules listed here: https://github.com/securego/gosec#available-rules
+ exclude-rules:
+ - path: _test\.go
+ linters:
+ # We use assertions rather than explicitly checking errors in tests
+ - errcheck
+
+ fix: true
+ max-issues-per-linter: 0
+ max-same-issues: 0
+
+run:
+ concurrency: 4
+ skip-dirs:
+ - node_modules
+ timeout: 5m
+
+# Over time, add more and more linters from
+# https://golangci-lint.run/usage/linters/ as the code improves.
+linters:
+ disable-all: true
+ enable:
+ - asciicheck
+ - bidichk
+ - bodyclose
+ - contextcheck
+ - deadcode
+ - dogsled
+ - errcheck
+ - errname
+ - errorlint
+ - exportloopref
+ - forcetypeassert
+ - gocritic
+ - gocyclo
+ - goimports
+ - gomodguard
+ - gosec
+ - gosimple
+ - govet
+ - importas
+ - ineffassign
+ # - ireturn
+ - makezero
+ - misspell
+ - nilnil
+ - noctx
+ - revive
+ - rowserrcheck
+ - sqlclosecheck
+ - staticcheck
+ - structcheck
+ - tenv
+ - typecheck
+ - unconvert
+ - unused
+ - varcheck
+ - varnamelen
+ - wastedassign
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000000000..c21dd4c902ae4
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,16 @@
+{
+ "go.lintTool": "golangci-lint",
+ "go.lintFlags": ["--fast"],
+ "go.lintOnSave": "package",
+ "go.coverOnSave": true,
+ "go.coverageDecorator": {
+ "type": "gutter",
+ "coveredHighlightColor": "rgba(64,128,128,0.5)",
+ "uncoveredHighlightColor": "rgba(128,64,64,0.25)",
+ "coveredBorderColor": "rgba(64,128,128,0.5)",
+ "uncoveredBorderColor": "rgba(128,64,64,0.25)",
+ "coveredGutterStyle": "blockgreen",
+ "uncoveredGutterStyle": "blockred"
+ }
+ }
+
\ No newline at end of file
diff --git a/codecov.yml b/codecov.yml
new file mode 100644
index 0000000000000..e7e51257c0e96
--- /dev/null
+++ b/codecov.yml
@@ -0,0 +1,20 @@
+codecov:
+ require_ci_to_pass: false
+
+comment:
+ show_carryforward_flags: yes
+
+coverage:
+ notify:
+ slack:
+ default:
+ url: secret:v1::ALa1/e2X+k36fPseab5D7+kBFc9bJyIoIQioD0IMA5jr+0HXVpBRNDCHZhHjCdGc67yff6PPixPEOLwEZpxC37rM23RBZOYlqAq9A5e0MeZVlEoVq19aOYN4Xel17hMJ6GGm7n17wrYpCpcvlVSqNrN0+cr3guVDyG10kQyfh2Y=
+ threshold: 1%
+ only_pulls: false
+ branches:
+ - "main"
+ status:
+ project:
+ default:
+ target: 80%
+ informational: yes
From 3a7e909b4021175988e9a7f06e84c3b9570f88df Mon Sep 17 00:00:00 2001
From: Kyle Carberry
Date: Tue, 4 Jan 2022 15:55:03 +0000
Subject: [PATCH 2/6] Use consistent file names
---
.golangci.yaml => .golangci.yml | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename .golangci.yaml => .golangci.yml (100%)
diff --git a/.golangci.yaml b/.golangci.yml
similarity index 100%
rename from .golangci.yaml
rename to .golangci.yml
From ed05fea0a67fb7d2a4fd9b4b08d31ffde18c0160 Mon Sep 17 00:00:00 2001
From: Kyle Carberry
Date: Tue, 4 Jan 2022 15:58:18 +0000
Subject: [PATCH 3/6] Format settings.json
---
.vscode/settings.json | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/.vscode/settings.json b/.vscode/settings.json
index c21dd4c902ae4..b133181f2da7d 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,16 +1,15 @@
{
- "go.lintTool": "golangci-lint",
- "go.lintFlags": ["--fast"],
- "go.lintOnSave": "package",
- "go.coverOnSave": true,
- "go.coverageDecorator": {
- "type": "gutter",
- "coveredHighlightColor": "rgba(64,128,128,0.5)",
- "uncoveredHighlightColor": "rgba(128,64,64,0.25)",
- "coveredBorderColor": "rgba(64,128,128,0.5)",
- "uncoveredBorderColor": "rgba(128,64,64,0.25)",
- "coveredGutterStyle": "blockgreen",
- "uncoveredGutterStyle": "blockred"
- }
+ "go.lintTool": "golangci-lint",
+ "go.lintFlags": ["--fast"],
+ "go.lintOnSave": "package",
+ "go.coverOnSave": true,
+ "go.coverageDecorator": {
+ "type": "gutter",
+ "coveredHighlightColor": "rgba(64,128,128,0.5)",
+ "uncoveredHighlightColor": "rgba(128,64,64,0.25)",
+ "coveredBorderColor": "rgba(64,128,128,0.5)",
+ "uncoveredBorderColor": "rgba(128,64,64,0.25)",
+ "coveredGutterStyle": "blockgreen",
+ "uncoveredGutterStyle": "blockred"
}
-
\ No newline at end of file
+}
From adba002c74a642cd98c8c61c8cb6f0a684835850 Mon Sep 17 00:00:00 2001
From: Kyle Carberry
Date: Tue, 4 Jan 2022 16:09:24 +0000
Subject: [PATCH 4/6] Add golangci-lint and codecov GitHub Actions
---
.github/workflows/coder.yaml | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/coder.yaml b/.github/workflows/coder.yaml
index 6fd8ae9737331..64f98c6ef5298 100644
--- a/.github/workflows/coder.yaml
+++ b/.github/workflows/coder.yaml
@@ -28,6 +28,16 @@ permissions:
statuses: none
jobs:
+ lint:
+ name: lint/golangci
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - name: golangci-lint
+ uses: golangci/golangci-lint-action@v2
+ with:
+ version: latest
+
style:
name: "style/${{ matrix.style }}"
runs-on: ubuntu-latest
@@ -81,9 +91,21 @@ jobs:
with:
go-version: "^1.17"
- # Check that go is available
- # TODO: Implement actual test run
- - run: go version
+ - run: go install gotest.tools/gotestsum@latest
+
+ - run: |
+ gotestsum \
+ --jsonfile="gotests.json" \
+ --packages="./..." \
+ -- \
+ -covermode=atomic \
+ -coverprofile="gotests.coverage"
+
+ - uses: codecov/codecov-action@v2
+ with:
+ token: ${{ secrets.CODECOV_TOKEN }}
+ files: ./gotests.coverage
+ fail_ci_if_error: true
test-js:
name: "test/js"
From f359eebace01a88a8a50d7c831538f29f6a77584 Mon Sep 17 00:00:00 2001
From: Kyle Carberry
Date: Tue, 4 Jan 2022 16:11:10 +0000
Subject: [PATCH 5/6] Add base Go file for linting
---
.github/workflows/coder.yaml | 4 ++--
cmd/coder/main.go | 7 +++++++
go.mod | 3 +++
3 files changed, 12 insertions(+), 2 deletions(-)
create mode 100644 cmd/coder/main.go
create mode 100644 go.mod
diff --git a/.github/workflows/coder.yaml b/.github/workflows/coder.yaml
index 64f98c6ef5298..9fa8fa5105522 100644
--- a/.github/workflows/coder.yaml
+++ b/.github/workflows/coder.yaml
@@ -28,8 +28,8 @@ permissions:
statuses: none
jobs:
- lint:
- name: lint/golangci
+ style-lint-golangci:
+ name: style/lint/golangci
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
diff --git a/cmd/coder/main.go b/cmd/coder/main.go
new file mode 100644
index 0000000000000..b1b14d0c797c1
--- /dev/null
+++ b/cmd/coder/main.go
@@ -0,0 +1,7 @@
+package main
+
+import "fmt"
+
+func main() {
+ fmt.Println("Hello World!")
+}
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000000000..ff7eaabf436fb
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,3 @@
+module github.com/coder/coder
+
+go 1.17
From b7ec5635f7739f33854499033b3b549b292b7f27 Mon Sep 17 00:00:00 2001
From: Kyle Carberry
Date: Tue, 4 Jan 2022 16:18:16 +0000
Subject: [PATCH 6/6] Add test coverage
---
.github/workflows/coder.yaml | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/.github/workflows/coder.yaml b/.github/workflows/coder.yaml
index 9fa8fa5105522..7ddc3f366a135 100644
--- a/.github/workflows/coder.yaml
+++ b/.github/workflows/coder.yaml
@@ -93,18 +93,14 @@ jobs:
- run: go install gotest.tools/gotestsum@latest
- - run: |
- gotestsum \
- --jsonfile="gotests.json" \
- --packages="./..." \
- -- \
- -covermode=atomic \
- -coverprofile="gotests.coverage"
-
+ # Windows is not happy with backslashed commands.
+ - run: gotestsum --jsonfile="gotests.json" --packages="./..." -- -covermode=atomic -coverprofile="gotests.coverage"
+
- uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./gotests.coverage
+ flags: ${{ matrix.os }}
fail_ci_if_error: true
test-js:
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/coder/coder/pull/3.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy