Skip to content

Commit

Permalink
Fix nolint warnings and adhere to best practices (knative#1823)
Browse files Browse the repository at this point in the history
  • Loading branch information
markusthoemmes authored Oct 20, 2020
1 parent 5c30f48 commit 385c8b9
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion configmap/hash-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func processFile(fileName string) error {
return err
}

// nolint:gosec // This is not security critical so open permissions are fine.
//nolint:gosec // This is not security critical so open permissions are fine.
if err := ioutil.WriteFile(fileName, out, 0644); err != nil {
return fmt.Errorf("failed to write file: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ type Impl struct {

// ControllerOptions encapsulates options for creating a new controller,
// including throttling and stats behavior.
type ControllerOptions struct { //nolint for backcompat.
type ControllerOptions struct { //nolint // for backcompat.
WorkQueueName string
Logger *zap.SugaredLogger
Reporter StatsReporter
Expand Down
6 changes: 3 additions & 3 deletions kmeta/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the license.
package kmeta

import (
"crypto/md5" // nolint:gosec // No strong cryptography needed.
"crypto/md5" //nolint:gosec // No strong cryptography needed.
"fmt"
"strings"
)
Expand All @@ -42,7 +42,7 @@ func ChildName(parent, suffix string) string {
// If the suffix is longer than the longest allowed suffix, then
// we hash the whole combined string and use that as the suffix.
if head-len(suffix) <= 0 {
// nolint:gosec // No strong cryptography needed.
//nolint:gosec // No strong cryptography needed.
h := md5.Sum([]byte(parent + suffix))
// 1. trim parent, if needed
if head < len(parent) {
Expand All @@ -59,7 +59,7 @@ func ChildName(parent, suffix string) string {
// remove it.
return strings.TrimRight(ret, "-")
}
// nolint:gosec // No strong cryptography needed.
//nolint:gosec // No strong cryptography needed.
n = fmt.Sprintf("%s%x", parent[:head-len(suffix)], md5.Sum([]byte(parent)))
}
return n + suffix
Expand Down
4 changes: 2 additions & 2 deletions metrics/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func prometheusPort() (int, error) {

// JsonToMetricsOptions converts a json string of a
// ExporterOptions. Returns a non-nil ExporterOptions always.
func JsonToMetricsOptions(jsonOpts string) (*ExporterOptions, error) { // nolint No rename due to backwards incompatibility.
func JsonToMetricsOptions(jsonOpts string) (*ExporterOptions, error) { //nolint // No rename due to backwards incompatibility.
var opts ExporterOptions
if jsonOpts == "" {
return nil, errors.New("json options string is empty")
Expand All @@ -360,7 +360,7 @@ func JsonToMetricsOptions(jsonOpts string) (*ExporterOptions, error) { // nolint
}

// MetricsOptionsToJson converts a ExporterOptions to a json string.
func MetricsOptionsToJson(opts *ExporterOptions) (string, error) { // nolint No rename due to backwards incompatibility.
func MetricsOptionsToJson(opts *ExporterOptions) (string, error) { //nolint // No rename due to backwards incompatibility.
if opts == nil {
return "", nil
}
Expand Down
2 changes: 1 addition & 1 deletion reconciler/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewEvent(eventtype, reason, messageFmt string, args ...interface{}) Event {

// ReconcilerEvent wraps the fields required for recorders to create a
// kubernetes recorder Event.
type ReconcilerEvent struct { //nolint for backcompat.
type ReconcilerEvent struct { //nolint:golint // for backcompat.
EventType string
Reason string
Format string
Expand Down
2 changes: 1 addition & 1 deletion test/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"google.golang.org/api/option"
)

//nolint there's also Client so they collide.
//nolint // there's also Client so they collide.
type GCSClient struct {
*storage.Client
}
Expand Down
2 changes: 1 addition & 1 deletion test/logging/example_tlogger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// nolint
//nolint
package logging_test

import (
Expand Down
2 changes: 1 addition & 1 deletion test/logging/tlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (o *TLogger) interfacesToFields(things ...interface{}) []interface{} {
return fields
}

func (o *TLogger) errorWithRuntimeCheck(stringThenKeysAndValues ...interface{}) (error, string, []interface{}) { //nolint Returning the error first is okay and expected here.
func (o *TLogger) errorWithRuntimeCheck(stringThenKeysAndValues ...interface{}) (error, string, []interface{}) { //nolint // Returning the error first is okay and expected here.
if len(stringThenKeysAndValues) == 0 {
return nil, "", nil
}
Expand Down
2 changes: 1 addition & 1 deletion test/mako/config/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"os"
"path/filepath"

"github.com/golang/protobuf/proto" //nolint apis incompatible with the new version
"github.com/golang/protobuf/proto" //nolint // apis incompatible with the new version
mpb "github.com/google/mako/spec/proto/mako_go_proto"
)

Expand Down
2 changes: 1 addition & 1 deletion test/mako/stub-sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"net/http"
"strings"

"github.com/golang/protobuf/jsonpb" //nolint: the newer package has different interface.
"github.com/golang/protobuf/jsonpb" //nolint // the newer package has different interface.
mako "github.com/google/mako/spec/proto/mako_go_proto"

"log"
Expand Down
2 changes: 1 addition & 1 deletion testutils/clustermanager/perf-tests/pkg/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
)

// backupLocations are used in retrying cluster creation, if stockout happens in one location.
// nolint // TODO(chizhg): it's currently not used, use it in the cluster creation retry logic.
//nolint // TODO(chizhg): it's currently not used, use it in the cluster creation retry logic.
var backupLocations = []string{"us-west1", "us-west2", "us-east1"}

// GKECluster saves the config information for the GKE cluster
Expand Down
4 changes: 2 additions & 2 deletions tracing/config/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func NewTracingConfigFromConfigMap(config *corev1.ConfigMap) (*Config, error) {

// JsonToTracingConfig converts a json string of a Config.
// Returns a non-nil Config always and an eventual error.
func JsonToTracingConfig(jsonCfg string) (*Config, error) { //nolint:stylecheck for backcompat.
func JsonToTracingConfig(jsonCfg string) (*Config, error) { //nolint // for backcompat.

if jsonCfg == "" {
return NoopConfig(), errors.New("empty json tracing config")
Expand All @@ -155,7 +155,7 @@ func JsonToTracingConfig(jsonCfg string) (*Config, error) { //nolint:stylecheck
}

// TracingConfigToJson converts a Config to a json string.
func TracingConfigToJson(cfg *Config) (string, error) { //nolint:stylecheck for backcompat.
func TracingConfigToJson(cfg *Config) (string, error) { //nolint // for backcompat.
if cfg == nil {
return "", nil
}
Expand Down

0 comments on commit 385c8b9

Please sign in to comment.