From b7d9bce0b6e0732feb7deb0859e6ad7c68e6f5e7 Mon Sep 17 00:00:00 2001 From: Genadi Samokovarov Date: Sat, 13 Oct 2018 09:47:29 -0700 Subject: [PATCH 1/2] Fix the same-line comments detection in the empty-lines rule Fixes #84. --- fixtures/empty-lines.go | 33 +++++++++++++++++++++++++++++++++ rule/empty-lines.go | 8 +++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/fixtures/empty-lines.go b/fixtures/empty-lines.go index 0308ac0..0e9d57c 100644 --- a/fixtures/empty-lines.go +++ b/fixtures/empty-lines.go @@ -2,6 +2,8 @@ package fixtures +import "time" + func f1(x *int) bool { // MATCH /extra empty line at the start of a block/ return x > 2 @@ -127,3 +129,34 @@ func f18(x *int) bool { return false } + +func w() { + select { + case <-time.After(dur): + // TODO: Handle Ctrl-C is pressed in `mysql` client. + // return 1 when SLEEP() is KILLed + } + return 0, false, nil +} + +func x() { + if tagArray[2] == "req" { + bit := len(u.reqFields) + u.reqFields = append(u.reqFields, name) + reqMask = uint64(1) << uint(bit) + // TODO: if we have more than 64 required fields, we end up + // not verifying that all required fields are present. + // Fix this, perhaps using a count of required fields? + } + + if err == nil { // No need to refresh if the stream is over or failed. + // Consider any buffered body data (read from the conn but not + // consumed by the client) when computing flow control for this + // stream. + v := int(cs.inflow.available()) + cs.bufPipe.Len() + if v < transportDefaultStreamFlow-transportDefaultStreamMinRefresh { + streamAdd = int32(transportDefaultStreamFlow - v) + cs.inflow.add(streamAdd) + } + } +} diff --git a/rule/empty-lines.go b/rule/empty-lines.go index 54759e8..e26c8dd 100644 --- a/rule/empty-lines.go +++ b/rule/empty-lines.go @@ -100,9 +100,11 @@ func (w lintEmptyLines) commentBetween(position token.Position, node ast.Node) b return false } - commentStart := w.position(comments[0].Pos()) - if commentStart.Line-position.Line == 1 || commentStart.Line-position.Line == -1 { - return true + for _, comment := range comments { + start, end := w.position(comment.Pos()), w.position(comment.End()) + if start.Line-position.Line == 1 || position.Line-end.Line == 1 { + return true + } } return false From 3cae2fa6f991dfd8742a8465d19a9b843254cebd Mon Sep 17 00:00:00 2001 From: SalvadorC Date: Sat, 13 Oct 2018 20:13:29 +0200 Subject: [PATCH 2/2] Update empty-lines.go removes warning on unused parameter --- rule/empty-lines.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rule/empty-lines.go b/rule/empty-lines.go index e26c8dd..37ec2a8 100644 --- a/rule/empty-lines.go +++ b/rule/empty-lines.go @@ -11,7 +11,7 @@ import ( type EmptyLinesRule struct{} // Apply applies the rule to given file. -func (r *EmptyLinesRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { +func (r *EmptyLinesRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure { var failures []lint.Failure onFailure := func(failure lint.Failure) {