1
0
mirror of https://github.com/mgechev/revive.git synced 2025-01-26 03:52:12 +02:00

Merge pull request #85 from gsamokovarov/empty-lines-comments-check

Fix the same-line comments detection in the empty-lines rule
This commit is contained in:
SalvadorC 2018-10-13 20:15:31 +02:00 committed by GitHub
commit 6633ce6f24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 4 deletions

View File

@ -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)
}
}
}

View File

@ -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) {
@ -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