Skip to content

Commit 61bff08

Browse files
authored
Merge pull request #11 from tucksaun/ci/golangci-lint
ci: add golangci-lint
2 parents 6cd72c4 + d55dd87 commit 61bff08

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

.github/workflows/test.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ on:
55
push:
66

77
jobs:
8+
lint:
9+
name: Lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: golangci-lint
14+
uses: golangci/golangci-lint-action@v8
15+
816
test:
917
runs-on: ubuntu-latest
1018
strategy:
@@ -20,7 +28,7 @@ jobs:
2028
- '1.24'
2129
name: Go ${{ matrix.go }} test
2230
steps:
23-
- uses: actions/checkout@v2
31+
- uses: actions/checkout@v4
2432
with:
2533
fetch-depth: 0
2634
- name: Setup go

.golangci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: "2"
2+
3+
run:
4+
issues-exit-code: 1
5+
6+
formatters:
7+
enable:
8+
- gofmt
9+
- gci
10+
11+
linters:
12+
enable:
13+
- wrapcheck
14+
settings:
15+
wrapcheck:
16+
ignore-package-globs:
17+
# We already make sure your own packages wrap errors properly
18+
- github.com/symfony-cli/*
19+
errcheck:
20+
exclude-functions:
21+
- github.com/symfony-cli/terminal.Printf
22+
- github.com/symfony-cli/terminal.Println
23+
- github.com/symfony-cli/terminal.Printfln
24+
- github.com/symfony-cli/terminal.Eprintf
25+
- github.com/symfony-cli/terminal.Eprintln
26+
- github.com/symfony-cli/terminal.Eprintfln
27+
- github.com/symfony-cli/terminal.Eprint
28+
- fmt.Fprintln
29+
- fmt.Fprintf
30+
- fmt.Fprint

cert.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (ca *CA) Install(force bool) error {
144144
return err
145145
}
146146
f, _ := os.OpenFile(ca.trustedpath, os.O_RDONLY|os.O_CREATE, 0644)
147-
f.Close()
147+
_ = f.Close()
148148
terminal.Println("The local CA is now installed in the system trust store!")
149149
}
150150
if hasNSS() && (force || !ca.checkNSS()) {
@@ -168,7 +168,9 @@ func (ca *CA) Uninstall() error {
168168
hasCertutil := certutilPath() != ""
169169
if hasNSS() {
170170
if hasCertutil {
171-
ca.uninstallNSS()
171+
if err := ca.uninstallNSS(); err != nil {
172+
terminal.Printf("<warning>WARNING</> an error happened during CA uninstallation from %s: %s!\n", NSSBrowsers, err)
173+
}
172174
} else if CertutilInstallHelp != "" {
173175
terminal.Printf("<warning>WARNING</> \"certutil\" is not available, so the CA can't be automatically uninstalled from %s (if it was ever installed)!\n", NSSBrowsers)
174176
terminal.Printf("You can install \"certutil\" with \"%s\" and re-run the command\n", CertutilInstallHelp)
@@ -204,7 +206,9 @@ func Cert(filename string) (tls.Certificate, error) {
204206
if err != nil {
205207
return tls.Certificate{}, errors.WithStack(err)
206208
}
207-
defer ioutil.WriteFile(filename, pfxData, 0644)
209+
if err := errors.WithStack(ioutil.WriteFile(filename, pfxData, 0644)); err != nil {
210+
return tls.Certificate{}, err
211+
}
208212

209213
certs := [][]byte{domainCert.Raw}
210214
for _, c := range caCerts {

truststore_darwin.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ func (ca *CA) installPlatform() error {
6262
return errors.Wrap(err, "failed to create temp file")
6363
}
6464

65-
defer os.Remove(plistFile.Name())
65+
defer func(name string) {
66+
// a failure during removal of this file is not important
67+
_ = os.Remove(name)
68+
}(plistFile.Name())
6669

6770
cmd = commandWithSudo("security", "trust-settings-export", "-d", plistFile.Name())
6871
if out, err := cmd.CombinedOutput(); err != nil {

truststore_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func getSystemTrust() (string, []string) {
5757
}
5858

5959
func (ca *CA) systemTrustFilename(systemTrustFilenamePattern string) string {
60-
return fmt.Sprintf(systemTrustFilenamePattern, strings.Replace(ca.caUniqueName(), " ", "_", -1))
60+
return fmt.Sprintf(systemTrustFilenamePattern, strings.ReplaceAll(ca.caUniqueName(), " ", "_"))
6161
}
6262

6363
func (ca *CA) installPlatform() error {

truststore_nss.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ func (ca *CA) installNSS() error {
102102
return nil
103103
}
104104

105-
func (ca *CA) uninstallNSS() {
105+
func (ca *CA) uninstallNSS() error {
106106
certutilPath := certutilPath()
107-
ca.forEachNSSProfile(func(profile string) error {
107+
_, err := ca.forEachNSSProfile(func(profile string) error {
108108
err := exec.Command(certutilPath, "-V", "-d", profile, "-u", "L", "-n", ca.caUniqueName()).Run()
109109
if err != nil {
110110
return nil
@@ -115,6 +115,8 @@ func (ca *CA) uninstallNSS() {
115115
}
116116
return nil
117117
})
118+
119+
return err
118120
}
119121

120122
func (ca *CA) forEachNSSProfile(f func(profile string) error) (int, error) {
@@ -156,5 +158,5 @@ func execCertutil(cmd *exec.Cmd) ([]byte, error) {
156158
cmd.Args = append(cmd.Args, origArgs...)
157159
out, err = cmd.CombinedOutput()
158160
}
159-
return out, err
161+
return out, errors.WithStack(err)
160162
}

0 commit comments

Comments
 (0)