Skip to content

Commit

Permalink
WIP: Cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
bombsimon committed May 4, 2024
1 parent bd1297e commit 35f4640
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cursor.go
Expand Up @@ -41,6 +41,20 @@ func (c *Cursor) Previous() bool {
return true
}

func (c *Cursor) PeekNext() bool {
c.Save()
defer c.Reset()

return c.Next()
}

func (c *Cursor) PeekPrevious() bool {
c.Save()
defer c.Reset()

return c.Previous()
}

func (c *Cursor) Stmt() ast.Stmt {
return c.statements[c.currentIdx]
}
Expand Down
9 changes: 9 additions & 0 deletions testdata/src/wip/wip.go
@@ -1 +1,10 @@
package testpkg

func fn1() {
if foo := 1; foo != 2 {
panic(foo)
}
if foo := 2; foo != 2 { // want "missing whitespace decreases readability"
panic(bar)
}
}
10 changes: 10 additions & 0 deletions testdata/src/wip/wip.go.golden
@@ -1 +1,11 @@
package testpkg

func fn1() {
if foo := 1; foo != 2 {
panic(foo)
}

if foo := 2; foo != 2 { // want "missing whitespace decreases readability"
panic(bar)
}
}
5 changes: 5 additions & 0 deletions wsl.go
Expand Up @@ -75,12 +75,17 @@ func (w *WSL) CheckIf(stmt *ast.IfStmt, cursor *Cursor) {
previousIdents := []*ast.Ident{}
if cursor.Previous() {
previousIdents = allIdents(cursor.Stmt())
cursor.Next()
}

n := w.numberOfStatementsAbove(cursor)
if n > 0 {
intersects := identIntersection(currentIdents, previousIdents)

fmt.Println(currentIdents)
fmt.Println(previousIdents)
fmt.Println(intersects)

// No idents above share name with one in the if statement.
if len(intersects) == 0 {
w.addError(
Expand Down

0 comments on commit 35f4640

Please sign in to comment.