Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
v2: Project-and-CI-wide linter config (#2812)
* v2: split golangci-lint configuration into its own file to allow code editors to take advantage of it * v2: simplify code * v2: set the correct lint output formatting * v2: invert the logic of linter's configuration of output formatting to allow the editor convenience over CI-specific customization. Customize the output format in CI by passing the flag. * v2: remove irrelevant golangci-lint config
Mohammed Al Sahaf committed
Oct 16, 2019 at 00:37 UTC
e3726588b416682db28ea9173bf2c36e4554ce05
5 files changed
+52
-4
.golangci.yml
new
+49
@@ -0,0 +1,49 @@
1
+linters-settings:
2
+ errcheck:
3
+ ignore: fmt:.*,io/ioutil:^Read.*,github.com/caddyserver/caddy/v2/caddyconfig:RegisterAdapter,github.com/caddyserver/caddy/v2:RegisterModule
4
+ ignoretests: true
5
+ misspell:
6
+ locale: US
7
+
8
+linters:
9
+ enable:
10
+ - bodyclose
11
+ - errcheck
12
+ - gofmt
13
+ - goimports
14
+ - gosec
15
+ - ineffassign
16
+ - misspell
17
+
18
+run:
19
+ # default concurrency is a available CPU number.
20
+ # concurrency: 4 # explicitly omit this value to fully utilize available resources.
21
+ deadline: 5m
22
+ issues-exit-code: 1
23
+ tests: false
24
+
25
+# output configuration options
26
+output:
27
+ format: 'colored-line-number'
28
+ print-issued-lines: true
29
+ print-linter-name: true
30
+
31
+issues:
32
+ exclude-rules:
33
+ # we aren't calling unknown URL
34
+ - text: "G107" # G107: Url provided to HTTP request as taint input
35
+ linters:
36
+ - gosec
37
+ # as a web server that's expected to handle any template, this is totally in the hands of the user.
38
+ - text: "G203" # G203: Use of unescaped data in HTML templates
39
+ linters:
40
+ - gosec
41
+ # we're shelling out to known commands, not relying on user-defined input.
42
+ - text: "G204" # G204: Audit use of command execution
43
+ linters:
44
+ - gosec
45
+ # the choice of weakrand is deliberate, hence the named import "weakrand"
46
+ - path: modules/caddyhttp/reverseproxy/selectionpolicies.go
47
+ text: "G404" # G404: Insecure random number source (rand)
48
+ linters:
49
+ - gosec
azure-pipelines.yml
+2
-1
@@ -89,7 +89,8 @@ steps:
89
displayName: Get dependencies
90
91
- script: |
92
- (golangci-lint run --out-format junit-xml -E gofmt -E goimports -E misspell) > test-results/lint-result.xml
92
+ # its behavior is governed by .golangci.yml
93
+ (golangci-lint run --out-format junit-xml) > test-results/lint-result.xml
94
exit 0
95
workingDirectory: '$(modulePath)'
96
continueOnError: true
caddyconfig/caddyfile/lexer.go
-1
@@ -107,7 +107,6 @@ func (l *lexer) next() bool {
107
escaped = false
108
} else {
109
if ch == '"' {
110
- quoted = false
110
return makeToken()
111
}
112
}
cmd/main.go
-1
@@ -118,7 +118,6 @@ func loadConfig(configFile, adapterName string) ([]byte, error) {
118
if os.IsNotExist(err) {
119
// okay, no default Caddyfile; pretend like this never happened
120
cfgAdapter = nil
121
- err = nil
121
} else if err != nil {
122
// default Caddyfile exists, but error reading it
123
return nil, fmt.Errorf("reading default Caddyfile: %v", err)
modules/caddyhttp/server.go
+1
-1
@@ -169,7 +169,7 @@ func (s *Server) enforcementHandler(w http.ResponseWriter, r *http.Request, next
169
if err != nil {
170
hostname = r.Host // OK; probably lacked port
171
}
172
- if strings.ToLower(r.TLS.ServerName) != strings.ToLower(hostname) {
172
+ if !strings.EqualFold(r.TLS.ServerName, hostname) {
173
err := fmt.Errorf("strict host matching: TLS ServerName (%s) and HTTP Host (%s) values differ",
174
r.TLS.ServerName, hostname)
175
r.Close = true