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

Golangci-lint Workflow and hooks ( Excluding handling errors) #6385

Merged
merged 1 commit into from
Jul 1, 2020
Merged
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
23 changes: 23 additions & 0 deletions .github/workflows/golangci-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: golangci-lint
on: [push,pull_request]
jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Install golangci-lint
run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.27.0

- name: Run golangci-lint
run: $(go env GOPATH)/bin/golangci-lint run --disable=errcheck --timeout=10m go/...
4 changes: 2 additions & 2 deletions go/cmd/automation_client/automation_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func main() {
Parameters: params.parameters,
}
fmt.Printf("Sending request:\n%v", proto.MarshalTextString(enqueueRequest))
enqueueResponse, err := client.EnqueueClusterOperation(context.Background(), enqueueRequest, grpc.FailFast(false))
enqueueResponse, err := client.EnqueueClusterOperation(context.Background(), enqueueRequest, grpc.FailFast(false)) //nolint
if err != nil {
fmt.Println("Failed to enqueue ClusterOperation. Error:", err)
os.Exit(4)
Expand All @@ -113,7 +113,7 @@ func waitForClusterOp(client automationservicepb.AutomationClient, id string) (*
Id: id,
}

resp, err := client.GetClusterOperationDetails(context.Background(), req, grpc.FailFast(false))
resp, err := client.GetClusterOperationDetails(context.Background(), req, grpc.FailFast(false)) //nolint
if err != nil {
return nil, fmt.Errorf("failed to get ClusterOperation Details. Request: %v Error: %v", req, err)
}
Expand Down
3 changes: 2 additions & 1 deletion go/cmd/mysqlctl/mysqlctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ var (
tabletUID = flag.Uint("tablet_uid", 41983, "tablet uid")
mysqlSocket = flag.String("mysql_socket", "", "path to the mysql socket")

tabletAddr string
// Reason for nolint : Being used in line 246 (tabletAddr = netutil.JoinHostPort("localhost", int32(*port))
tabletAddr string //nolint
Akilan1999 marked this conversation as resolved.
Show resolved Hide resolved
)

func initConfigCmd(subFlags *flag.FlagSet, args []string) error {
Expand Down
3 changes: 2 additions & 1 deletion go/cmd/zkctl/zkctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ var (
myID = flag.Uint("zk.myid", 0,
"which server do you want to be? only needed when running multiple instance on one box, otherwise myid is implied by hostname")

stdin *bufio.Reader
// Reason for nolint : Used in line 54 (stdin = bufio.NewReader(os.Stdin)) in the init function
stdin *bufio.Reader //nolint
Akilan1999 marked this conversation as resolved.
Show resolved Hide resolved
)

func init() {
Expand Down
10 changes: 9 additions & 1 deletion go/mysql/binlog_event_make_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,15 @@ func TestRowsEvent(t *testing.T) {
f := NewMySQL56BinlogFormat()
s := NewFakeBinlogStream()

tableID := uint64(0x102030405060)
/*
Reason for nolint
Used in line 384 to 387
tableID = event.TableID(f)
if tableID != 0x102030405060 {
t.Fatalf("NewRowsEvent().TableID returned %x", tableID)
}
*/
tableID := uint64(0x102030405060) //nolint
Akilan1999 marked this conversation as resolved.
Show resolved Hide resolved

tm := &TableMap{
Flags: 0x8090,
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ func checkQueryInternal(t *testing.T, query string, sConn, cConn *Conn, result *
}
}

//lint:ignore U1000 for now, because deleting this function causes more errors
//nolint
func writeResult(conn *Conn, result *sqltypes.Result) error {
if len(result.Fields) == 0 {
return conn.writeOKPacket(result.RowsAffected, result.InsertID, conn.StatusFlags, 0)
Expand Down
16 changes: 8 additions & 8 deletions go/mysql/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ func (c *Conn) WriteComBinlogDumpGTID(serverID uint32, binlogFilename string, bi
4 + // data-size
len(gtidSet) // data
data, pos := c.startEphemeralPacketWithHeader(length)
pos = writeByte(data, pos, ComBinlogDumpGTID)
pos = writeUint16(data, pos, flags)
pos = writeUint32(data, pos, serverID)
pos = writeUint32(data, pos, uint32(len(binlogFilename)))
pos = writeEOFString(data, pos, binlogFilename)
pos = writeUint64(data, pos, binlogPos)
pos = writeUint32(data, pos, uint32(len(gtidSet)))
pos += copy(data[pos:], gtidSet)
pos = writeByte(data, pos, ComBinlogDumpGTID) //nolint
pos = writeUint16(data, pos, flags) //nolint
pos = writeUint32(data, pos, serverID) //nolint
pos = writeUint32(data, pos, uint32(len(binlogFilename))) //nolint
pos = writeEOFString(data, pos, binlogFilename) //nolint
pos = writeUint64(data, pos, binlogPos) //nolint
pos = writeUint32(data, pos, uint32(len(gtidSet))) //nolint
pos += copy(data[pos:], gtidSet) //nolint
if err := c.writeEphemeralPacket(); err != nil {
return NewSQLError(CRServerGone, SSUnknownSQLState, "%v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions go/mysql/replication_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:unparam
package mysql

// This file contains the constant definitions for this package.
Expand Down Expand Up @@ -208,7 +208,7 @@ const (
//eXAPrepareLogEvent = 38

// MariaDB specific values. They start at 160.
eMariaAnnotateRowsEvent = 160
eMariaAnnotateRowsEvent = 160 //nolint
// Unused
//eMariaBinlogCheckpointEvent = 161
eMariaGTIDEvent = 162
Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func LaunchCluster(setupType int, streamMode string, stripes int) (int, error) {

// if streamMode is xbstream, add some additional args to test other xtrabackup flags
if streamMode == "xbstream" {
xtrabackupArgs = append(xtrabackupArgs, "-xtrabackup_prepare_flags", fmt.Sprintf("--use-memory=100M"))
xtrabackupArgs = append(xtrabackupArgs, "-xtrabackup_prepare_flags", fmt.Sprintf("--use-memory=100M")) //nolint
}

commonTabletArg = append(commonTabletArg, xtrabackupArgs...)
Expand Down Expand Up @@ -661,7 +661,7 @@ func terminateRestore(t *testing.T) {
assert.Fail(t, "restore in progress file missing")
}
tmpProcess.Process.Signal(syscall.SIGTERM)
found = true
found = true //nolint
return
}
}
Expand Down
15 changes: 8 additions & 7 deletions go/test/endtoend/vtctldweb/vtctld_web_main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ import (
"vitess.io/vitess/go/vt/vttest"
)

//nolint
var (
localCluster *vttest.LocalCluster
hostname = "localhost"
hostname = "localhost" //nolint
wd selenium.WebDriver
seleniumService *selenium.Service
vtctldAddr string
Expand Down Expand Up @@ -175,7 +176,7 @@ func CreateWebDriver(port int) error {
return err
}

name, err := wd.CurrentWindowHandle()
name, err := wd.CurrentWindowHandle() //nolint
return wd.ResizeWindow(name, 1280, 1024)
}

Expand All @@ -201,7 +202,7 @@ func CreateWebDriver(port int) error {
if err != nil {
return err
}
name, err := wd.CurrentWindowHandle()
name, err := wd.CurrentWindowHandle() //nolint
return wd.ResizeWindow(name, 1280, 1024)
}

Expand Down Expand Up @@ -346,7 +347,7 @@ func getDashboardKeyspaces(t *testing.T) []string {
dashboardContent, err := wd.FindElement(selenium.ByTagName, "vt-dashboard")
require.Nil(t, err)

ksCards, err := dashboardContent.FindElements(selenium.ByClassName, "vt-keyspace-card")
ksCards, err := dashboardContent.FindElements(selenium.ByClassName, "vt-keyspace-card") //nolint
var out []string
for _, ks := range ksCards {
out = append(out, text(t, ks))
Expand All @@ -358,10 +359,10 @@ func getDashboardKeyspaces(t *testing.T) []string {
func getDashboardShards(t *testing.T) []string {
wait(t, selenium.ByTagName, "vt-dashboard")

dashboardContent, err := wd.FindElement(selenium.ByTagName, "vt-dashboard")
dashboardContent, err := wd.FindElement(selenium.ByTagName, "vt-dashboard") //nolint
require.Nil(t, err)

ksCards, err := dashboardContent.FindElements(selenium.ByClassName, "vt-shard-stats")
ksCards, err := dashboardContent.FindElements(selenium.ByClassName, "vt-shard-stats") //nolint
var out []string
for _, ks := range ksCards {
out = append(out, text(t, ks))
Expand Down Expand Up @@ -390,7 +391,7 @@ func getShardTablets(t *testing.T) ([]string, []string) {
shardContent, err := wd.FindElement(selenium.ByTagName, "vt-shard-view")
require.Nil(t, err)

tableRows, err := shardContent.FindElements(selenium.ByTagName, "tr")
tableRows, err := shardContent.FindElements(selenium.ByTagName, "tr") //nolint
tableRows = tableRows[1:]

var tabletTypes, tabletUIDs []string
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestSchemaChange(t *testing.T) {

func testWithInitialSchema(t *testing.T) {
// Create 4 tables
var sqlQuery = ""
var sqlQuery = "" //nolint
for i := 0; i < totalTableCount; i++ {
sqlQuery = fmt.Sprintf(createTable, fmt.Sprintf("vt_select_test_%02d", i))
err := clusterInstance.VtctlclientProcess.ApplySchema(keyspaceName, sqlQuery)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/grpcclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func Dial(target string, failFast FailFast, opts ...grpc.DialOption) (*grpc.Clie
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(*grpccommon.MaxMessageSize),
grpc.MaxCallSendMsgSize(*grpccommon.MaxMessageSize),
grpc.FailFast(bool(failFast)),
grpc.FailFast(bool(failFast)), //nolint
),
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/mysqlctl/builtinbackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (be *BuiltinBackupEngine) ExecuteBackup(ctx context.Context, params BackupP
// Save initial state so we can restore.
slaveStartRequired := false
sourceIsMaster := false
readOnly := true
readOnly := true //nolint
var replicationPosition mysql.Position
semiSyncMaster, semiSyncSlave := params.Mysqld.SemiSyncEnabled()

Expand Down
2 changes: 1 addition & 1 deletion go/vt/mysqlctl/grpcmysqlctlclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type client struct {

func factory(network, addr string) (mysqlctlclient.MysqlctlClient, error) {
// create the RPC client
cc, err := grpcclient.Dial(addr, grpcclient.FailFast(false), grpc.WithInsecure(), grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
cc, err := grpcclient.Dial(addr, grpcclient.FailFast(false), grpc.WithInsecure(), grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { //nolint:staticcheck
return net.DialTimeout(network, addr, timeout)
}))
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion go/vt/mysqlctl/mycnf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"
"strings"
"testing"

"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/servenv"
)
Expand Down Expand Up @@ -79,6 +78,8 @@ func TestMycnf(t *testing.T) {
// 3. go test
// 4. \rm $VTROOT/vthook/make_mycnf
// 5. Add No Prefix back

//nolint
func NoTestMycnfHook(t *testing.T) {
uid := uint32(11111)
cnf := NewMycnf(uid, 6802)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/mysqlctl/mysqld.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (mysqld *Mysqld) startNoWait(ctx context.Context, cnf *Mycnf, mysqldArgs ..
switch hr := hook.NewHook("mysqld_start", mysqldArgs).Execute(); hr.ExitStatus {
case hook.HOOK_SUCCESS:
// hook exists and worked, we can keep going
name = "mysqld_start hook"
name = "mysqld_start hook" //nolint
case hook.HOOK_DOES_NOT_EXIST:
// hook doesn't exist, run mysqld_safe ourselves
log.Infof("%v: No mysqld_start hook, running mysqld_safe directly", ts)
Expand Down
6 changes: 3 additions & 3 deletions go/vt/mysqlctl/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ func (mysqld *Mysqld) ResetReplication(ctx context.Context) error {
//
// Array indices for the results of SHOW PROCESSLIST.
const (
colConnectionID = iota
colUsername
colConnectionID = iota //nolint
colUsername //nolint
colClientAddr
colDbName
colDbName //nolint
colCommand
)

Expand Down
2 changes: 1 addition & 1 deletion go/vt/mysqlctl/tmutils/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func TestSchemaDiff(t *testing.T) {
})

testDiff(t, sd4, sd5, "sd4", "sd5", []string{
fmt.Sprintf("schemas differ on table type for table table2:\nsd4: VIEW\n differs from:\nsd5: BASE TABLE"),
fmt.Sprintf("schemas differ on table type for table table2:\nsd4: VIEW\n differs from:\nsd5: BASE TABLE"), //nolint
})

sd1.DatabaseSchema = "CREATE DATABASE {{.DatabaseName}}"
Expand Down
2 changes: 1 addition & 1 deletion go/vt/sqlparser/precedence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestRandom(t *testing.T) {
// The purpose of this test is to find discrepancies between Format and parsing. If for example our precedence rules are not consistent between the two, this test should find it.
// The idea is to generate random queries, and pass them through the parser and then the unparser, and one more time. The result of the first unparse should be the same as the second result.
seed := time.Now().UnixNano()
fmt.Println(fmt.Sprintf("seed is %d", seed))
fmt.Println(fmt.Sprintf("seed is %d", seed)) //nolint
g := newGenerator(seed, 5)
endBy := time.Now().Add(1 * time.Second)

Expand Down
2 changes: 1 addition & 1 deletion go/vt/throttler/max_replication_lag_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ func (m *MaxReplicationLagModule) decreaseAndGuessRate(r *result, now time.Time,

if replicationLagChange == equal {
// The replication lag did not change. Keep going at the current rate.
r.Reason = fmt.Sprintf("did not decrease the rate because the lag did not change (assuming a 1s error margin)")
r.Reason = fmt.Sprintf("did not decrease the rate because the lag did not change (assuming a 1s error margin)") //nolint
return
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/topo/consultopo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func getClientCreds() (creds map[string]*ClientAuthCred, err error) {
}

if err := json.Unmarshal(data, &creds); err != nil {
err = vterrors.Wrapf(err, fmt.Sprintf("Error parsing consul_auth_static_file"))
err = vterrors.Wrapf(err, fmt.Sprintf("Error parsing consul_auth_static_file")) //nolint
return creds, err
}
return creds, nil
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go/vt/topo/k8stopo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func NewServer(_, root string) (*Server, error) {

var config *rest.Config
var err error
namespace := "default"
namespace := "default" //nolint

if *kubeconfigPath == "" {
log.Info("Creating new in-cluster Kubernetes config")
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtctl/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func commandBackupShard(ctx context.Context, wr *wrangler.Wrangler, subFlags *fl
switch tablets[i].Type {
case topodatapb.TabletType_MASTER:
tabletForBackup = tablets[i].Tablet
secondsBehind = 0
secondsBehind = 0 //nolint
break ChooseMaster
default:
continue
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ func (e *Executor) handlePrepare(ctx context.Context, safeSession *SafeSession,
var errCount uint64
if err != nil {
logStats.Error = err
errCount = 1
errCount = 1 //nolint
return nil, err
}
logStats.RowsAffected = qr.RowsAffected
Expand Down
3 changes: 2 additions & 1 deletion go/vt/vtgate/executor_vschema_ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func waitForVschemaTables(t *testing.T, ks string, tables []string, executor *Ex
return nil
}

//nolint
func waitForColVindexes(t *testing.T, ks, table string, names []string, executor *Executor) *vschemapb.SrvVSchema {
t.Helper()

Expand Down Expand Up @@ -383,7 +384,7 @@ func TestExecutorAddDropVindexDDL(t *testing.T) {
defer func() {
*vschemaacl.AuthorizedDDLUsers = ""
}()
executor, sbc1, sbc2, sbclookup := createExecutorEnv()
executor, sbc1, sbc2, sbclookup := createExecutorEnv() //nolint
ks := "TestExecutor"
session := NewSafeSession(&vtgatepb.Session{TargetString: ks})
vschemaUpdates := make(chan *vschemapb.SrvVSchema, 4)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func testFile(t *testing.T, filename, tempDir string, vschema *vschemaWrapper) {
if fail && tempDir != "" {
gotFile := fmt.Sprintf("%s/%s", tempDir, filename)
ioutil.WriteFile(gotFile, []byte(strings.TrimSpace(expected.String())+"\n"), 0644)
fmt.Println(fmt.Sprintf("Errors found in plantests. If the output is correct, run `cp %s/* testdata/` to update test expectations", tempDir))
fmt.Println(fmt.Sprintf("Errors found in plantests. If the output is correct, run `cp %s/* testdata/` to update test expectations", tempDir)) //nolint
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/workflow/resharding/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func (hw *horizontalReshardingWorkflow) Run(ctx context.Context, manager *workfl
if err := hw.runWorkflow(); err != nil {
return err
}
hw.setUIMessage(fmt.Sprintf("Horizontal Resharding is finished successfully."))
hw.setUIMessage(fmt.Sprintf("Horizontal Resharding is finished successfully.")) //nolint
return nil
}

Expand Down
Loading