diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 88796e3..227fb7a 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -32,9 +32,9 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Go version: [e.g. 1.21] - - Package version: [e.g. 1.0.0] +- OS: [e.g. iOS] +- Go version: [e.g. 1.21] +- Package version: [e.g. 1.0.0] **Additional context** Add any other context about the problem here. diff --git a/.github/linters/.golangci.yml b/.github/linters/.golangci.yml index 1c817ae..b592b37 100644 --- a/.github/linters/.golangci.yml +++ b/.github/linters/.golangci.yml @@ -42,6 +42,11 @@ linters: - makezero - wrapcheck - interfacebloat + - dupl + - errorlint + - gosmopolitan + - ireturn + - nolintlint # disabled because of generics - rowserrcheck diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 24fa016..51cd28b 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -9,6 +9,11 @@ on: branches: [ "main" ] schedule: - cron: '0 9 * * *' + +permissions: + contents: read + security-events: write + pull-requests: read jobs: analyze: diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 8412e1a..7cf6f2f 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -11,6 +11,9 @@ on: - main pull_request: +permissions: + contents: read + jobs: build: name: Build Examples diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 2170d3c..06f8418 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -11,9 +11,14 @@ on: - main pull_request: +permissions: + contents: read + packages: read + statuses: write + jobs: - build: - name: Lint Code Base + super-linter: + name: Super-Linter runs-on: ubuntu-latest steps: @@ -25,6 +30,22 @@ jobs: - name: Lint Code Base uses: super-linter/super-linter/slim@v6 env: - VALIDATE_GO: true VALIDATE_ALL_CODEBASE: true - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + VALIDATE_GO: false + VALIDATE_MARKDOWN: false + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + golangci-lint: + name: GolangCI-Lint + runs-on: ubuntu-latest + steps: + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: 1.22.0 + - name: Checkout source code + uses: actions/checkout@v4 + - name: Install dependencies + run: go mod tidy + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v4 \ No newline at end of file diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 48e828e..42e662d 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -6,6 +6,12 @@ on: schedule: - cron: '0 8 * * *' +permissions: + contents: read + statuses: write + issues: write + pull-requests: write + jobs: stale: diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index e44903d..12a5b2c 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -52,7 +52,7 @@ decisions when appropriate. This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. -Examples of representing our community include using an official e-mail address, +Examples of representing our community include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event. @@ -60,7 +60,7 @@ representative at an online or offline event. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at -info@kaiser-bielefeld.de. +[info@kaiser-bielefeld.de](mailto:info@kaiser-bielefeld.de). All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the @@ -116,13 +116,11 @@ the community. This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at -https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. +[contributor-covenant.org](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html). Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). -[homepage]: https://www.contributor-covenant.org - For answers to common questions about this code of conduct, see the FAQ at -https://www.contributor-covenant.org/faq. Translations are available at -https://www.contributor-covenant.org/translations. +[https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are available at +[https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations). diff --git a/SECURITY.md b/SECURITY.md index f634a3e..79cf10a 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,7 +2,7 @@ ## Supported Versions -I am dedicated to ensure the security of go-dbase. To achieve this, I follow the Semantic Versioning (semver) scheme, where revisions are in the format "major.minor.patch". +I am dedicated to ensure the security of go-dbase. To achieve this, I follow the Semantic Versioning (SemVer) scheme, where revisions are in the format "major.minor.patch". I will release patches for any security vulnerabilities that are discovered in the latest major or minor release. | Version | Supported | diff --git a/dbase/conversion.go b/dbase/conversion.go index 5c698b5..22da694 100644 --- a/dbase/conversion.go +++ b/dbase/conversion.go @@ -22,6 +22,7 @@ func julianDate(y, m, d int) int { // Convert julian day number to year, month and day. // (Julian day number -> days since 01-01-4712 BC) +// nolint: gocritic // assignment can not be simplified func julianToDate(jd int) (int, int, int) { l := jd + 68569 n := (4 * l) / 146097 diff --git a/dbase/error.go b/dbase/error.go index 6df5899..b79a70e 100644 --- a/dbase/error.go +++ b/dbase/error.go @@ -37,7 +37,7 @@ func NewError(err string) Error { trace: make([]string, 0), details: make([]error, 0), } - e.trace = trace(e, 2) + e.trace = trace(e) return e } @@ -47,7 +47,7 @@ func NewErrorf(format string, a ...interface{}) Error { trace: make([]string, 0), details: make([]error, 0), } - e.trace = trace(e, 2) + e.trace = trace(e) return e } @@ -82,7 +82,7 @@ func WrapError(err error) Error { return NewError("unknown error occurred - cant wrap nil error") } if e, ok := err.(Error); ok { - e.trace = trace(e, 2) + e.trace = trace(e) return e } e := Error{ @@ -90,12 +90,12 @@ func WrapError(err error) Error { trace: make([]string, 0), details: make([]error, 0), } - e.trace = trace(e, 2) + e.trace = trace(e) return e } -func trace(e Error, level int) []string { - _, file, line, ok := runtime.Caller(level) +func trace(e Error) []string { + _, file, line, ok := runtime.Caller(2) if !ok { return e.trace } diff --git a/dbase/io_unix.go b/dbase/io_unix.go index 9f7d2e7..88882c6 100644 --- a/dbase/io_unix.go +++ b/dbase/io_unix.go @@ -203,7 +203,7 @@ func (u UnixIO) ReadHeader(file *File) error { return nil } -func (u UnixIO) WriteHeader(file *File) (err error) { +func (u UnixIO) WriteHeader(file *File) error { debugf("Writing header - exclusive writing: %v", file.config.WriteLock) handle, err := u.getHandle(file) if err != nil { @@ -280,7 +280,7 @@ func (u UnixIO) ReadColumns(file *File) ([]*Column, *Column, error) { return columns, nullFlag, nil } -func (u UnixIO) WriteColumns(file *File) (err error) { +func (u UnixIO) WriteColumns(file *File) error { debugf("Writing columns - exclusive writing: %v", file.config.WriteLock) handle, err := u.getHandle(file) if err != nil { @@ -488,7 +488,7 @@ func (u UnixIO) WriteMemo(file *File, raw []byte, text bool, length int) ([]byte return address, nil } -func (u UnixIO) WriteMemoHeader(file *File, size int) (err error) { +func (u UnixIO) WriteMemoHeader(file *File, size int) error { relatedHandle, err := u.getRelatedHandle(file) if err != nil { return WrapError(err) @@ -543,7 +543,7 @@ func (u UnixIO) ReadRow(file *File, position uint32) ([]byte, error) { return buf, nil } -func (u UnixIO) WriteRow(file *File, row *Row) (err error) { +func (u UnixIO) WriteRow(file *File, row *Row) error { debugf("Writing row: %d ...", row.Position) row.handle.dbaseMutex.Lock() defer row.handle.dbaseMutex.Unlock() diff --git a/examples/documentation/documentation.go b/examples/documentation/documentation.go index 8406170..e10a798 100644 --- a/examples/documentation/documentation.go +++ b/examples/documentation/documentation.go @@ -99,7 +99,7 @@ func main() { output = append(output, "\n\n## Columns\n\n") for _, info := range tableInfos { - output = append(output, fmt.Sprintf("### %v\n\n", info.Name)) + output = append(output, fmt.Sprintf("\n### %v\n\n", info.Name)) output = append(output, "| Column | Type | Length | Comment |\n|---|---|---|---|\n") for _, column := range info.ColumnsInfo { output = append(output, column.String()) diff --git a/examples/documentation/documentation.md b/examples/documentation/documentation.md index 9b339e4..7d45920 100644 --- a/examples/documentation/documentation.md +++ b/examples/documentation/documentation.md @@ -2,60 +2,64 @@ Exracted in 45.2824ms -| Table | Columns | Records | First record | Row size | File size | Modified | -|---|---|---|---|---|---|---| -| [employees](#employees) | 16 | 3 | 808 | 523 B | 2.4 kB | 2022-10-15 00:00:00 +0200 CEST | -| [expense_categories](#expense_categories) | 3 | 5 | 392 | 59 B | 687 B | 2022-10-15 00:00:00 +0200 CEST | -| [expense_details](#expense_details) | 6 | 6 | 488 | 79 B | 962 B | 2022-10-15 00:00:00 +0200 CEST | -| [expense_reports](#expense_reports) | 9 | 3 | 584 | 140 B | 1.0 kB | 2022-10-15 00:00:00 +0200 CEST | +| Table | Columns | Records | First record | Row size | File size | Modified | +| ----------------------------------------- | ------- | ------- | ------------ | -------- | --------- | ------------------------------ | +| [employees](#employees) | 16 | 3 | 808 | 523 B | 2.4 kB | 2022-10-15 00:00:00 +0200 CEST | +| [expense_categories](#expense_categories) | 3 | 5 | 392 | 59 B | 687 B | 2022-10-15 00:00:00 +0200 CEST | +| [expense_details](#expense_details) | 6 | 6 | 488 | 79 B | 962 B | 2022-10-15 00:00:00 +0200 CEST | +| [expense_reports](#expense_reports) | 9 | 3 | 584 | 140 B | 1.0 kB | 2022-10-15 00:00:00 +0200 CEST | ## EMPLOYEES -| Name | Type | Golang type | Length | Comment | -| --- | --- | --- | --- | --- | -| *EMPLOYEEID* | I | int32 | 4 | | -| *DEPARTMENT* | C | string | 50 | | -| *SOCIALSECU* | C | string | 30 | | -| *EMPLOYEENU* | C | string | 30 | | -| *FIRSTNAME* | C | string | 50 | | -| *LASTNAME* | C | string | 50 | | -| *TITLE* | C | string | 50 | | -| *EMAILNAME* | C | string | 50 | | -| *EXTENSION* | C | string | 30 | | -| *ADDRESS* | M | []uint8 | 4 | | -| *CITY* | C | string | 50 | | -| *STATEORPRO* | C | string | 20 | | -| *POSTALCODE* | C | string | 20 | | -| *COUNTRY* | C | string | 50 | | -| *WORKPHONE* | C | string | 30 | | -| *NOTES* | M | []uint8 | 4 | | +| Name | Type | Golang type | Length | Comment | +| ------------ | ---- | ----------- | ------ | ------- | +| *EMPLOYEEID* | I | int32 | 4 | | +| *DEPARTMENT* | C | string | 50 | | +| *SOCIALSECU* | C | string | 30 | | +| *EMPLOYEENU* | C | string | 30 | | +| *FIRSTNAME* | C | string | 50 | | +| *LASTNAME* | C | string | 50 | | +| *TITLE* | C | string | 50 | | +| *EMAILNAME* | C | string | 50 | | +| *EXTENSION* | C | string | 30 | | +| *ADDRESS* | M | []uint8 | 4 | | +| *CITY* | C | string | 50 | | +| *STATEORPRO* | C | string | 20 | | +| *POSTALCODE* | C | string | 20 | | +| *COUNTRY* | C | string | 50 | | +| *WORKPHONE* | C | string | 30 | | +| *NOTES* | M | []uint8 | 4 | | + ## EXPENSE_CATEGORIES -| Name | Type | Golang type | Length | Comment | -| --- | --- | --- | --- | --- | -| *EXPENSECAT* | I | int32 | 4 | | -| *EXPENSECA2* | C | string | 50 | | -| *EXPENSECA3* | I | int32 | 4 | | +| Name | Type | Golang type | Length | Comment | +| ------------ | ---- | ----------- | ------ | ------- | +| *EXPENSECAT* | I | int32 | 4 | | +| *EXPENSECA2* | C | string | 50 | | +| *EXPENSECA3* | I | int32 | 4 | | + + ## EXPENSE_DETAILS -| Name | Type | Golang type | Length | Comment | -| --- | --- | --- | --- | --- | -| *EXPENSEDET* | I | int32 | 4 | | -| *EXPENSEREP* | I | int32 | 4 | | -| *EXPENSECAT* | I | int32 | 4 | | -| *EXPENSEITE* | Y | float64 | 8 | | -| *EXPENSEIT2* | C | string | 50 | | -| *EXPENSEDAT* | T | time.Time | 8 | | +| Name | Type | Golang type | Length | Comment | +| ------------ | ---- | ----------- | ------ | ------- | +| *EXPENSEDET* | I | int32 | 4 | | +| *EXPENSEREP* | I | int32 | 4 | | +| *EXPENSECAT* | I | int32 | 4 | | +| *EXPENSEITE* | Y | float64 | 8 | | +| *EXPENSEIT2* | C | string | 50 | | +| *EXPENSEDAT* | T | time.Time | 8 | | + ## EXPENSE_REPORTS -| Name | Type | Golang type | Length | Comment | -| --- | --- | --- | --- | --- | -| *EXPENSEREP* | I | int32 | 4 | | -| *EMPLOYEEID* | I | int32 | 4 | | -| *EXPENSETYP* | C | string | 50 | | -| *EXPENSERPT* | C | string | 30 | | -| *EXPENSERP2* | M | []uint8 | 4 | | -| *DATESUBMIT* | T | time.Time | 8 | | -| *ADVANCEAMO* | Y | float64 | 8 | | -| *DEPARTMENT* | C | string | 30 | | -| *PAID* | L | bool | 1 | | +| Name | Type | Golang type | Length | Comment | +| ------------ | ---- | ----------- | ------ | ------- | +| *EXPENSEREP* | I | int32 | 4 | | +| *EMPLOYEEID* | I | int32 | 4 | | +| *EXPENSETYP* | C | string | 50 | | +| *EXPENSERPT* | C | string | 30 | | +| *EXPENSERP2* | M | []uint8 | 4 | | +| *DATESUBMIT* | T | time.Time | 8 | | +| *ADVANCEAMO* | Y | float64 | 8 | | +| *DEPARTMENT* | C | string | 30 | | +| *PAID* | L | bool | 1 | |