Skip to content

Commit

Permalink
xk6-sse: fix linter issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phymbert committed Apr 4, 2024
1 parent c6e5e6a commit e07593e
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
args: --timeout=30m --config=.golangci.yml
args: --config=.golangci.yml
121 changes: 109 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,115 @@
run:
timeout: 10m

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

# We want to try and improve the comments in the k6 codebase, so individual
# non-golint items from the default exclusion list will gradually be added
# to the exclude-rules below
exclude-use-default: false

exclude-rules:
# Exclude duplicate code and function length and complexity checking in test
# files (due to common repeats and long functions in test code)
- path: _(test|gen)\.go
linters:
- cyclop
- dupl
- gocognit
- funlen
- lll
- nestif
- stylecheck

linters-settings:
nolintlint:
# Disable to ensure that nolint directives don't have a leading space. Default is true.
allow-leading-space: false
exhaustive:
default-signifies-exhaustive: true
govet:
check-shadowing: true
cyclop:
max-complexity: 25
maligned:
suggest-new: true
dupl:
threshold: 150
goconst:
min-len: 10
min-occurrences: 5
funlen:
lines: 80
statements: 60

linters:
enable-all: true
disable:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- contextcheck
- cyclop
- wsl
- godox
- dogsled
- dupl
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- funlen
- gocheckcompilerdirectives
- gochecknoglobals
- ireturn
- nlreturn
- testpackage
- paralleltest
- exhaustivestruct
- exhaustruct
- gocognit
- gochecknoinits
- gocyclo
- goconst
- gocritic
- gofmt
- gofumpt
- goimports
- gomoddirectives
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
- interfacebloat
- lll
- makezero
- misspell
- nakedret
- nestif
- nilerr
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- paralleltest
- prealloc
- predeclared
- promlinter
- revive
- reassign
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tenv
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
fast: false
3 changes: 3 additions & 0 deletions lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

golangci-lint run --config=.golangci.yml
2 changes: 2 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package sse

import (
"errors"

"go.k6.io/k6/js/modules"
"go.k6.io/k6/metrics"
)

// MetricEventName is the sse event metric of the module
const MetricEventName = "sse_event"

type sseMetrics struct {
Expand Down
5 changes: 2 additions & 3 deletions sse.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Package sse implements a k6/x/sse javascript module extension for k6.
// It provides basic functionality to handle Server-Sent Event over http
// that *blocks* the event loop while the http connection is opened.
// [SSE API design document]: https://github.com/phymbert/xk6-sse/blob/master/docs/design/021-sse-api.md#proposed-solution
// [SSE API design document]:
// https://github.com/phymbert/xk6-sse/blob/master/docs/design/021-sse-api.md#proposed-solution
package sse

import (
Expand Down Expand Up @@ -168,7 +169,6 @@ func (mi *sse) Open(url string, args ...goja.Value) (*HTTPResponse, error) {
func (mi *sse) open(ctx context.Context, state *lib.State,
rt *goja.Runtime, url string, args *sseOpenArgs,
) (*Client, func(), error) {

sseClient := Client{
ctx: ctx,
rt: rt,
Expand Down Expand Up @@ -352,7 +352,6 @@ func (c *Client) readEvents(readChan chan Event, errorChan chan error, closeChan
var buf bytes.Buffer

for {

line, err := reader.ReadBytes('\n')
if err != nil {
if errors.Is(err, io.EOF) {
Expand Down

0 comments on commit e07593e

Please sign in to comment.