Skip to content

Commit

Permalink
chore: lining; add flake.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
mavolin committed Jun 29, 2024
1 parent b7e4ca9 commit 4e9bfe1
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 75 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
25 changes: 18 additions & 7 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v3
- name: Generate Coverage Report
run: go test -coverprofile coverage.txt -covermode atomic ./...
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
run: nix develop -c go test -coverprofile coverage.txt -covermode atomic ./...
- name: Upload Unit Test Coverage to Codecov
uses: codecov/codecov-action@v4
with:
flags: unit
- name: Generate Coverage Report for Integration Tests
working-directory: test/
run: nix develop -c bash codecov.sh -coverprofile
- name: Upload Integration Test Coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./test/prepare_coverage.txt,./test/integration_coverage.txt
flags: integration
14 changes: 7 additions & 7 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch All Tags
run: git fetch --force --tags
- name: Set-Up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
- name: Install Dependencies
run: go install golang.org/x/tools/cmd/stringer@latest
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
go-version: '>=1.21.0'
- name: Install Nix
uses: cachix/install-nix-action@v22
with:
args: release --rm-dist
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser
run: nix develop -c goreleaser release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Lint Project
uses: reviewdog/action-golangci-lint@v1
uses: reviewdog/action-golangci-lint@v2
with:
reporter: github-pr-review
13 changes: 8 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Test

on: [push, pull_request]

jobs:
Expand All @@ -7,8 +8,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v3
- name: Run Tests
run: go test -race ./...
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Unit Tests
run: nix develop -c go test -race ./...
59 changes: 34 additions & 25 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- deadcode
- dupword
- durationcheck
- errcheck
- errname
- errorlint
- execinquery
- exhaustive
- exportloopref
- forbidigo
- gocheckcompilerdirectives
- gocritic
- godot
- gofumpt
Expand All @@ -16,47 +22,50 @@ linters:
- gosimple
- govet
- ineffassign
- lll
- loggercheck
- misspell
- nakedret
- nilerr
- nolintlint
- nosprintfhostport
- prealloc
- predeclared
- reassign
- revive
- rowserrcheck
- staticcheck
- structcheck
- thelper
- tenv
- tparallel
- typecheck
- unconvert
- unparam
- unused
- varcheck
- usestdlibvars
- wastedassign
- whitespace

linters-settings:
godot:
exclude:
- ^\s*.+:.+$
- ^\s*(?:=+|/+|-+|\++)
- ^\s*\w+$
- ^\s*[a-z0-9]
unparam:
check-exported: true
gocritic:
disabled-checks:
- singleCaseSwitch
dupword:
ignore:
- XXX

errcheck:
exclude-functions:
- github.com/mavolin/corgi/file/fileutil.Walk

issues:
exclude-rules:
# prevent errors on type assertions with field access
- linters:
- errorlint
source: \w\.\(\*?\w+\)\.\w+
- linters:
- lll
source: //(?:nolint|go|goland)
# io.EOF and sql.ErrNoRows should, according to the doc, never be wrapped
- linters:
- errorlint
source: "\\w+\\s*==\\s*(io.EOF|sql.ErrNoRows)"
- path: (?:_test|test_util)\.go$
linters:
- bodyclose
- errcheck
- errorlint
- gosec
- unparam
- path: ^test/
linters: [unused]
- path: ^de/pensioninsurancenumber/area_code.go$
linters: [revive]
2 changes: 1 addition & 1 deletion de/postalcode/postalcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var ErrSyntax = errors.New("postal code: must be 5-digit number")

// PostalCode represents a German postal code code (Postleitzahl).
// PostalCode represents a German postal code (Postleitzahl).
//
// It is a 5-digit string.
type PostalCode string
Expand Down
60 changes: 60 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
};

outputs = {
self,
nixpkgs,
utils,
}:
utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
};
in {
formatter = pkgs.alejandra;

devShells.default = pkgs.mkShell {
packages = with pkgs; [go golangci-lint goreleaser];

hardeningDisable = ["fortify"];
};
}
);
}
35 changes: 15 additions & 20 deletions iban/national_checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var checksumFuncs = map[iso3166.Alpha2Code]func(IBAN) bool{
},
// https://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
// https://www.ecbs.org/Download/Tr201v3.9.pdf (page 105)
// ECBS calls the concatentation of the bank code and account no. the
// ECBS calls the concatenation of the bank code and account no. the
// "account number", which is a bit confusing.
// Otherwise, the same as wiki.
iso3166.NO: func(iban IBAN) bool {
Expand Down Expand Up @@ -188,19 +188,15 @@ var checksumFuncs = map[iso3166.Alpha2Code]func(IBAN) bool{

// https://en.wikipedia.org/wiki/International_Bank_Account_Number#National_check_digits
// https://www.ecbs.org/Download/Tr201v3.9.pdf (page 34)
// wiki has complement wrong, otherwise as above
// Wiki has complement wrong, otherwise as above.
func czech(iban IBAN) bool {
r := weighted(iban.BranchCode, 11, 10, 5, 8, 4, 2, 1)
if r != 0 {
return false
}

r = weighted(iban.AccountNumber, 11, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1)
if r != 0 {
return false
}

return true
return r == 0
}

// https://en.wikipedia.org/wiki/International_Bank_Account_Number#National_check_digits
Expand Down Expand Up @@ -229,17 +225,16 @@ func franceTransliterate(s string) string {
return string(bs)
}

var (
// https://www.ecbs.org/Download/Tr201v3.9.pdf (page 77)
// Officially called odd mapping, but since they consider the first digit
// to be odd, and 0 is even, I'm swapping the names.
italyEvenMapping = [...]int{
1, 0, 5, 7, 9, 13, 15, 17, 19, 21,
2, 4, 18, 20, 11, 3, 6, 8, 12, 14,
16, 10, 22, 25, 24, 23,
}
// odd mapping is just ascending numbers
)
// https://www.ecbs.org/Download/Tr201v3.9.pdf (page 77)
// Officially called odd mapping, but since they consider the first digit
// to be odd, and 0 is even, I'm swapping the names.
var italyEvenMapping = [...]int{
1, 0, 5, 7, 9, 13, 15, 17, 19, 21,
2, 4, 18, 20, 11, 3, 6, 8, 12, 14,
16, 10, 22, 25, 24, 23,
}

// Odd mapping is just ascending numbers.

func italy(iban IBAN) bool {
if len(iban.NationalChecksum) != 1 {
Expand Down Expand Up @@ -318,10 +313,10 @@ func weighted(s string, mod int, weights ...int) int {
return sum % mod
}

func weightedRTL(s string, mod int, weigths ...int) int {
func weightedRTL(s string, mod int, weights ...int) int {
var sum int
for i, r := 0, len(s)-1; r >= 0; i, r = i+1, r-1 {
sum += (digit(rune(s[r])) * weigths[i%len(weigths)]) % mod
sum += (digit(rune(s[r])) * weights[i%len(weights)]) % mod
}
return sum % mod
}
Expand Down
2 changes: 1 addition & 1 deletion iban/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Parse(s string) (IBAN, error) {

iban.BBAN = s[4:]

bbanRegexp, _ := bbanRegexps[iban.CountryCode]
bbanRegexp := bbanRegexps[iban.CountryCode]
if bbanRegexp != nil {
matches := bbanRegexp.FindStringSubmatch(iban.BBAN)
if matches == nil {
Expand Down
Loading

0 comments on commit 4e9bfe1

Please sign in to comment.