Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita6b2dd7

Browse files
authored
chore: Add golangci-lint and codecov (#3)
* chore: Add golangci-lint and codecov* Use consistent file names* Format settings.json* Add golangci-lint and codecov GitHub Actions* Add base Go file for linting* Add test coverage
1 parent78973ea commita6b2dd7

File tree

6 files changed

+324
-3
lines changed

6 files changed

+324
-3
lines changed

‎.github/workflows/coder.yaml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ permissions:
2828
statuses:none
2929

3030
jobs:
31+
style-lint-golangci:
32+
name:style/lint/golangci
33+
runs-on:ubuntu-latest
34+
steps:
35+
-uses:actions/checkout@v2
36+
-name:golangci-lint
37+
uses:golangci/golangci-lint-action@v2
38+
with:
39+
version:latest
40+
3141
style:
3242
name:"style/${{ matrix.style }}"
3343
runs-on:ubuntu-latest
@@ -81,9 +91,17 @@ jobs:
8191
with:
8292
go-version:"^1.17"
8393

84-
# Check that go is available
85-
# TODO: Implement actual test run
86-
-run:go version
94+
-run:go install gotest.tools/gotestsum@latest
95+
96+
# Windows is not happy with backslashed commands.
97+
-run:gotestsum --jsonfile="gotests.json" --packages="./..." -- -covermode=atomic -coverprofile="gotests.coverage"
98+
99+
-uses:codecov/codecov-action@v2
100+
with:
101+
token:${{ secrets.CODECOV_TOKEN }}
102+
files:./gotests.coverage
103+
flags:${{ matrix.os }}
104+
fail_ci_if_error:true
87105

88106
test-js:
89107
name:"test/js"

‎.golangci.yml

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
# See https://golangci-lint.run/usage/configuration/
2+
# Over time we should try tightening some of these.
3+
4+
linters-settings:
5+
gocognit:
6+
min-complexity:46# Min code complexity (def 30).
7+
8+
goconst:
9+
min-len:4# Min length of string consts (def 3).
10+
min-occurrences:3# Min number of const occurrences (def 3).
11+
12+
gocritic:
13+
enabled-checks:
14+
# - appendAssign
15+
# - appendCombine
16+
-argOrder
17+
# - assignOp
18+
# - badCall
19+
-badCond
20+
-badLock
21+
-badRegexp
22+
-boolExprSimplify
23+
# - builtinShadow
24+
-builtinShadowDecl
25+
-captLocal
26+
-caseOrder
27+
-codegenComment
28+
# - commentedOutCode
29+
-commentedOutImport
30+
# - commentFormatting
31+
-defaultCaseOrder
32+
-deferUnlambda
33+
# - deprecatedComment
34+
# - docStub
35+
-dupArg
36+
-dupBranchBody
37+
-dupCase
38+
-dupImport
39+
-dupSubExpr
40+
# - elseif
41+
-emptyFallthrough
42+
# - emptyStringTest
43+
# - equalFold
44+
# - evalOrder
45+
# - exitAfterDefer
46+
# - exposedSyncMutex
47+
# - filepathJoin
48+
-flagDeref
49+
-flagName
50+
-hexLiteral
51+
# - httpNoBody
52+
# - hugeParam
53+
# - ifElseChain
54+
# - importShadow
55+
-indexAlloc
56+
-initClause
57+
# - ioutilDeprecated
58+
-mapKey
59+
-methodExprCall
60+
# - nestingReduce
61+
-newDeref
62+
-nilValReturn
63+
# - octalLiteral
64+
-offBy1
65+
# - paramTypeCombine
66+
# - preferStringWriter
67+
# - preferWriteByte
68+
# - ptrToRefParam
69+
# - rangeExprCopy
70+
# - rangeValCopy
71+
-regexpMust
72+
-regexpPattern
73+
# - regexpSimplify
74+
-ruleguard
75+
-singleCaseSwitch
76+
-sloppyLen
77+
# - sloppyReassign
78+
-sloppyTypeAssert
79+
-sortSlice
80+
# - sprintfQuotedString
81+
-sqlQuery
82+
# - stringConcatSimplify
83+
# - stringXbytes
84+
# - suspiciousSorting
85+
-switchTrue
86+
-truncateCmp
87+
-typeAssertChain
88+
# - typeDefFirst
89+
-typeSwitchVar
90+
# - typeUnparen
91+
-underef
92+
# - unlabelStmt
93+
# - unlambda
94+
# - unnamedResult
95+
# - unnecessaryBlock
96+
# - unnecessaryDefer
97+
# - unslice
98+
-valSwap
99+
-weakCond
100+
# - whyNoLint
101+
# - wrapperFunc
102+
# - yodaStyleExpr
103+
settings:
104+
ruleguard:
105+
failOn:all
106+
rules:"${configDir}/lib/go/lintrules/*.go"
107+
108+
goimports:
109+
local-prefixes:coder.com,cdr.dev,go.coder.com,github.com/cdr,github.com/coder
110+
111+
gocyclo:
112+
min-complexity:50
113+
114+
importas:
115+
no-unaliased:true
116+
alias:
117+
-pkg:k8s.io/api/(\w+)/(v[\w\d]+)
118+
alias:${1}${2}
119+
120+
-pkg:k8s.io/apimachinery/pkg/apis/meta/(v[\w\d]+)
121+
alias:meta${1}
122+
123+
-pkg:k8s.io/client-go/kubernetes/typed/(\w+)/(v[\w\d]+)
124+
alias:${1}${2}client
125+
126+
-pkg:k8s.io/metrics/pkg/apis/metrics/(v[\w\d]+)
127+
alias:metrics${1}
128+
129+
-pkg:github.com/docker/docker/api/types
130+
alias:dockertypes
131+
132+
-pkg:github.com/docker/docker/client
133+
alias:dockerclient
134+
135+
misspell:
136+
locale:US
137+
138+
nestif:
139+
min-complexity:4# Min complexity of if statements (def 5, goal 4)
140+
141+
revive:
142+
# see https://github.com/mgechev/revive#available-rules for details.
143+
ignore-generated-header:true
144+
severity:warning
145+
rules:
146+
-name:atomic
147+
-name:bare-return
148+
-name:blank-imports
149+
-name:bool-literal-in-expr
150+
-name:call-to-gc
151+
-name:confusing-naming
152+
-name:confusing-results
153+
-name:constant-logical-expr
154+
-name:context-as-argument
155+
-name:context-keys-type
156+
-name:deep-exit
157+
-name:defer
158+
-name:dot-imports
159+
-name:duplicated-imports
160+
-name:early-return
161+
-name:empty-block
162+
-name:empty-lines
163+
-name:error-naming
164+
-name:error-return
165+
-name:error-strings
166+
-name:errorf
167+
-name:exported
168+
-name:flag-parameter
169+
-name:get-return
170+
-name:identical-branches
171+
-name:if-return
172+
-name:import-shadowing
173+
-name:increment-decrement
174+
-name:indent-error-flow
175+
-name:modifies-parameter
176+
-name:modifies-value-receiver
177+
-name:package-comments
178+
-name:range
179+
-name:range-val-address
180+
-name:range-val-in-closure
181+
-name:receiver-naming
182+
-name:redefines-builtin-id
183+
-name:string-of-int
184+
-name:struct-tag
185+
-name:superfluous-else
186+
-name:time-naming
187+
-name:unconditional-recursion
188+
-name:unexported-naming
189+
-name:unexported-return
190+
-name:unhandled-error
191+
-name:unnecessary-stmt
192+
-name:unreachable-code
193+
-name:unused-parameter
194+
-name:unused-receiver
195+
-name:var-declaration
196+
-name:var-naming
197+
-name:waitgroup-by-value
198+
199+
issues:
200+
# Rules listed here: https://github.com/securego/gosec#available-rules
201+
exclude-rules:
202+
-path:_test\.go
203+
linters:
204+
# We use assertions rather than explicitly checking errors in tests
205+
-errcheck
206+
207+
fix:true
208+
max-issues-per-linter:0
209+
max-same-issues:0
210+
211+
run:
212+
concurrency:4
213+
skip-dirs:
214+
-node_modules
215+
timeout:5m
216+
217+
# Over time, add more and more linters from
218+
# https://golangci-lint.run/usage/linters/ as the code improves.
219+
linters:
220+
disable-all:true
221+
enable:
222+
-asciicheck
223+
-bidichk
224+
-bodyclose
225+
-contextcheck
226+
-deadcode
227+
-dogsled
228+
-errcheck
229+
-errname
230+
-errorlint
231+
-exportloopref
232+
-forcetypeassert
233+
-gocritic
234+
-gocyclo
235+
-goimports
236+
-gomodguard
237+
-gosec
238+
-gosimple
239+
-govet
240+
-importas
241+
-ineffassign
242+
# - ireturn
243+
-makezero
244+
-misspell
245+
-nilnil
246+
-noctx
247+
-revive
248+
-rowserrcheck
249+
-sqlclosecheck
250+
-staticcheck
251+
-structcheck
252+
-tenv
253+
-typecheck
254+
-unconvert
255+
-unused
256+
-varcheck
257+
-varnamelen
258+
-wastedassign

‎.vscode/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"go.lintTool":"golangci-lint",
3+
"go.lintFlags": ["--fast"],
4+
"go.lintOnSave":"package",
5+
"go.coverOnSave":true,
6+
"go.coverageDecorator": {
7+
"type":"gutter",
8+
"coveredHighlightColor":"rgba(64,128,128,0.5)",
9+
"uncoveredHighlightColor":"rgba(128,64,64,0.25)",
10+
"coveredBorderColor":"rgba(64,128,128,0.5)",
11+
"uncoveredBorderColor":"rgba(128,64,64,0.25)",
12+
"coveredGutterStyle":"blockgreen",
13+
"uncoveredGutterStyle":"blockred"
14+
}
15+
}

‎cmd/coder/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import"fmt"
4+
5+
funcmain() {
6+
fmt.Println("Hello World!")
7+
}

‎codecov.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
codecov:
2+
require_ci_to_pass:false
3+
4+
comment:
5+
show_carryforward_flags:yes
6+
7+
coverage:
8+
notify:
9+
slack:
10+
default:
11+
url:secret:v1::ALa1/e2X+k36fPseab5D7+kBFc9bJyIoIQioD0IMA5jr+0HXVpBRNDCHZhHjCdGc67yff6PPixPEOLwEZpxC37rM23RBZOYlqAq9A5e0MeZVlEoVq19aOYN4Xel17hMJ6GGm7n17wrYpCpcvlVSqNrN0+cr3guVDyG10kQyfh2Y=
12+
threshold:1%
13+
only_pulls:false
14+
branches:
15+
-"main"
16+
status:
17+
project:
18+
default:
19+
target:80%
20+
informational:yes

‎go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
modulegithub.com/coder/coder
2+
3+
go1.17

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp