Skip to content

Commit

Permalink
fix lint for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Jun 1, 2023
1 parent c104e96 commit cacd140
Show file tree
Hide file tree
Showing 76 changed files with 235 additions and 1,441 deletions.
10 changes: 8 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ run:

linters:
enable:
- gofmt
- gofumpt
- revive
- gocyclo
- bodyclose
Expand All @@ -19,7 +19,13 @@ issues:
- path: lib/launcher/os_unix.go
source: "// \\+build !windows"
linters:
- gofmt
- gofumpt

# To support old golang version
- path: lib/launcher/os_windows.go
source: "// \\+build windows"
linters:
- gofumpt

- source: 'io/ioutil'
linters:
Expand Down
6 changes: 4 additions & 2 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (
)

// Browser implements these interfaces
var _ proto.Client = &Browser{}
var _ proto.Contextable = &Browser{}
var (
_ proto.Client = &Browser{}
_ proto.Contextable = &Browser{}
)

// Browser represents the browser.
// It doesn't depends on file system, it should work with remote browser seamlessly.
Expand Down
12 changes: 7 additions & 5 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"github.com/go-rod/rod/lib/utils"
)

type timeoutContextKey struct{}
type timeoutContextVal struct {
parent context.Context
cancel context.CancelFunc
}
type (
timeoutContextKey struct{}
timeoutContextVal struct {
parent context.Context
cancel context.CancelFunc
}
)

// Context returns a clone with the specified ctx for chained sub-operations
func (b *Browser) Context(ctx context.Context) *Browser {
Expand Down
7 changes: 5 additions & 2 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"dropzone",
"duckduckgo",
"enctype",
"errcheck",
"evenodd",
"excludesfile",
"fetchup",
Expand All @@ -47,6 +48,7 @@
"gocyclo",
"GODEBUG",
"gofmt",
"gofumpt",
"goimports",
"golangci",
"goob",
Expand Down Expand Up @@ -76,6 +78,7 @@
"MDPI",
"MITM",
"mitmproxy",
"mvdan",
"Noto",
"Numpad",
"onbeforeunload",
Expand All @@ -87,6 +90,7 @@
"progresser",
"proto",
"proxyauth",
"Rects",
"repost",
"sattributes",
"schildren",
Expand Down Expand Up @@ -114,8 +118,7 @@
"wsutil",
"xlink",
"XVFB",
"ysmood",
"Rects"
"ysmood"
],
// flagWords - list of words to be always considered incorrect
// This is useful for offensive words and common spelling errors.
Expand Down
8 changes: 5 additions & 3 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import (
)

// Element implements these interfaces
var _ proto.Client = &Element{}
var _ proto.Contextable = &Element{}
var _ proto.Sessionable = &Element{}
var (
_ proto.Client = &Element{}
_ proto.Contextable = &Element{}
_ proto.Sessionable = &Element{}
)

// Element represents the DOM element
type Element struct {
Expand Down
9 changes: 3 additions & 6 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ func (e *ErrExpectElements) Error() string {
func (e *ErrExpectElements) Is(err error) bool { _, ok := err.(*ErrExpectElements); return ok }

// ErrElementNotFound error
type ErrElementNotFound struct {
}
type ErrElementNotFound struct{}

func (e *ErrElementNotFound) Error() string {
return "cannot find element"
Expand Down Expand Up @@ -106,8 +105,7 @@ func (e *ErrNavigation) Error() string {
func (e *ErrNavigation) Is(err error) bool { _, ok := err.(*ErrNavigation); return ok }

// ErrPageCloseCanceled error
type ErrPageCloseCanceled struct {
}
type ErrPageCloseCanceled struct{}

func (e *ErrPageCloseCanceled) Error() string {
return "page close canceled"
Expand Down Expand Up @@ -175,8 +173,7 @@ func (e *ErrNoPointerEvents) Unwrap() error {
func (e *ErrNoPointerEvents) Is(err error) bool { _, ok := err.(*ErrNoPointerEvents); return ok }

// ErrPageNotFound error
type ErrPageNotFound struct {
}
type ErrPageNotFound struct{}

func (e *ErrPageNotFound) Error() string {
return "cannot find page"
Expand Down
2 changes: 1 addition & 1 deletion lib/devices/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func main() {
path := "./lib/devices/list.go"
utils.E(utils.OutputFile(path, code))

utils.Exec("gofmt -s -w", path)
utils.Exec("gofumpt -w", path)
utils.Exec(
"go run github.com/ysmood/golangci-lint@latest -- "+
"run --no-config --fix",
Expand Down
1 change: 0 additions & 1 deletion lib/docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func login() {
var headSha = strings.TrimSpace(utils.ExecLine(false, "git", "rev-parse", "HEAD"))

func description(dev bool) string {

f := "Dockerfile"
if dev {
f = "dev." + f
Expand Down
2 changes: 1 addition & 1 deletion lib/examples/compare-chromedp/download_image/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
log.Fatal(err)
}

if err := ioutil.WriteFile("download.png", b, 0644); err != nil {
if err := ioutil.WriteFile("download.png", b, 0o644); err != nil {
log.Fatal(err)
}
log.Print("wrote download.png")
Expand Down
2 changes: 1 addition & 1 deletion lib/examples/compare-chromedp/screenshot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
panic(err)
}

err = ioutil.WriteFile("fullScreenshot.png", buf, 0644)
err = ioutil.WriteFile("fullScreenshot.png", buf, 0o644)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/js/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {

utils.E(utils.OutputFile("lib/js/helper.go", out))

utils.Exec("gofmt -s -w lib/js/helper.go")
utils.Exec("gofumpt -w lib/js/helper.go")
}

var regDeps = regexp.MustCompile(`\Wfunctions.(\w+)`)
Expand Down
4 changes: 2 additions & 2 deletions lib/launcher/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ func terminateProcess(pid int) {
return
}

syscall.TerminateProcess(handle, 0)
syscall.CloseHandle(handle)
_ = syscall.TerminateProcess(handle, 0)
_ = syscall.CloseHandle(handle)
}
1 change: 0 additions & 1 deletion lib/launcher/revision/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const RevisionPlaywright = {{.playwright}}
)

utils.E(utils.OutputFile(filepath.FromSlash("lib/launcher/revision.go"), out))

}

func getList(path string) []string {
Expand Down
8 changes: 5 additions & 3 deletions lib/launcher/rod-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
"github.com/go-rod/rod/lib/utils"
)

var addr = flag.String("address", ":7317", "the address to listen to")
var quiet = flag.Bool("quiet", false, "silence the log")
var allowAllPath = flag.Bool("allow-all", false, "allow all path set by the client")
var (
addr = flag.String("address", ":7317", "the address to listen to")
quiet = flag.Bool("quiet", false, "silence the log")
allowAllPath = flag.Bool("allow-all", false, "allow all path set by the client")
)

func main() {
flag.Parse()
Expand Down
6 changes: 4 additions & 2 deletions lib/launcher/url_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ func MustResolveURL(u string) string {
return u
}

var regPort = regexp.MustCompile(`^\:?(\d+)$`)
var regProtocol = regexp.MustCompile(`^\w+://`)
var (
regPort = regexp.MustCompile(`^\:?(\d+)$`)
regProtocol = regexp.MustCompile(`^\w+://`)
)

// ResolveURL by requesting the u, it will try best to normalize the u.
// The format of u can be "9222", ":9222", "host:9222", "ws://host:9222", "wss://host:9222",
Expand Down
9 changes: 5 additions & 4 deletions lib/proto/a_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ type Client struct {
ret interface{}
}

var _ proto.Client = &Client{}
var _ proto.Sessionable = &Client{}
var _ proto.Contextable = &Client{}
var (
_ proto.Client = &Client{}
_ proto.Sessionable = &Client{}
_ proto.Contextable = &Client{}
)

func (c *Client) Call(_ context.Context, sessionID, methodName string, params interface{}) (res []byte, err error) {
c.sessionID = sessionID
Expand Down Expand Up @@ -91,7 +93,6 @@ func (t T) Rect() {
pt := res.OnePointInside()
t.Eq(348.5, pt.X)
t.Eq(399.25, pt.Y)

}

func (t T) Area() {
Expand Down
6 changes: 4 additions & 2 deletions lib/proto/a_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"strings"
)

var regAsterisk = regexp.MustCompile(`([^\\])\*`)
var regBackSlash = regexp.MustCompile(`([^\\])\?`)
var (
regAsterisk = regexp.MustCompile(`([^\\])\*`)
regBackSlash = regexp.MustCompile(`([^\\])\?`)
)

// PatternToReg FetchRequestPattern.URLPattern to regular expression
func PatternToReg(pattern string) string {
Expand Down
Loading

0 comments on commit cacd140

Please sign in to comment.