Skip to content
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

Merged
merged 4 commits into from Jun 8, 2020
Merged

Add Noctx #1179

merged 4 commits into from Jun 8, 2020

Conversation

sonatard
Copy link
Contributor

@sonatard sonatard commented Jun 6, 2020

noctx finds sending http request without context.Context.
https://github.com/sonatard/noctx

@boring-cyborg
Copy link

boring-cyborg bot commented Jun 6, 2020

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

CLAassistant commented Jun 6, 2020

CLA assistant check
All committers have signed the CLA.

@sonatard sonatard marked this pull request as ready for review June 6, 2020 17:26
@@ -114,6 +114,7 @@ linters:
# - goerr113
# - maligned
# - nestif
# - noctx (TODO: enable after next release; current release at time of writing is v1.27)
Copy link
Contributor

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?

Copy link
Contributor Author

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",
Copy link
Contributor

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?

Copy link
Contributor Author

@sonatard sonatard Jun 7, 2020

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

@sonatard sonatard Jun 8, 2020

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.

Copy link
Contributor

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 :)

@iwankgb iwankgb merged commit f1a46f9 into golangci:master Jun 8, 2020
@golangci-automator
Copy link

Hey, @sonatard — we just merged your PR to golangci-lint! 🔥🚀

golangci-lint is built by awesome people like you. Let us say “thanks”: we just invited you to join the GolangCI organization on GitHub.
This will add you to our team of maintainers. Accept the invite by visiting this link.

By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.
More information about contributing is here.

Thanks again!

@sonatard sonatard deleted the noctx branch June 8, 2020 22:53
@ldez ldez added the linter: new Support new linter label Dec 7, 2020
@ldez ldez added this to the v1.28 milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linter: new Support new linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants