Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable more linters #473

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v3.4.0
with:
args: --verbose
version: v1.51.2
28 changes: 28 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
issues:
exclude-rules:
- path: promlog/log.go
text: unexported-return
- path: expfmt/expfmt.go
text: var-naming

linters:
enable:
- gocritic
- gofumpt
- goimports
- gosimple
- misspell
- nolintlint
- revive
- unconvert
- unused

linters-settings:
goimports:
local-prefixes: github.com/prometheus

output:
sort-results: true

run:
timeout: 5m
7 changes: 3 additions & 4 deletions config/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func SerialNumber() *big.Int {
serialNumber.Add(&serial, big.NewInt(1))

return &serial

}

func GenerateCertificateAuthority(commonName string, parentCert *x509.Certificate, parentKey *rsa.PrivateKey) (*x509.Certificate, *rsa.PrivateKey, error) {
Expand Down Expand Up @@ -170,7 +169,7 @@ func writeCertificateAndKey(path string, cert *x509.Certificate, key *rsa.Privat
return err
}

if err := os.WriteFile(fmt.Sprintf("%s.crt", path), b.Bytes(), 0644); err != nil {
if err := os.WriteFile(fmt.Sprintf("%s.crt", path), b.Bytes(), 0o644); err != nil {
return err
}

Expand All @@ -179,7 +178,7 @@ func writeCertificateAndKey(path string, cert *x509.Certificate, key *rsa.Privat
return err
}

if err := os.WriteFile(fmt.Sprintf("%s.key", path), b.Bytes(), 0644); err != nil {
if err := os.WriteFile(fmt.Sprintf("%s.key", path), b.Bytes(), 0o644); err != nil {
return err
}

Expand Down Expand Up @@ -239,7 +238,7 @@ func main() {
log.Fatal(err)
}

if err := os.WriteFile("testdata/tls-ca-chain.pem", b.Bytes(), 0644); err != nil {
if err := os.WriteFile("testdata/tls-ca-chain.pem", b.Bytes(), 0o644); err != nil {
log.Fatal(err)
}
}
22 changes: 11 additions & 11 deletions config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var TLSVersions = map[string]TLSVersion{

func (tv *TLSVersion) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
err := unmarshal((*string)(&s))
err := unmarshal(&s)
if err != nil {
return err
}
Expand Down Expand Up @@ -251,12 +251,12 @@ func (o *OAuth2) UnmarshalJSON(data []byte) error {
}

// SetDirectory joins any relative file paths with dir.
func (a *OAuth2) SetDirectory(dir string) {
if a == nil {
func (o *OAuth2) SetDirectory(dir string) {
if o == nil {
return
}
a.ClientSecretFile = JoinDir(dir, a.ClientSecretFile)
a.TLSConfig.SetDirectory(dir)
o.ClientSecretFile = JoinDir(dir, o.ClientSecretFile)
o.TLSConfig.SetDirectory(dir)
}

// LoadHTTPConfig parses the YAML input s into a HTTPClientConfig.
Expand Down Expand Up @@ -1104,9 +1104,9 @@ func (t *tlsRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
}

t.mtx.RLock()
equal := bytes.Equal(caHash[:], t.hashCAData) &&
bytes.Equal(certHash[:], t.hashCertData) &&
bytes.Equal(keyHash[:], t.hashKeyData)
equal := bytes.Equal(caHash, t.hashCAData) &&
bytes.Equal(certHash, t.hashCertData) &&
bytes.Equal(keyHash, t.hashKeyData)
rt := t.rt
t.mtx.RUnlock()
if equal {
Expand All @@ -1129,9 +1129,9 @@ func (t *tlsRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {

t.mtx.Lock()
t.rt = rt
t.hashCAData = caHash[:]
t.hashCertData = certHash[:]
t.hashKeyData = keyHash[:]
t.hashCAData = caHash
t.hashCertData = certHash
t.hashKeyData = keyHash
t.mtx.Unlock()

return rt.RoundTrip(req)
Expand Down
Loading
Loading