mirror of https://github.com/0xERR0R/blocky.git
chore(build): add additional linters (#774)
* chore(build): add nolintlint linter * chore(build): add usestdlibvars linter
This commit is contained in:
parent
2b49c2048f
commit
f78a57a94d
|
@ -39,6 +39,7 @@ linters:
|
|||
- nilerr
|
||||
- nilnil
|
||||
- nlreturn
|
||||
- nolintlint
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
|
@ -51,6 +52,7 @@ linters:
|
|||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- usestdlibvars
|
||||
- wastedassign
|
||||
- whitespace
|
||||
- wsl
|
||||
|
@ -61,6 +63,7 @@ linters:
|
|||
- structcheck
|
||||
- deadcode
|
||||
- varcheck
|
||||
- forbidigo
|
||||
|
||||
disable-all: false
|
||||
presets:
|
||||
|
|
|
@ -27,7 +27,7 @@ func randString(n int) string {
|
|||
b := make([]byte, n)
|
||||
|
||||
for i := range b {
|
||||
b[i] = charPool[rand.Intn(len(charPool))] // nolint:gosec
|
||||
b[i] = charPool[rand.Intn(len(charPool))]
|
||||
}
|
||||
|
||||
return string(b)
|
||||
|
@ -37,7 +37,7 @@ func createTestdata(count int) []string {
|
|||
var result []string
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
result = append(result, randString(8+rand.Intn(20))) // nolint:gosec
|
||||
result = append(result, randString(8+rand.Intn(20)))
|
||||
}
|
||||
|
||||
return result
|
||||
|
|
|
@ -451,6 +451,7 @@ func extractNet(upstream string) (NetProtocol, string) {
|
|||
}
|
||||
|
||||
// Config main configuration
|
||||
//
|
||||
//nolint:maligned
|
||||
type Config struct {
|
||||
Upstream UpstreamConfig `yaml:"upstream"`
|
||||
|
|
|
@ -36,7 +36,7 @@ const (
|
|||
ApplicationStarted = "application:started"
|
||||
)
|
||||
|
||||
// nolint
|
||||
//nolint:gochecknoglobals
|
||||
var evtBus = EventBus.New()
|
||||
|
||||
// Bus returns the global bus instance
|
||||
|
|
|
@ -41,7 +41,7 @@ func TestServer(data string) *httptest.Server {
|
|||
// DoGetRequest performs a GET request
|
||||
func DoGetRequest(url string,
|
||||
fn func(w http.ResponseWriter, r *http.Request)) (*httptest.ResponseRecorder, *bytes.Buffer) {
|
||||
r, _ := http.NewRequest("GET", url, nil)
|
||||
r, _ := http.NewRequest(http.MethodGet, url, nil)
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
handler := http.HandlerFunc(fn)
|
||||
|
|
|
@ -401,7 +401,7 @@ func createTestListFile(dir string, totalLines int) string {
|
|||
|
||||
w := bufio.NewWriter(file)
|
||||
for i := 0; i < totalLines; i++ {
|
||||
fmt.Fprintln(w, RandStringBytes(8+rand.Intn(10))+".com") // nolint:gosec
|
||||
fmt.Fprintln(w, RandStringBytes(8+rand.Intn(10))+".com")
|
||||
}
|
||||
w.Flush()
|
||||
|
||||
|
@ -413,7 +413,7 @@ const charpool = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
|
|||
func RandStringBytes(n int) string {
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = charpool[rand.Intn(len(charpool))] // nolint:gosec
|
||||
b[i] = charpool[rand.Intn(len(charpool))]
|
||||
}
|
||||
|
||||
return string(b)
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
)
|
||||
|
||||
// Logger is the global logging instance
|
||||
//
|
||||
//nolint:gochecknoglobals
|
||||
var logger *logrus.Logger
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
// nolint
|
||||
//nolint:gochecknoglobals
|
||||
var reg = prometheus.NewRegistry()
|
||||
|
||||
// RegisterMetric registers prometheus collector
|
||||
|
|
|
@ -255,7 +255,7 @@ var _ = Describe("Bootstrap", Label("bootstrap"), func() {
|
|||
Describe("HTTP Transport", func() {
|
||||
It("uses the bootstrap upstream", func() {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(200)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
DeferCleanup(server.Close)
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ var _ = Describe("HostsFileResolver", func() {
|
|||
When("Hosts file cannot be located", func() {
|
||||
BeforeEach(func() {
|
||||
sut = NewHostsFileResolver(config.HostsFileConfig{
|
||||
//nolint:gosec
|
||||
Filepath: fmt.Sprintf("/tmp/blocky/file-%d", rand.Uint64()),
|
||||
HostsTTL: config.Duration(time.Duration(TTL) * time.Second),
|
||||
}).(*HostsFileResolver)
|
||||
|
|
|
@ -126,7 +126,7 @@ func (r *httpUpstreamClient) callExternal(msg *dns.Msg,
|
|||
return nil, 0, fmt.Errorf("can't pack message: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", upstreamURL, bytes.NewReader(rawDNSMessage))
|
||||
req, err := http.NewRequest(http.MethodPost, upstreamURL, bytes.NewReader(rawDNSMessage))
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("can't create the new request %w", err)
|
||||
|
|
|
@ -141,7 +141,6 @@ var _ = Describe("UpstreamResolver", Label("upstreamResolver"), func() {
|
|||
sut, _ = NewUpstreamResolver(upstream, skipUpstreamCheck)
|
||||
|
||||
// use insecure certificates for test doh upstream
|
||||
// nolint:gosec
|
||||
sut.upstreamClient.(*httpUpstreamClient).client.Transport = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
|
@ -161,7 +160,7 @@ var _ = Describe("UpstreamResolver", Label("upstreamResolver"), func() {
|
|||
When("Configured DOH resolver returns wrong http status code", func() {
|
||||
BeforeEach(func() {
|
||||
modifyHTTPRespFn = func(w http.ResponseWriter) {
|
||||
w.WriteHeader(500)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
It("should return error", func() {
|
||||
|
|
|
@ -112,6 +112,7 @@ func retrieveCertificate(cfg *config.Config) (cert tls.Certificate, err error) {
|
|||
}
|
||||
|
||||
// NewServer creates new server instance with passed config
|
||||
//
|
||||
//nolint:funlen
|
||||
func NewServer(cfg *config.Config) (server *Server, err error) {
|
||||
log.ConfigureLogger(cfg.LogLevel, cfg.LogFormat, cfg.LogTimestamp)
|
||||
|
@ -296,7 +297,7 @@ func createUDPServer(address string) (*dns.Server, error) {
|
|||
func createSelfSignedCert() (tls.Certificate, error) {
|
||||
// Create CA
|
||||
ca := &x509.Certificate{
|
||||
SerialNumber: big.NewInt(int64(mrand.Intn(math.MaxInt))), //nolint:gosec
|
||||
SerialNumber: big.NewInt(int64(mrand.Intn(math.MaxInt))),
|
||||
NotBefore: time.Now(),
|
||||
NotAfter: time.Now().AddDate(caExpiryYears, 0, 0),
|
||||
IsCA: true,
|
||||
|
@ -339,7 +340,7 @@ func createSelfSignedCert() (tls.Certificate, error) {
|
|||
|
||||
// Create certificate
|
||||
cert := &x509.Certificate{
|
||||
SerialNumber: big.NewInt(int64(mrand.Intn(math.MaxInt))), //nolint:gosec
|
||||
SerialNumber: big.NewInt(int64(mrand.Intn(math.MaxInt))),
|
||||
DNSNames: []string{"*"},
|
||||
NotBefore: time.Now(),
|
||||
NotAfter: time.Now().AddDate(certExpiryYears, 0, 0),
|
||||
|
|
Loading…
Reference in New Issue