go get [-u] rsc.io/grind
rsc / grind Goto Github PK
View Code? Open in Web Editor NEWGrind polishes Go programs.
License: BSD 3-Clause "New" or "Revised" License
Grind polishes Go programs.
License: BSD 3-Clause "New" or "Revised" License
go get [-u] rsc.io/grind
This code is not be beautiful to start with (there are indeed many things wrong with it), but the change proposed by grind
doesn't make it better I think. Perhaps a threshold of some kind where the moving of a vardecl is skipped if it results in more than x new vardecls? Or recognizing the zero value so the early returns could be modified to return nil, ...
instead?
@@ -829,26 +830,29 @@ func (m *Model) ConnectedTo(deviceID protocol.DeviceID) bool {
}
func (m *Model) GetIgnores(folder string) ([]string, []string, error) {
- var lines []string
m.fmut.RLock()
cfg, ok := m.folderCfgs[folder]
m.fmut.RUnlock()
if !ok {
+ var lines []string
return lines, nil, fmt.Errorf("Folder %s does not exist", folder)
}
fd, err := os.Open(filepath.Join(cfg.Path, ".stignore"))
if err != nil {
if os.IsNotExist(err) {
+ var lines []string
return lines, nil, nil
}
l.Warnln("Loading .stignore:", err)
+ var lines []string
return lines, nil, err
}
defer fd.Close()
scanner := bufio.NewScanner(fd)
+ var lines []string
for scanner.Scan() {
lines = append(lines, strings.TrimSpace(scanner.Text()))
}
... duplicate, sorry.
I'm getting ../../../rsc.io/grind/vardecl/vardecl.go:84: assignment count mismatch: 2 = 3
when I go get the package. I looked into NodeEval() and it seemed correct. So I'm at a loss for more suggestions, sorry.
I'm using go version 1.4 (darwin/amd64) in case it matters.
Looks like go/types
has changed.
$ go get rsc.io/grind
# rsc.io/grind/vardecl
src/rsc.io/grind/vardecl/vardecl.go:88: undefined: types.EvalNode
trace:
package golang.org/x/tools/go/gcimporter: cannot find package "golang.org/x/tools/go/gcimporter" in any of:
/usr/local/Cellar/go/1.6.2/libexec/src/golang.org/x/tools/go/gcimporter (from $GOROOT)
/Users/daddye/.src/go/src/golang.org/x/tools/go/gcimporter (from $GOPATH)
package golang.org/x/tools/go/types: no buildable Go source files in /Users/daddye/.src/go/src/golang.org/x/tools/go/types
$ grind github.com/btcsuite/btcd
gets stuck in a loop swapping var declarations:
EDIT: cpuminer.go
@@ -73,8 +73,8 @@ func (m *CPUMiner) speedMonitor() {
defer ticker.Stop()
out:
- var hashesPerSec float64
var totalHashes uint64
+ var hashesPerSec float64
for {
select {
// Periodic updates from the workers with how many hashes they
36
EDIT: cpuminer.go
@@ -73,8 +73,8 @@ func (m *CPUMiner) speedMonitor() {
defer ticker.Stop()
out:
- var totalHashes uint64
var hashesPerSec float64
+ var totalHashes uint64
for {
select {
// Periodic updates from the workers with how many hashes they
Given the code....
func test(s string) []string {
var p []string
switch s {
case "test":
p = append(p, "test")
}
return p
}
... grind produces...
func test(s string) []string {
switch s {
case "test":
var p []string
p = append(p, "test")
}
var p []string
return p
}
/go/src/rsc.io/grind/vardecl/vardecl.go:88: undefined: types.EvalNode
I see this project looks very young, but stumbled upon it from twitter. Since github has lacklustre subscribing features, I'll do it here: is there a way of learning more about this project save for reading the code that I don't know about? The godoc isn't a whole lot of help at the moment I'm afraid.
A minimal test case:
package main
import "time"
func f(ch chan int) {
}
func main() {
var m int
ch := make(chan int)
for i := 0; i < 10; i++ {
go f(ch)
}
t := time.After(1 * time.Second)
loop:
for i := 0; i < 10; i++ {
select {
case j, ok := <-ch:
if ok {
m += j
}
case <-t:
break loop
}
}
}
becomes
package main
import "time"
func f(ch chan int) {
}
func main() {
ch := make(chan int)
for i := 0; i < 10; i++ {
go f(ch)
}
t := time.After(1 * time.Second)
loop:
var m int
for i := 0; i < 10; i++ {
select {
case j, ok := <-ch:
if ok {
m += j
}
case <-t:
break loop
}
}
}
which fails to build because loop
is no longer a valid break label because the declaration of m
was moved after it, making it a regular label.
The package now is part of go/types
Here is a trimmed down test case:
package main
import "fmt"
func main() {
ch := make(chan int)
var ok bool
var m int
select {
case m, ok = <-ch:
if ok {
fmt.Println(m)
}
}
}
after grinding becomes
package main
import "fmt"
func main() {
ch := make(chan int)
select {
case m, ok = <-ch:
var ok bool
if ok {
var m int
fmt.Println(m)
}
}
}
which fails to build because the declarations of m
and ok
now appear after their first use in the select case.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.