Files
gocryptotrader/.github/workflows/misc.yml
Adrian Gallagher a5b638bfb7 GHA: Add additional checks for common issues (#1922)
* GHA, tests: Add additional checks for common issues

These checks include:
- Ensuring that all testify funcs use their formatted variants (e.g., `assert.Equalf(t, expected, actual)` instead of `assert.Equal(t, expected, actual)`).
- Replacing `%s` with %q
- Enforcing consistent usage of should/must wording for testify assert/require messages

* Add support for checking backticked string format specifiers and fix issues

* tests: Fix error comparisons

* tests: Replace errors.Is(err, nil) usage with testify and automate check

* refactor: Rename ExtractPort to ExtractPortOrDefault

* tests: Replace assert with require for error handling in multiple test files

* tests: Replace assert with require for error handling and improve assertions in data tests

* tests: Fix typo in assertion message for StreamVol test

* OKX: Fix GetOpenInterestAndVolumeStrike test with instrument selection and improved assertions

* OKX: Revert intentional error check

* Improve error message for expiry time check in GetOpenInterestAndVolumeStrike test
2025-05-28 12:26:51 +10:00

47 lines
1.9 KiB
YAML

name: misc
on: [push, pull_request]
jobs:
lint:
name: miscellaneous checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check for currency.NewPair(BTC, USD) used instead of currency.NewBTCUSD
run: |
grep -r -n --color=always -E "currency.NewPair\(currency.BTC, currency.USDT?\)" * || exit 0
echo "::error::Replace currency.NewPair(BTC, USD*) with currency.NewBTCUSD*()"
exit 1
- name: Check for missing postfix `f` format func variant for testify assertions
run: |
grep -r -n -P --include="*.go" --color=always '(assert|require)\.[A-Za-z_]\w*?(?<!f)\((?:(?!fmt\.Sprintf).)*%.*' || exit 0
echo "::error::Replace func with the `…f` func variant (e.g. Equalf, Errorf)"
exit 1
- name: Check for quoted and backticked %s usage in format specifier strings
run: |
grep -r -n --include='*.go' --color=always -E "[\`']%s[\`']" . || exit 0
echo "::error::Replace '%s' or `%s` format specifier with %q"
exit 1
- name: Check for testify `require… "should"` and `assert… "must"` message consistency
run: |
exit_code=0
echo "Checking for 'should' in require messages..."
grep -r -n --include="*.go" --color=always -E 'require\.[A-Za-z0-9_]+.*"[^"]*should[^"]*"' . && exit_code=1 || true
echo "Checking for 'must' in assert messages..."
grep -r -n --include="*.go" --color=always -E 'assert\.[A-Za-z0-9_]+.*"[^"]*must[^"]*"' . && exit_code=1 || true
if [ $exit_code -eq 1 ]; then
echo "::error::Replace \"should\" in require messages and \"must\" in assert messages"
exit 1
fi
- name: Check for errors.Is(err, nil) usage
run: |
grep -r -n --include='*_test.go' --color=always -E "errors.Is\([^,]+, nil" . || exit 0
echo "::error::Replace errors.Is(err, nil) with testify equivalents"
exit 1