-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Noctx #1179
Add Noctx #1179
Conversation
Hey, thank you for opening your first Pull Request ! |
@@ -114,6 +114,7 @@ linters: | |||
# - goerr113 | |||
# - maligned | |||
# - nestif | |||
# - noctx (TODO: enable after next release; current release at time of writing is v1.27) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't it be enabled now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The golangci-lint version is 1.27 in Github Actions.
Version 1.27 does not include noctx
, test in CI is failed.
https://github.com/golangci/golangci-lint/runs/745557992
lint
only-new-issues: false
Run golangci/golangci-lint-action@v1
with:
version: v1.27
github-token: ***
only-new-issues: false
prepare environment
go env
Installed Go in 15611ms
Prepared env in 15627ms
run golangci-lint
Running [/home/runner/golangci-lint-1.27.0-linux-amd64/golangci-lint run --out-format=github-actions] in [] ...
level=error msg="Running error: no such linter \"noctx\""
##[error]golangci-lint exit with code 3
Ran golangci-lint in 125ms
@@ -110,7 +110,7 @@ func testOneSource(t *testing.T, sourcePath string) { | |||
"--print-issued-lines=false", | |||
"--print-linter-name=false", | |||
"--out-format=line-number", | |||
"--max-same-issues=10", | |||
"--max-same-issues=100", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have you decided to increase the limit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change --max-same-issues
number to output all results. It enables to pass all tests.
When "--max-same-issues=10"
$ T=noctx.go make test_linters
GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdataWithIssuesDir/noctx.go
=== RUN TestSourcesFromTestdataWithIssuesDir
=== RUN TestSourcesFromTestdataWithIssuesDir/noctx.go
=== PAUSE TestSourcesFromTestdataWithIssuesDir/noctx.go
=== CONT TestSourcesFromTestdataWithIssuesDir/noctx.go
--- FAIL: TestSourcesFromTestdataWithIssuesDir (1.28s)
linters_test.go:41: testdata/*.go
--- FAIL: TestSourcesFromTestdataWithIssuesDir/noctx.go (1.42s)
linters_test.go:142: [run --allow-parallel-runners --disable-all --print-issued-lines=false --print-linter-name=false --out-format=line-number --max-same-issues=10 -Enoctx --no-config testdata/noctx.go]
linters_test.go:37:
Error Trace: linters_test.go:37
linters_test.go:143
linters_test.go:57
Error: Received unexpected error:
noctx.go:34: missing error "should rewrite http.NewRequestWithContext or add \\(\\*Request\\).WithContext"
noctx.go:47: missing error "should rewrite http.NewRequestWithContext or add \\(\\*Request\\).WithContext"
noctx.go:69: missing error "should rewrite http.NewRequestWithContext or add \\(\\*Request\\).WithContext"
noctx.go:122: missing error "should rewrite http.NewRequestWithContext or add \\(\\*Request\\).WithContext"
Test: TestSourcesFromTestdataWithIssuesDir/noctx.go
FAIL
FAIL github.com/golangci/golangci-lint/test 3.172s
FAIL
make: *** [Makefile:38: test_linters] Error 1
return req12, req13 | ||
}() | ||
|
||
func() (*http.Request, *http.Request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does context have to be set in scope of the function where Request
is created?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If context is set it in other scope, it will be difficult to migrate to http.NewRequestWithContext.
WithContext should be run on the next line of NewRequest for compatibility of http.NewRequestWithContext function.
req3 = req3.WithContext(ctx) | ||
cli.Do(req3) | ||
|
||
f2 := func(req *http.Request, ctx context.Context) *http.Request { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this function? There are few other similar introduced in this test file and I'm not sure I can grasp why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SSA is different for each test cases. These test cases are useful for finding bugs.
If you don't need these tests for golangci-lint, I can remove them, leaving a simple test case for golangci-lint, since they are running in noctx repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm absolutely fine with the tests - I just wanted to understand why you decided to follow such an approach :)
Hey, @sonatard — we just merged your PR to
By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests. Thanks again! |
noctx
finds sending http request without context.Context.https://github.com/sonatard/noctx