Skip to content

Commit f65e21e

Browse files
committed
Remove unused return values
1 parent 010a609 commit f65e21e

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

.golangci.yml

+31-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ linters:
66
- unconvert
77
- staticcheck
88
- ineffassign
9+
- unparam
910

1011
issues:
1112
# Disable the default exclude list so that all excludes are explicitly
@@ -16,7 +17,36 @@ issues:
1617
# Temp Ignore SA9004: only the first constant in this group has an explicit type
1718
# https://staticcheck.io/docs/checks#SA9004
1819
- linters: [staticcheck]
19-
text: "SA9004:"
20+
text: 'SA9004:'
21+
22+
# An argument that always receives the same value is often not a problem.
23+
- linters: [unparam]
24+
text: 'always receives'
25+
26+
# Often functions will implement an interface that returns an error without
27+
# needing to return an error. Sometimes the error return value is unnecessary
28+
# but a linter can not tell the difference.
29+
- linters: [unparam]
30+
text: 'result \d+ \(error\) is always nil'
31+
32+
# Allow unused parameters to start with an underscore. Arguments with a name
33+
# of '_' are already ignored.
34+
# Ignoring longer names that start with underscore allow for better
35+
# self-documentation than a single underscore by itself. Underscore arguments
36+
# should generally only be used when a function is implementing an interface.
37+
- linters: [unparam]
38+
text: '`_[^`]*` is unused'
39+
40+
# Temp ignore some common unused parameters so that unparam can be added
41+
# incrementally.
42+
- linters: [unparam]
43+
text: '`(t|resp|req|entMeta)` is unused'
44+
45+
# Temp ignore everything in _oss(_test).go and _ent(_test).go. Many of these
46+
# could use underscore to ignore the unused arguments, but the "always returns"
47+
# issue will likely remain in oss, and will need to be excluded.
48+
- linters: [unparam]
49+
path: '(_oss.go|_oss_test.go|_ent.go|_ent_test.go)'
2050

2151
linters-settings:
2252
gofmt:

agent/connect/ca/provider_consul.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (c *ConsulProvider) State() (map[string]string, error) {
139139

140140
// ActiveRoot returns the active root CA certificate.
141141
func (c *ConsulProvider) ActiveRoot() (string, error) {
142-
_, providerState, err := c.getState()
142+
providerState, err := c.getState()
143143
if err != nil {
144144
return "", err
145145
}
@@ -150,7 +150,7 @@ func (c *ConsulProvider) ActiveRoot() (string, error) {
150150
// GenerateRoot initializes a new root certificate and private key
151151
// if needed.
152152
func (c *ConsulProvider) GenerateRoot() error {
153-
_, providerState, err := c.getState()
153+
providerState, err := c.getState()
154154
if err != nil {
155155
return err
156156
}
@@ -205,7 +205,7 @@ func (c *ConsulProvider) GenerateRoot() error {
205205
// GenerateIntermediateCSR creates a private key and generates a CSR
206206
// for another datacenter's root to sign.
207207
func (c *ConsulProvider) GenerateIntermediateCSR() (string, error) {
208-
_, providerState, err := c.getState()
208+
providerState, err := c.getState()
209209
if err != nil {
210210
return "", err
211211
}
@@ -249,7 +249,7 @@ func (c *ConsulProvider) GenerateIntermediateCSR() (string, error) {
249249
// SetIntermediate validates that the given intermediate is for the right private key
250250
// and writes the given intermediate and root certificates to the state.
251251
func (c *ConsulProvider) SetIntermediate(intermediatePEM, rootPEM string) error {
252-
_, providerState, err := c.getState()
252+
providerState, err := c.getState()
253253
if err != nil {
254254
return err
255255
}
@@ -289,7 +289,7 @@ func (c *ConsulProvider) ActiveIntermediate() (string, error) {
289289
return c.ActiveRoot()
290290
}
291291

292-
_, providerState, err := c.getState()
292+
providerState, err := c.getState()
293293
if err != nil {
294294
return "", err
295295
}
@@ -325,7 +325,7 @@ func (c *ConsulProvider) Sign(csr *x509.CertificateRequest) (string, error) {
325325
defer c.Unlock()
326326

327327
// Get the provider state
328-
_, providerState, err := c.getState()
328+
providerState, err := c.getState()
329329
if err != nil {
330330
return "", err
331331
}
@@ -437,7 +437,7 @@ func (c *ConsulProvider) Sign(csr *x509.CertificateRequest) (string, error) {
437437
// are met. It should return a signed CA certificate with a path length constraint
438438
// of 0 to ensure that the certificate cannot be used to generate further CA certs.
439439
func (c *ConsulProvider) SignIntermediate(csr *x509.CertificateRequest) (string, error) {
440-
_, providerState, err := c.getState()
440+
providerState, err := c.getState()
441441
if err != nil {
442442
return "", err
443443
}
@@ -520,7 +520,7 @@ func (c *ConsulProvider) CrossSignCA(cert *x509.Certificate) (string, error) {
520520
}
521521

522522
// Get the provider state
523-
_, providerState, err := c.getState()
523+
providerState, err := c.getState()
524524
if err != nil {
525525
return "", err
526526
}
@@ -586,18 +586,18 @@ func (c *ConsulProvider) SupportsCrossSigning() (bool, error) {
586586

587587
// getState returns the current provider state from the state delegate, and returns
588588
// ErrNotInitialized if no entry is found.
589-
func (c *ConsulProvider) getState() (uint64, *structs.CAConsulProviderState, error) {
589+
func (c *ConsulProvider) getState() (*structs.CAConsulProviderState, error) {
590590
stateStore := c.Delegate.State()
591-
idx, providerState, err := stateStore.CAProviderState(c.id)
591+
_, providerState, err := stateStore.CAProviderState(c.id)
592592
if err != nil {
593-
return 0, nil, err
593+
return nil, err
594594
}
595595

596596
if providerState == nil {
597-
return 0, nil, ErrNotInitialized
597+
return nil, ErrNotInitialized
598598
}
599599

600-
return idx, providerState, nil
600+
return providerState, nil
601601
}
602602

603603
func (c *ConsulProvider) incrementAndGetNextSerialNumber() (uint64, error) {

agent/dns.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,8 @@ func trimUDPResponse(req, resp *dns.Msg, udpAnswerLimit int) (trimmed bool) {
11381138
}
11391139

11401140
// trimDNSResponse will trim the response for UDP and TCP
1141-
func (d *DNSServer) trimDNSResponse(cfg *dnsConfig, network string, req, resp *dns.Msg) (trimmed bool) {
1141+
func (d *DNSServer) trimDNSResponse(cfg *dnsConfig, network string, req, resp *dns.Msg) {
1142+
var trimmed bool
11421143
if network != "tcp" {
11431144
trimmed = trimUDPResponse(req, resp, cfg.UDPAnswerLimit)
11441145
} else {
@@ -1148,7 +1149,6 @@ func (d *DNSServer) trimDNSResponse(cfg *dnsConfig, network string, req, resp *d
11481149
if trimmed && cfg.EnableTruncate {
11491150
resp.Truncated = true
11501151
}
1151-
return trimmed
11521152
}
11531153

11541154
// lookupServiceNodes returns nodes with a given service.

0 commit comments

Comments
 (0)