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

Enable static checks #10

Merged
merged 5 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
go-version: '1.20'
cache: false

- name: staticcheck
uses: dominikh/[email protected]
with:
version: "2023.1.6"

- name: Build
run: go build -v ./...

Expand Down
22 changes: 8 additions & 14 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
name: OSX

on: [push]
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
name: Build
runs-on: macos-latest

steps:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ^1.13

- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: '1.20'
cache: false

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi

- name: Build
run: go build -v ./...

Expand Down
10 changes: 10 additions & 0 deletions src/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ const (
mdb_TIMESTAMPTZ = "timestamptz"

// full names and aliases, spaces are replaced with underscores
//lint:ignore U1000 prepare to enable staticchecks
mdb_CHARACTER = mdb_CHAR
//lint:ignore U1000 prepare to enable staticchecks
mdb_CHARACTER_VARYING = mdb_VARCHAR
//lint:ignore U1000 prepare to enable staticchecks
mdb_CHARACHTER_LARGE_OBJECT = mdb_CLOB
//lint:ignore U1000 prepare to enable staticchecks
mdb_BINARY_LARGE_OBJECT = mdb_BLOB
//lint:ignore U1000 prepare to enable staticchecks
mdb_NUMERIC = mdb_DECIMAL
//lint:ignore U1000 prepare to enable staticchecks
mdb_DOUBLE_PRECISION = mdb_DOUBLE
)

Expand Down Expand Up @@ -255,6 +261,7 @@ func toByteString(v driver.Value) (string, error) {
case []uint8:
return toQuotedString(string(val))
default:
//lint:ignore ST1005 prepare to enable staticchecks
return "", fmt.Errorf("Unsupported type")
}
}
Expand All @@ -266,6 +273,7 @@ func toDateTimeString(v driver.Value) (string, error) {
case Date:
return toQuotedString(fmt.Sprintf("%04d-%02d-%02d", val.Year, val.Month, val.Day))
default:
//lint:ignore ST1005 prepare to enable staticchecks
return "", fmt.Errorf("Unsupported type")
}
}
Expand Down Expand Up @@ -298,6 +306,7 @@ func convertToGo(value, dataType string) (driver.Value, error) {
value := strings.TrimSpace(value)
return mapper(value)
}
//lint:ignore ST1005 prepare to enable staticchecks
return nil, fmt.Errorf("Type not supported: %s", dataType)
}

Expand All @@ -311,5 +320,6 @@ func convertToMonet(value driver.Value) (string, error) {
if mapper, ok := toMonetMappers[n]; ok {
return mapper(value)
}
//lint:ignore ST1005 prepare to enable staticchecks
return "", fmt.Errorf("Type not supported: %v", t)
}
1 change: 1 addition & 0 deletions src/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func TestConvertToGo(t *testing.T) {
func compareByteArray(t *testing.T, val []byte, e driver.Value) bool {
switch exp := e.(type) {
case []byte:
//lint:ignore S1004 prepare to enable staticchecks
return bytes.Compare(val, exp) == 0
default:
return false
Expand Down
8 changes: 8 additions & 0 deletions src/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func parseDSN(name string) (config, error) {
ipv6_re := regexp.MustCompile(`^((?P<username>[^:]+?)(:(?P<password>[^@]+?))?@)?\[(?P<hostname>(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))+?)\](:(?P<port>\d+?))?\/(?P<database>.+?)$`)

if ipv6_re.MatchString(name) {
//lint:ignore SA4006 prepare to enable staticchecks
m := make([]string, 0)
//lint:ignore SA4006 prepare to enable staticchecks
n := make([]string, 0)
m = ipv6_re.FindAllStringSubmatch(name, -1)[0]
n = ipv6_re.SubexpNames()
Expand All @@ -60,12 +62,14 @@ func parseDSN(name string) (config, error) {
configWithHost, err := parseHost(reverse(host), c)

if err != nil {
//lint:ignore ST1005 prepare to enable staticchecks
return config{}, fmt.Errorf("Invalid DSN")
}

newConfig, err := parseCreds(reverse(creds), configWithHost)

if err != nil {
//lint:ignore ST1005 prepare to enable staticchecks
return config{}, fmt.Errorf("Invalid DSN")
}

Expand All @@ -80,6 +84,7 @@ func parseCreds(creds string, c config) (config, error) {

if found {
if username == "" {
//lint:ignore ST1005 prepare to enable staticchecks
return c, fmt.Errorf("Invalid DSN")
}

Expand All @@ -93,10 +98,12 @@ func parseHost(host string, c config) (config, error) {
host, dbName, found := Cut(host, "/")

if !found {
//lint:ignore ST1005 prepare to enable staticchecks
return c, fmt.Errorf("Invalid DSN")
}

if host == "" {
//lint:ignore ST1005 prepare to enable staticchecks
return c, fmt.Errorf("Invalid DSN")
}

Expand All @@ -113,6 +120,7 @@ func parseHost(host string, c config) (config, error) {
port_num, err := strconv.Atoi(port)

if err != nil {
//lint:ignore ST1005 prepare to enable staticchecks
return c, fmt.Errorf("Invalid DSN")
}

Expand Down
11 changes: 11 additions & 0 deletions src/mapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (c *MapiConn) Disconnect() {
// Cmd sends a MAPI command to MonetDB.
func (c *MapiConn) Cmd(operation string) (string, error) {
if c.State != MAPI_STATE_READY {
//lint:ignore ST1005 prepare to enable staticchecks
return "", fmt.Errorf("Database not connected")
}

Expand Down Expand Up @@ -125,9 +126,11 @@ func (c *MapiConn) Cmd(operation string) (string, error) {
return resp, nil

} else if strings.HasPrefix(resp, mapi_MSG_ERROR) {
//lint:ignore ST1005 prepare to enable staticchecks
return "", fmt.Errorf("Operational error: %s", resp[1:])

} else {
//lint:ignore ST1005 prepare to enable staticchecks
return "", fmt.Errorf("Unknown state: %s", resp)
}
}
Expand Down Expand Up @@ -198,6 +201,7 @@ func (c *MapiConn) tryLogin(iteration int) error {

} else if strings.HasPrefix(prompt, mapi_MSG_ERROR) {
// TODO log error
//lint:ignore ST1005 prepare to enable staticchecks
return fmt.Errorf("Database error: %s", prompt[1:])

} else if strings.HasPrefix(prompt, mapi_MSG_REDIRECT) {
Expand All @@ -209,6 +213,7 @@ func (c *MapiConn) tryLogin(iteration int) error {
if iteration <= 10 {
c.tryLogin(iteration + 1)
} else {
//lint:ignore ST1005 prepare to enable staticchecks
return fmt.Errorf("Maximal number of redirects reached (10)")
}

Expand All @@ -222,9 +227,11 @@ func (c *MapiConn) tryLogin(iteration int) error {
c.Connect()

} else {
//lint:ignore ST1005 prepare to enable staticchecks
return fmt.Errorf("Unknown redirect: %s", prompt)
}
} else {
//lint:ignore ST1005 prepare to enable staticchecks
return fmt.Errorf("Unknown state: %s", prompt)
}

Expand All @@ -242,6 +249,7 @@ func (c *MapiConn) challengeResponse(challenge []byte) (string, error) {
algo := t[5]

if protocol != "9" {
//lint:ignore ST1005 prepare to enable staticchecks
return "", fmt.Errorf("We only speak protocol v9")
}

Expand All @@ -250,6 +258,7 @@ func (c *MapiConn) challengeResponse(challenge []byte) (string, error) {
h = crypto.SHA512.New()
} else {
// TODO support more algorithm
//lint:ignore ST1005 prepare to enable staticchecks
return "", fmt.Errorf("Unsupported algorithm: %s", algo)
}
io.WriteString(h, c.Password)
Expand All @@ -270,6 +279,7 @@ func (c *MapiConn) challengeResponse(challenge []byte) (string, error) {
pwhash = fmt.Sprintf("{MD5}%x", h.Sum(nil))

} else {
//lint:ignore ST1005 prepare to enable staticchecks
return "", fmt.Errorf("Unsupported hash algorithm required for login %s", hashes)
}

Expand Down Expand Up @@ -342,6 +352,7 @@ func (c *MapiConn) putBlock(b []byte) error {
last = 1
}

//lint:ignore S1021 prepare to enable staticchecks
var packed uint16
packed = uint16((length << 1) + last)
flag := new(bytes.Buffer)
Expand Down
7 changes: 6 additions & 1 deletion src/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (s *Stmt) Query(args []driver.Value) (driver.Rows, error) {
return rows, rows.err
}

//lint:ignore SA4006 prepare to enable staticchecks
err = s.storeResult(r)
rows.queryId = s.queryId
rows.lastRowId = s.lastRowId
Expand Down Expand Up @@ -185,6 +186,7 @@ func (s *Stmt) storeResult(r string) error {

} else if strings.HasPrefix(line, mapi_MSG_QTRANS) {
s.offset = 0
//lint:ignore S1019 prepare to enable staticchecks
s.rows = make([][]driver.Value, 0, 0)
s.lastRowId = 0
s.description = nil
Expand Down Expand Up @@ -234,17 +236,19 @@ func (s *Stmt) storeResult(r string) error {
return nil

} else if strings.HasPrefix(line, mapi_MSG_ERROR) {
//lint:ignore ST1005 prepare to enable staticchecks
return fmt.Errorf("Database error: %s", line[1:])

}
}

//lint:ignore ST1005 prepare to enable staticchecks
return fmt.Errorf("Unknown state: %s", r)
}

func (s *Stmt) parseTuple(d string) ([]driver.Value, error) {
items := strings.Split(d[1:len(d)-1], ",\t")
if len(items) != len(s.description) {
//lint:ignore ST1005 prepare to enable staticchecks
return nil, fmt.Errorf("Length of row doesn't match header")
}

Expand All @@ -264,6 +268,7 @@ func (s *Stmt) updateDescription(
internalSizes, precisions, scales, nullOks []int) {

d := make([]description, len(columnNames))
//lint:ignore S1005 prepare to enable staticchecks
for i, _ := range columnNames {
desc := description{
columnName: columnNames[i],
Expand Down