Skip to content

Commit

Permalink
chore: use golangci-lint and gofumpt (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
canstand committed Jan 24, 2024
1 parent 67b851e commit 0d5814a
Show file tree
Hide file tree
Showing 39 changed files with 520 additions and 487 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go 1.x
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ^1.19.9
cache: false
id: go
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand All @@ -28,16 +29,16 @@ jobs:
runs-on: ${{ matrix.os }}
name: ${{ matrix.browser }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ^1.19.9
id: go
- name: Cache drivers
uses: actions/cache@v3
uses: actions/cache@v4
with:
# In order:
# * Driver for linux
Expand Down Expand Up @@ -78,9 +79,9 @@ jobs:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ^1.19.9
id: go
Expand All @@ -95,9 +96,9 @@ jobs:
test-examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go 1.x
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ^1.19.9
id: go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Deploy docs
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/verify_type_generation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ^1.19.9
- name: Install gofumpt
run: go install mvdan.cc/gofumpt@latest
- name: Install Browsers
run: |
go install ./...
Expand Down
6 changes: 6 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
linters:
enable-all: false
disable-all: false
enable:
- gofumpt
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Contributing

## Code style
The Go code is linted with [golangci-lint](https://golangci-lint.run/) and formatted with [gofumpt](https://github.com/mvdan/gofumpt). Please configure your editor to run the tools while developing and make sure to run the tools before committing any code.

## Tests

### Test coverage
Expand Down
4 changes: 2 additions & 2 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ func (b *browserImpl) StopTracing() ([]byte, error) {
return binary, err
}
if b.chromiumTracingPath != nil {
err := os.MkdirAll(filepath.Dir(*b.chromiumTracingPath), 0777)
err := os.MkdirAll(filepath.Dir(*b.chromiumTracingPath), 0o777)
if err != nil {
return binary, err
}
err = os.WriteFile(*b.chromiumTracingPath, binary, 0644)
err = os.WriteFile(*b.chromiumTracingPath, binary, 0o644)
if err != nil {
return binary, err
}
Expand Down
1 change: 1 addition & 0 deletions browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (b *browserContextImpl) Pages() []Page {
func (b *browserContextImpl) Browser() Browser {
return b.browser
}

func (b *browserContextImpl) Tracing() Tracing {
return b.tracing
}
Expand Down
1 change: 1 addition & 0 deletions browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (b *browserTypeImpl) LaunchPersistentContext(userDataDir string, options ..
b.didCreateContext(context, option, tracesDir)
return context, nil
}

func (b *browserTypeImpl) Connect(wsEndpoint string, options ...BrowserTypeConnectOptions) (Browser, error) {
overrides := map[string]interface{}{
"wsEndpoint": wsEndpoint,
Expand Down
2 changes: 1 addition & 1 deletion element_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (e *elementHandleImpl) Screenshot(options ...ElementHandleScreenshotOptions
return nil, fmt.Errorf("could not decode base64 :%w", err)
}
if path != nil {
if err := os.WriteFile(*path, image, 0644); err != nil {
if err := os.WriteFile(*path, image, 0o644); err != nil {
return nil, err
}
}
Expand Down
1 change: 0 additions & 1 deletion examples/javascript/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ func main() {
if err := pw.Stop(); err != nil {
log.Fatalf("could not stop Playwright: %v\n", err)
}

}
2 changes: 1 addition & 1 deletion examples/parallel-scraping/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func main() {
if err != nil {
assertErrorToNilf("could not get cwd %w", err)
}
if err := os.Mkdir(filepath.Join(cwd, "out"), 0777); err != nil && !os.IsExist(err) {
if err := os.Mkdir(filepath.Join(cwd, "out"), 0o777); err != nil && !os.IsExist(err) {
assertErrorToNilf("could not create output directory %w", err)
}

Expand Down
1 change: 0 additions & 1 deletion fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ func isJsonContentType(headers []map[string]string) bool {
}
}
}

}
return false
}
Expand Down
44 changes: 25 additions & 19 deletions generated-interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ type APIResponseAssertions interface {
ToBeOK() error
}

// A Browser is created via [BrowserType.Launch]. An example of using a [Browser] to create a [Page]:
// A Browser is created via [BrowserType.Launch]. An example of using a [Browser] to create a [Page]:
type Browser interface {
EventEmitter
// Emitted when Browser gets disconnected from the browser application. This might happen because of one of the
Expand Down Expand Up @@ -210,7 +210,8 @@ type Browser interface {
Version() string
}

// BrowserContexts provide a way to operate multiple independent browser sessions.
// BrowserContexts provide a way to operate multiple independent browser sessions.
//
// If a page opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's browser
// context.
// Playwright allows creating "incognito" browser contexts with [Browser.NewContext] method. "Incognito" browser
Expand Down Expand Up @@ -517,14 +518,15 @@ type BrowserType interface {
Name() string
}

// The `CDPSession` instances are used to talk raw Chrome Devtools Protocol:
// - protocol methods can be called with `session.send` method.
// - protocol events can be subscribed to with `session.on` method.
// The `CDPSession` instances are used to talk raw Chrome Devtools Protocol:
// - protocol methods can be called with `session.send` method.
// - protocol events can be subscribed to with `session.on` method.
//
// Useful links:
// - Documentation on DevTools Protocol can be found here:
// [DevTools Protocol Viewer].
// - Getting Started with DevTools Protocol:
// https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
// - Documentation on DevTools Protocol can be found here:
// [DevTools Protocol Viewer].
// - Getting Started with DevTools Protocol:
// https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
//
// [DevTools Protocol Viewer]: https://chromedevtools.github.io/devtools-protocol/
type CDPSession interface {
Expand Down Expand Up @@ -633,7 +635,8 @@ type Download interface {
String() string
}

// ElementHandle represents an in-page DOM element. ElementHandles can be created with the [Page.QuerySelector]
// ElementHandle represents an in-page DOM element. ElementHandles can be created with the [Page.QuerySelector]
//
// method.
// **NOTE** The use of ElementHandle is discouraged, use [Locator] objects and web-first assertions instead.
// ElementHandle prevents DOM element from garbage collection unless the handle is disposed with [JSHandle.Dispose].
Expand Down Expand Up @@ -1131,11 +1134,12 @@ type FileChooser interface {
// At every point of time, page exposes its current frame tree via the [Page.MainFrame] and [Frame.ChildFrames]
// methods.
// [Frame] object's lifecycle is controlled by three events, dispatched on the page object:
// - [Page.OnFrameAttached] - fired when the frame gets attached to the page. A Frame can be attached to the page
// only once.
// - [Page.OnFrameNavigated] - fired when the frame commits navigation to a different URL.
// - [Page.OnFrameDetached] - fired when the frame gets detached from the page. A Frame can be detached from the
// page only once.
// - [Page.OnFrameAttached] - fired when the frame gets attached to the page. A Frame can be attached to the page
// only once.
// - [Page.OnFrameNavigated] - fired when the frame commits navigation to a different URL.
// - [Page.OnFrameDetached] - fired when the frame gets detached from the page. A Frame can be detached from the
// page only once.
//
// An example of dumping frame tree:
type Frame interface {
// Returns the added tag when the script's onload fires or when the script content was injected into frame.
Expand Down Expand Up @@ -2848,7 +2852,8 @@ type Mouse interface {
Wheel(deltaX float64, deltaY float64) error
}

// Page provides methods to interact with a single tab in a [Browser], or an
// Page provides methods to interact with a single tab in a [Browser], or an
//
// [extension background page] in Chromium. One [Browser]
// instance might have multiple [Page] instances.
// This example creates a page, navigates it to a URL, and then saves a screenshot:
Expand Down Expand Up @@ -3916,9 +3921,10 @@ type PlaywrightAssertions interface {
}

// Whenever the page sends a request for a network resource the following sequence of events are emitted by [Page]:
// - [Page.OnRequest] emitted when the request is issued by the page.
// - [Page.OnResponse] emitted when/if the response status and headers are received for the request.
// - [Page.OnRequestFinished] emitted when the response body is downloaded and the request is complete.
// - [Page.OnRequest] emitted when the request is issued by the page.
// - [Page.OnResponse] emitted when/if the response status and headers are received for the request.
// - [Page.OnRequestFinished] emitted when the response body is downloaded and the request is complete.
//
// If request fails at some point, then instead of `requestfinished` event (and possibly instead of 'response'
// event), the [Page.OnRequestFailed] event is emitted.
// **NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request
Expand Down
2 changes: 1 addition & 1 deletion helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestAssignFields(t *testing.T) {
omitExtra bool
}
)
var testV = "foo"
testV := "foo"

tests := []struct {
name string
Expand Down
6 changes: 2 additions & 4 deletions input_files_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (

const fileSizeLimitInBytes = 50 * 1024 * 1024

var (
ErrInputFilesSizeExceeded = errors.New("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.")
)
var ErrInputFilesSizeExceeded = errors.New("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.")

type inputFiles struct {
Selector *string `json:"selector,omitempty"`
Expand All @@ -26,7 +24,7 @@ type inputFiles struct {
// - files should be one of: string, []string, InputFile, []InputFile,
// string: local file path
func convertInputFiles(files interface{}, context *browserContextImpl) (*inputFiles, error) {
var converted = &inputFiles{}
converted := &inputFiles{}
switch items := files.(type) {
case InputFile:
if sizeOfInputFiles([]InputFile{items}) > fileSizeLimitInBytes {
Expand Down
4 changes: 1 addition & 3 deletions internal/multierror/multierror_g0120.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ package multierror

import "errors"

var (
Join = errors.Join
)
var Join = errors.Join
4 changes: 1 addition & 3 deletions internal/multierror/multierror_go119.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ package multierror

import "go.uber.org/multierr"

var (
Join = multierr.Combine
)
var Join = multierr.Combine

0 comments on commit 0d5814a

Please sign in to comment.