go install/go get installation isn't recommended because of the following points: 1. some users use -u flag for go get, which upgrades our dependencies. Resulting configuration wasn't tested and isn't guaranteed to work. 2. go.mod replacement directive doesn't apply. It means a user will be using patched version of golangci-lint if we use such replacements. 3. it's stability depends on a user's Go version (e.g. on this compiler Go <= 1.12 bug). 4. we've encountered a lot of issues with Go modules hashes. 5. it allows installation from master branch which can't be considered stable. 6. it's slower than binary installation
// Wait an initial amount to have consistently slotted intervals. evalTimestamp := g.EvalTimestamp(time.Now().UnixNano()).Add(g.interval) select { case <-time.After(time.Until(evalTimestamp)): case <-g.done: return }
// The assumption here is that since the ticker was started after having // waited for `evalTimestamp` to pass, the ticks will trigger soon // after each `evalTimestamp + N * g.interval` occurrence. tick := time.NewTicker(g.interval) defer tick.Stop()
deferfunc() { if !g.markStale { return } gofunc(now time.Time) { for _, rule := range g.seriesInPreviousEval { for _, r := range rule { g.staleSeries = append(g.staleSeries, r) } } // That can be garbage collected at this point. g.seriesInPreviousEval = nil // Wait for 2 intervals to give the opportunity to renamed rules // to insert new series in the tsdb. At this point if there is a // renamed rule, it should already be started. select { case <-g.managerDone: case <-time.After(2 * g.interval): g.cleanupStaleSeries(ctx, now) } }(time.Now()) }()
g.evalIterationFunc(ctx, g, evalTimestamp) if g.shouldRestore { // If we have to restore, we wait for another Eval to finish. // The reason behind this is, during first eval (or before it) // we might not have enough data scraped, and recording rules would not // have updated the latest values, on which some alerts might depend. select { case <-g.done: return case <-tick.C: missed := (time.Since(evalTimestamp) / g.interval) - 1 if missed > 0 { g.metrics.IterationsMissed.WithLabelValues(GroupKey(g.file, g.name)).Add(float64(missed)) g.metrics.IterationsScheduled.WithLabelValues(GroupKey(g.file, g.name)).Add(float64(missed)) } evalTimestamp = evalTimestamp.Add((missed + 1) * g.interval) g.evalIterationFunc(ctx, g, evalTimestamp) }
/Users/fliter/video-tmp/kubernetes/cluster/images/etcd/migrate/data_dir.go:167:21: Duplicate words (to) found /Users/fliter/video-tmp/kubernetes/pkg/apis/core/types.go:3859:2: Duplicate words (LoadBalancer) found /Users/fliter/video-tmp/kubernetes/pkg/apis/core/types.go:5659:2: Duplicate words (P) found /Users/fliter/video-tmp/kubernetes/pkg/apis/core/types.go:5694:2: Duplicate words (P) found /Users/fliter/video-tmp/kubernetes/pkg/apis/core/types.go:5723:2: Duplicate words (P) found /Users/fliter/video-tmp/kubernetes/pkg/apis/apps/types.go:610:2: Duplicate words (during) found /Users/fliter/video-tmp/kubernetes/pkg/controller/garbagecollector/graph_builder.go:87:2: Duplicate words (after) found /Users/fliter/video-tmp/kubernetes/pkg/apis/storage/types.go:606:2: Duplicate words (be) found /Users/fliter/video-tmp/kubernetes/plugin/pkg/auth/authorizer/node/graph.go:77:1: Duplicate words (pod) found /Users/fliter/video-tmp/kubernetes/plugin/pkg/auth/authorizer/node/graph.go:79:1: Duplicate words (pv) found /Users/fliter/video-tmp/kubernetes/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy.go:209:4: Duplicate words (information) found /Users/fliter/video-tmp/kubernetes/pkg/apis/certificates/types.go:74:2: Duplicate words (and) found /Users/fliter/video-tmp/kubernetes/pkg/apis/networking/types.go:485:1: Duplicate words (where) found /Users/fliter/video-tmp/kubernetes/pkg/apis/batch/types.go:514:2: Duplicate words (new) found /Users/fliter/video-tmp/kubernetes/pkg/volume/volume.go:289:2: Duplicate words (the) found /Users/fliter/video-tmp/kubernetes/pkg/controlplane/controller/clusterauthenticationtrust/cluster_authentication_trust_controller.go:206:2: Duplicate words (that) found /Users/fliter/video-tmp/kubernetes/pkg/registry/core/service/ipallocator/allocator.go:77:1: Duplicate words (r.base) found /Users/fliter/video-tmp/kubernetes/pkg/registry/core/service/storage/alloc.go:214:4: Duplicate words (than) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:3760:21: Duplicate words (during) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:6408:21: Duplicate words (during) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:12780:21: Duplicate words (new) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:13586:21: Duplicate words (new) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:13949:21: Duplicate words (and) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:14272:21: Duplicate words (and) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:22099:21: Duplicate words (of) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:25687:21: Duplicate words (P) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:25703:21: Duplicate words (P) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:25717:21: Duplicate words (P) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:28505:18: Duplicate words (where) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:29949:21: Duplicate words (during) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:33450:18: Duplicate words (where) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:34593:18: Duplicate words (where) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:39577:21: Duplicate words (be) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:40165:21: Duplicate words (be) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:40907:21: Duplicate words (be) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:44173:18: Duplicate words (that) found /Users/fliter/video-tmp/kubernetes/pkg/generated/openapi/zz_generated.openapi.go:44181:18: Duplicate words (that) found /Users/fliter/video-tmp/kubernetes/pkg/controller/endpoint/endpoints_controller.go:239:4: Duplicate words (the) found /Users/fliter/video-tmp/kubernetes/pkg/util/goroutinemap/exponentialbackoff/exponential_backoff.go:102:1: Duplicate words (returned) found /Users/fliter/video-tmp/kubernetes/pkg/volume/util/operationexecutor/operation_generator.go:1161:4: Duplicate words (is) found /Users/fliter/video-tmp/kubernetes/pkg/controller/volume/ephemeral/controller.go:67:2: Duplicate words (indexer) found /Users/fliter/video-tmp/kubernetes/pkg/volume/awsebs/aws_ebs_block.go:61:2: Duplicate words (globalMapPath) found /Users/fliter/video-tmp/kubernetes/pkg/volume/awsebs/aws_util.go:303:2: Duplicate words (vol-1234) found /Users/fliter/video-tmp/kubernetes/pkg/volume/azuredd/azure_dd_block.go:62:2: Duplicate words (globalMapPath) found /Users/fliter/video-tmp/kubernetes/pkg/volume/fc/fc.go:308:2: Duplicate words (globalMapPathUUID) found /Users/fliter/video-tmp/kubernetes/pkg/volume/gcepd/gce_pd_block.go:64:2: Duplicate words (globalMapPath) found /Users/fliter/video-tmp/kubernetes/pkg/volume/iscsi/iscsi.go:294:2: Duplicate words (globalMapPathUUID) found /Users/fliter/video-tmp/kubernetes/pkg/volume/iscsi/iscsi.go:658:2: Duplicate words (globalMapPath) found /Users/fliter/video-tmp/kubernetes/pkg/volume/rbd/rbd.go:454:2: Duplicate words (globalMapPath) found /Users/fliter/video-tmp/kubernetes/pkg/volume/vsphere_volume/vsphere_volume_block.go:59:2: Duplicate words (globalMapPath) found /Users/fliter/video-tmp/kubernetes/pkg/proxy/ipvs/graceful_termination.go:70:1: Duplicate words (remove) found /Users/fliter/video-tmp/kubernetes/pkg/scheduler/internal/cache/interface.go:37:1: Duplicate words (v) found /Users/fliter/video-tmp/kubernetes/cmd/kubeadm/app/phases/controlplane/manifests.go:205:3: Duplicate words (localhost) found /Users/fliter/video-tmp/kubernetes/cmd/kubeadm/app/phases/controlplane/manifests.go:130:16: Duplicate words (run) found /Users/fliter/video-tmp/kubernetes/cmd/kubeadm/app/phases/etcd/local.go:272:15: Duplicate words (run) found /Users/fliter/video-tmp/kubernetes/cmd/kubeadm/app/cmd/completion.go:143:23: Duplicate words (fi,shift) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/cm/topologymanager/policy.go:320:3: Duplicate words (the) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/pluginmanager/cache/types.go:34:1: Duplicate words (v) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/pluginmanager/cache/types.go:35:1: Duplicate words (Out) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/volumemanager/cache/actual_state_of_world.go:458:2: Duplicate words (at) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/kubelet_pods.go:375:3: Duplicate words (podIPs) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/pod_workers.go:919:5: Duplicate words (the) found /Users/fliter/video-tmp/kubernetes/test/e2e/framework/framework.go:129:1: Duplicate words (with) found /Users/fliter/video-tmp/kubernetes/test/e2e/framework/log.go:83:2: Duplicate words (the) found /Users/fliter/video-tmp/kubernetes/test/e2e/common/node/container_probe.go:664:8: Duplicate words (script) found /Users/fliter/video-tmp/kubernetes/test/e2e/common/node/container_probe.go:676:8: Duplicate words (script) found /Users/fliter/video-tmp/kubernetes/test/e2e/storage/utils/ebs.go:49:1: Duplicate words (to) found /Users/fliter/video-tmp/kubernetes/test/e2e/apps/statefulset.go:1665:1: Duplicate words (to) found /Users/fliter/video-tmp/kubernetes/test/e2e/apimachinery/discovery.go:71:3: Duplicate words (resources) found /Users/fliter/video-tmp/kubernetes/test/e2e/instrumentation/logging/utils/wait.go:75:1: Duplicate words (still) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:810:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:822:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:823:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:824:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:825:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:826:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:827:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:828:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:829:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:833:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:834:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:835:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:836:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:837:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:838:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:839:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:840:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/netpol/network_policy.go:841:4: Duplicate words (X) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/network_tiers.go:162:2: Duplicate words (the) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/networking_perf.go:266:3: Duplicate words (three-node-ipv6-worker2) found /Users/fliter/video-tmp/kubernetes/test/e2e/network/service.go:320:1: Duplicate words (the) found /Users/fliter/video-tmp/kubernetes/test/e2e/storage/testsuites/capacity.go:209:1: Duplicate words (when) found /Users/fliter/video-tmp/kubernetes/test/e2e/windows/security_context.go:137:3: Duplicate words (the) found /Users/fliter/video-tmp/kubernetes/test/e2e/windows/host_process.go:466:32: Duplicate words (create) found /Users/fliter/video-tmp/kubernetes/test/images/regression-issue-74839/tcp.go:159:3: Duplicate words (IPv6) found /Users/fliter/video-tmp/kubernetes/cluster/gce/gci/append_or_replace_prefixed_line_test.go:59:25: Duplicate words (helloworld) found /Users/fliter/video-tmp/kubernetes/cmd/kubeadm/app/cmd/upgrade/plan_test.go:369:26: Duplicate words (v1.19.3) found /Users/fliter/video-tmp/kubernetes/cmd/kubeadm/app/phases/controlplane/manifests_test.go:98:16: Duplicate words (KubeAPIServer) found /Users/fliter/video-tmp/kubernetes/pkg/apis/apps/validation/validation_test.go:1062:10: Duplicate words (update) found /Users/fliter/video-tmp/kubernetes/pkg/apis/core/validation/events_test.go:377:14: Duplicate words (zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz) found /Users/fliter/video-tmp/kubernetes/pkg/apis/core/validation/events_test.go:569:14: Duplicate words (zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz) found /Users/fliter/video-tmp/kubernetes/pkg/apis/core/validation/validation_test.go:4436:10: Duplicate words (dot) found /Users/fliter/video-tmp/kubernetes/pkg/apis/core/validation/validation_test.go:4458:10: Duplicate words (dot) found /Users/fliter/video-tmp/kubernetes/pkg/apis/core/validation/validation_test.go:4480:10: Duplicate words (dot) found /Users/fliter/video-tmp/kubernetes/pkg/controller/controller_ref_manager_test.go:287:18: Duplicate words (uid) found /Users/fliter/video-tmp/kubernetes/pkg/controller/cronjob/utils_test.go:193:3: Duplicate words (way) found /Users/fliter/video-tmp/kubernetes/pkg/controller/cronjob/utils_test.go:203:3: Duplicate words (way) found /Users/fliter/video-tmp/kubernetes/pkg/controller/deployment/recreate_test.go:227:6: Duplicate words (pod) found /Users/fliter/video-tmp/kubernetes/pkg/controller/podautoscaler/horizontal_test.go:3593:34: Duplicate words (with) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/cm/cpumanager/cpu_assignment_test.go:84:4: Duplicate words (per) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/cm/cpumanager/cpu_assignment_test.go:90:4: Duplicate words (per) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/cm/cpumanager/cpu_assignment_test.go:96:4: Duplicate words (per) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/cm/cpumanager/cpu_assignment_test.go:102:4: Duplicate words (per) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/cm/cpumanager/cpu_assignment_test.go:108:4: Duplicate words (per) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/cm/cpumanager/cpu_assignment_test.go:196:4: Duplicate words (per) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/cm/cpumanager/cpu_assignment_test.go:202:4: Duplicate words (per) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/cm/cpumanager/cpu_assignment_test.go:208:4: Duplicate words (per) found /Users/fliter/video-tmp/kubernetes/pkg/kubelet/kuberuntime/logs/logs_test.go:356:18: Duplicate words (abcdefg) found /Users/fliter/video-tmp/kubernetes/pkg/proxy/service_test.go:705:13: Duplicate words (service) found /Users/fliter/video-tmp/kubernetes/pkg/proxy/iptables/proxier_test.go:3612:13: Duplicate words (service) found /Users/fliter/video-tmp/kubernetes/pkg/proxy/ipvs/proxier_test.go:2639:13: Duplicate words (service) found /Users/fliter/video-tmp/kubernetes/pkg/scheduler/schedule_one_test.go:685:12: Duplicate words (timeout) found /Users/fliter/video-tmp/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity/filtering_test.go:1286:4: Duplicate words (pod) found /Users/fliter/video-tmp/kubernetes/plugin/pkg/admission/resourcequota/admission_test.go:665:1: Duplicate words (that) found /Users/fliter/video-tmp/kubernetes/test/e2e_node/topology_manager_test.go:838:25: Duplicate words (with) found /Users/fliter/video-tmp/kubernetes/test/integration/job/job_test.go:166:11: Duplicate words (the) found
不能无脑改,需要甄别。。
go的benchmark检测出的:
1 2 3 4 5
/Users/fliter/fixgo/20000/benchmarks/garbage/nethttp.go:40:67: Duplicate words (req) found /Users/fliter/fixgo/20000/benchmarks/garbage/nethttp.go:1878:13: Duplicate words (Header,nil,) found /Users/fliter/fixgo/20000/benchmarks/garbage/nethttp.go:4701:43: Duplicate words (Handler,Header,t.idleConn) found /Users/fliter/fixgo/20000/benchmarks/third_party/biogo-examples/igor/igor/cluster.go:63:2: Duplicate words (all) found /Users/fliter/fixgo/20000/benchmarks/third_party/biogo-examples/igor/igor/cluster.go:72:2: Duplicate words (are) found
packages/network/tcpserver/disseminator.go:144:2: github.com/sirupsen/logrus.Debug call has possible Printf formatting directive %x
这个禁用gocritic检测的标记好像没起作用啊,还是:
1 2
./secp256k1fx/output_owners_test.go:146:17: dupArg: suspicious method call with the same argument and receiver ./secp256k1fx/output_owners_test.go:147:17: dupArg: suspicious method call with the same argument and receiver
go/src/cmd/internal/src/pos.go:413:46: don’t use Yoda conditions (ST1017)
“don’t use Yoda conditions (ST1017)” 是一个来自 Go 语言静态分析工具 staticcheck 的警告。这个警告的意思是建议避免使用一种特定的条件表达式写法,称为“Yoda 条件”。
什么是 Yoda 条件?
Yoda 条件是指在条件语句中,将常量放在表达式的左侧,而变量放在右侧。例如:
1 2 3
if5 == x { // do something }
这种写法源于 Yoda(《星球大战》中的角色)的说话方式,常常把动词放在句子的前面。它的主要目的是防止在比较时意外地使用赋值运算符(=)代替比较运算符(==),因为在 C 语言等语言中,错误地写成 if (x = 5) 会导致编译错误,而 if (5 == x) 则不会。
Go 语言的推荐做法
在 Go 语言中,这种写法并不常见,且并不必要,因为 Go 的编译器会检测到赋值错误。因此,推荐的做法是将变量放在条件的左侧,如下所示:
1 2 3
if x == 5 { // do something }
总结
为了提高代码的可读性和一致性,建议遵循 Go 语言的最佳实践,避免使用 Yoda 条件。使用标准的比较形式(变量在左,常量在右)会使代码更易于理解。
tools/go/analysis/passes/findcall/findcall.go:57:17: unnecessary use of fmt.Sprintf (S1039)
搜索 unnecessary use of 搜索 doesn’t have side effects