Skip to content

Commit

Permalink
Fixing remaining gofmt/misspell issues for goreportcard
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Shaw committed Mar 2, 2017
1 parent 22e2877 commit 8e8dabb
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 251 deletions.
4 changes: 2 additions & 2 deletions cdp/debugger/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (p *RemoveBreakpointParams) Do(ctxt context.Context, h cdp.Handler) (err er
// scriptId in start and end range locations should be the same.
type GetPossibleBreakpointsParams struct {
Start *Location `json:"start"` // Start of range to search possible breakpoint locations in.
End *Location `json:"end,omitempty"` // End of range to search possible breakpoint locations in (excluding). When not specifed, end of scripts is used as end of range.
End *Location `json:"end,omitempty"` // End of range to search possible breakpoint locations in (excluding). When not specified, end of scripts is used as end of range.
RestrictToFunction bool `json:"restrictToFunction,omitempty"` // Only consider locations which are in the same (non-nested) function as start.
}

Expand All @@ -259,7 +259,7 @@ func GetPossibleBreakpoints(start *Location) *GetPossibleBreakpointsParams {
}

// WithEnd end of range to search possible breakpoint locations in
// (excluding). When not specifed, end of scripts is used as end of range.
// (excluding). When not specified, end of scripts is used as end of range.
func (p GetPossibleBreakpointsParams) WithEnd(end *Location) *GetPossibleBreakpointsParams {
p.End = end
return &p
Expand Down
4 changes: 2 additions & 2 deletions cdp/dom/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ type EventPseudoElementRemoved struct {
PseudoElementID cdp.NodeID `json:"pseudoElementId,omitempty"` // The removed pseudo element id.
}

// EventDistributedNodesUpdated called when distrubution is changed.
// EventDistributedNodesUpdated called when distribution is changed.
type EventDistributedNodesUpdated struct {
InsertionPointID cdp.NodeID `json:"insertionPointId,omitempty"` // Insertion point where distrubuted nodes were updated.
InsertionPointID cdp.NodeID `json:"insertionPointId,omitempty"` // Insertion point where distributed nodes were updated.
DistributedNodes []*cdp.BackendNode `json:"distributedNodes,omitempty"` // Distributed nodes for given insertion point.
}

Expand Down
8 changes: 4 additions & 4 deletions cdp/emulation/emulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ func (p *SetDeviceMetricsOverrideParams) Do(ctxt context.Context, h cdp.Handler)
return h.Execute(ctxt, cdp.CommandEmulationSetDeviceMetricsOverride, p, nil)
}

// ClearDeviceMetricsOverrideParams clears the overriden device metrics.
// ClearDeviceMetricsOverrideParams clears the overridden device metrics.
type ClearDeviceMetricsOverrideParams struct{}

// ClearDeviceMetricsOverride clears the overriden device metrics.
// ClearDeviceMetricsOverride clears the overridden device metrics.
func ClearDeviceMetricsOverride() *ClearDeviceMetricsOverrideParams {
return &ClearDeviceMetricsOverrideParams{}
}
Expand Down Expand Up @@ -289,11 +289,11 @@ func (p *SetGeolocationOverrideParams) Do(ctxt context.Context, h cdp.Handler) (
return h.Execute(ctxt, cdp.CommandEmulationSetGeolocationOverride, p, nil)
}

// ClearGeolocationOverrideParams clears the overriden Geolocation Position
// ClearGeolocationOverrideParams clears the overridden Geolocation Position
// and Error.
type ClearGeolocationOverrideParams struct{}

// ClearGeolocationOverride clears the overriden Geolocation Position and
// ClearGeolocationOverride clears the overridden Geolocation Position and
// Error.
func ClearGeolocationOverride() *ClearGeolocationOverrideParams {
return &ClearGeolocationOverrideParams{}
Expand Down
2 changes: 1 addition & 1 deletion cdp/heapprofiler/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type EventReportHeapSnapshotProgress struct {
}

// EventLastSeenObjectID if heap objects tracking has been started then
// backend regulary sends a current value for last seen object id and
// backend regularly sends a current value for last seen object id and
// corresponding timestamp. If the were changes in the heap since last event
// then one or more heapStatsUpdate events will be sent before a new
// lastSeenObjectId event.
Expand Down
4 changes: 2 additions & 2 deletions cdp/io/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ func (p ReadParams) WithSize(size int64) *ReadParams {
// ReadReturns return values.
type ReadReturns struct {
Data string `json:"data,omitempty"` // Data that were read.
EOF bool `json:"eof,omitempty"` // Set if the end-of-file condition occured while reading.
EOF bool `json:"eof,omitempty"` // Set if the end-of-file condition occurred while reading.
}

// Do executes IO.read against the provided context and
// target handler.
//
// returns:
// data - Data that were read.
// eof - Set if the end-of-file condition occured while reading.
// eof - Set if the end-of-file condition occurred while reading.
func (p *ReadParams) Do(ctxt context.Context, h cdp.Handler) (data string, eof bool, err error) {
// execute
var res ReadReturns
Expand Down
2 changes: 2 additions & 0 deletions cmd/chromedp-gen/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
set -ve
go generate

gofmt -w -s templates/*.go

go build

time ./chromedp-gen $@
Expand Down
14 changes: 7 additions & 7 deletions cmd/chromedp-gen/fixup/fixup.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ func FixDomains(domains []*internal.Domain) {
Type: internal.TypeObject,
Description: "Message error type.",
Properties: []*internal.Type{
&internal.Type{
{
Name: "code",
Type: internal.TypeInteger,
Description: "Error code.",
},
&internal.Type{
{
Name: "message",
Type: internal.TypeString,
Description: "Error message.",
Expand All @@ -123,27 +123,27 @@ func FixDomains(domains []*internal.Domain) {
Type: internal.TypeObject,
Description: "Chrome Debugging Protocol message sent to/read over websocket connection.",
Properties: []*internal.Type{
&internal.Type{
{
Name: "id",
Type: internal.TypeInteger,
Description: "Unique message identifier.",
},
&internal.Type{
{
Name: "method",
Ref: "Inspector.MethodType",
Description: "Event or command type.",
},
&internal.Type{
{
Name: "params",
Type: internal.TypeAny,
Description: "Event or command parameters.",
},
&internal.Type{
{
Name: "result",
Type: internal.TypeAny,
Description: "Command return values.",
},
&internal.Type{
{
Name: "error",
Ref: "MessageError",
Description: "Error message.",
Expand Down
1 change: 1 addition & 0 deletions cmd/chromedp-gen/internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func (t Type) IDorName() string {
func (t Type) String() string {
desc := t.GetDescription()
if desc != "" {
desc, _ = MisspellReplacer.Replace(desc)
desc = " - " + desc
}

Expand Down
13 changes: 12 additions & 1 deletion cmd/chromedp-gen/internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"regexp"
"strings"

"github.com/client9/misspell"
"github.com/knq/snaker"
)

Expand All @@ -18,6 +19,14 @@ const (
Base64EncodedDescriptionPrefix = "Base64-encoded"
)

// MisspellReplacer is the misspelling replacer
var MisspellReplacer *misspell.Replacer

func init() {
MisspellReplacer = misspell.New()
MisspellReplacer.Compile()
}

// ForceCamel forces camel case specific to go.
func ForceCamel(s string) string {
if s == "" {
Expand Down Expand Up @@ -114,7 +123,9 @@ func structDef(types []*Type, d *Domain, domains []*Domain, noExposeOverride, om

// add comment
if v.Type != TypeObject && v.Description != "" {
s += " // " + CodeRE.ReplaceAllString(v.Description, "")
comment := CodeRE.ReplaceAllString(v.Description, "")
comment, _ = MisspellReplacer.Replace(comment)
s += " // " + comment
}
}
if len(types) > 0 {
Expand Down
33 changes: 33 additions & 0 deletions cmd/chromedp-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ func main() {
os.Exit(1)
}

// gofmt
err = gofmt(files)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}

log.Printf("done.")
}

Expand Down Expand Up @@ -249,6 +256,32 @@ func easyjson(pkgs []string) error {
return nil
}

// gofmt formats all the output file buffers on disk using gofmt.
func gofmt(fileBuffers map[string]*bytes.Buffer) error {
log.Printf("running gofmt")

var keys []string
for k := range fileBuffers {
keys = append(keys, k)
}
sort.Strings(keys)

var wg sync.WaitGroup
for _, n := range keys {
wg.Add(1)
go func(wg *sync.WaitGroup, n string) {
defer wg.Done()
buf, err := exec.Command("gofmt", "-w", "-s", out()+"/"+n).CombinedOutput()
if err != nil {
log.Fatalf("error: could not format %s, got:\n%s", n, string(buf))
}
}(&wg, n)
}
wg.Wait()

return nil
}

// out returns the output path of the passed package flag.
func out() string {
return os.Getenv("GOPATH") + "/src/" + *internal.FlagPkg
Expand Down
2 changes: 1 addition & 1 deletion cmd/chromedp-gen/templates/file.qtpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func FileHeader(pkgName string, d *internal.Domain) string {
func StreamFileImportTemplate(qw422016 *qt422016.Writer, m map[string]string) {
//line templates/file.qtpl:22
var keys []string
for k, _ := range m {
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
Expand Down
2 changes: 2 additions & 0 deletions cmd/chromedp-gen/templates/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func formatComment(s, chop, newstr string) string {
}
s += "."

s, _ = internal.MisspellReplacer.Replace(s)

return wrap(s, commentWidth-len(commentPrefix), commentPrefix)
}

Expand Down
2 changes: 2 additions & 0 deletions contrib/meta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pushd $SRC &> /dev/null

gometalinter \
--disable=aligncheck \
--enable=misspell \
--enable=gofmt \
--deadline=100s \
--cyclo-over=25 \
--sort=path \
Expand Down
12 changes: 9 additions & 3 deletions kb/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func main() {

// special characters
keys := map[rune]kb.Key{
'\b': kb.Key{"Backspace", "Backspace", "", "", int64('\b'), int64('\b'), false, false},
'\t': kb.Key{"Tab", "Tab", "", "", int64('\t'), int64('\t'), false, false},
'\r': kb.Key{"Enter", "Enter", "\r", "\r", int64('\r'), int64('\r'), false, true},
'\b': {"Backspace", "Backspace", "", "", int64('\b'), int64('\b'), false, false},
'\t': {"Tab", "Tab", "", "", int64('\t'), int64('\t'), false, false},
'\r': {"Enter", "Enter", "\r", "\r", int64('\r'), int64('\r'), false, true},
}

// load keys
Expand Down Expand Up @@ -100,6 +100,12 @@ func main() {
if err != nil {
log.Fatal(err)
}

// format
err = exec.Command("gofmt", "-s", "-w", *flagOut).Run()
if err != nil {
log.Fatal(err)
}
}

// loadKeys loads the dom key definitions from the chromium source tree.
Expand Down

0 comments on commit 8e8dabb

Please sign in to comment.