Skip to content

Commit 7f8e374

Browse files
committed
Support exec package
exec.CommandContext can be used to run commands with a context.
1 parent 8d4d1b5 commit 7f8e374

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

noctx.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ var ngFuncMessages = map[string]string{
6565
"(*database/sql.Stmt).Query": "must not be called. use (*database/sql.Conn).QueryContext",
6666
"(*database/sql.Stmt).QueryRow": "must not be called. use (*database/sql.Conn).QueryRowContext",
6767

68+
// exec
69+
"os/exec.Command": "must not be called. use os/exec.CommandContext",
70+
6871
// crypto/tls dialer
6972
"crypto/tls.Dial": "must not be called. use (*crypto/tls.Dialer).DialContext",
7073
"crypto/tls.DialWithDialer": "must not be called. use (*crypto/tls.Dialer).DialContext with NetDialer",

noctx_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func TestAnalyzer(t *testing.T) {
1212
desc string
1313
}{
1414
{desc: "crypto_tls"},
15+
{desc: "exec_cmd"},
1516
{desc: "http_client"},
1617
{desc: "http_request"},
1718
{desc: "network"},

testdata/src/exec_cmd/exec.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package exec
2+
3+
import (
4+
"context"
5+
"os/exec"
6+
)
7+
8+
func _() {
9+
ctx := context.Background()
10+
11+
exec.Command("ls", "-l") // want `os/exec.Command must not be called. use os/exec.CommandContext`
12+
13+
exec.CommandContext(ctx, "ls", "-l")
14+
}

0 commit comments

Comments
 (0)