Skip to content
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
78 changes: 37 additions & 41 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Go

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

permissions:
contents: read
Expand All @@ -17,42 +17,38 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

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

- name: Go Format
run: gofmt -s -w . && git diff --exit-code

- name: Go Tidy
run: go mod tidy && git diff --exit-code

- name: Go mod verify
run: go mod verify

- name: Run linter
uses: golangci/golangci-lint-action@v3
with:
version: latest
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
args: --timeout 3m --verbose

- name: Test
run: go test -v ./...

- name: Update coverage report
uses: ncruces/go-coverage-report@v0
with:
report: true
chart: true
amend: true
if: github.event_name == 'push'
continue-on-error: true
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25"

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

- name: Go Format
run: gofmt -s -w . && git diff --exit-code

- name: Go Tidy
run: go mod tidy && git diff --exit-code

- name: Go mod verify
run: go mod verify

- name: Run linter
uses: golangci/golangci-lint-action@v9
with:
args: --timeout 3m --verbose

- name: Test
run: go test -v ./... -count=10

- name: Update coverage report
uses: ncruces/go-coverage-report@v0
with:
report: true
chart: true
amend: true
if: github.event_name == 'push'
continue-on-error: true
65 changes: 32 additions & 33 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
# More info on config here: https://github.com/golangci/golangci-lint#config-file
version: "2"

run:
deadline: 10s
issues-exit-code: 1
timeout: 10s
tests: true
skip-dirs-use-default: true
skip-dirs:
- bin
- vendor
- tests

output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true

linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2

formats:
text:
path: stdout
print-linter-name: true
colors: true

linters:
disable-all: true
default: none
enable:
- unused
- stylecheck
- gosimple
- govet
- errcheck
- ineffassign
- typecheck
- dupl
- goconst
- goimports
- megacheck
- gosec
- gocritic
- staticcheck
exclusions:
presets:
- comments
- std-error-handling
rules:
- linters:
- staticcheck
text: "ST1003"
- linters:
- staticcheck
text: "ST1000"
settings:
govet:
enable:
- shadow
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2

issues:
exclude-use-default: false
exclude:
- ST1003
- ST1000
formatters:
enable:
- goimports
10 changes: 3 additions & 7 deletions bik/bik_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ func TestValidate(t *testing.T) {
}

for i, tc := range testCases {
tc := tc

isValid, err := Validate(tc.Code)
if err != nil {
require.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code))
Expand Down Expand Up @@ -87,8 +85,6 @@ func TestValidate(t *testing.T) {
},
}
for i, tc := range testCases {
tc := tc

isValid, err := Validate(tc.Code)
if err != nil {
require.ErrorAs(t, err, &tc.Error, fmt.Sprintf("invalid test case %d: input: %s", i, tc.Code))
Expand All @@ -102,7 +98,7 @@ func TestValidate(t *testing.T) {
}

func Test_Generate(t *testing.T) {
for i := 0; i < 10; i++ {
for range 10 {
bik := Generate()
isValid, err := Validate(bik)
require.NoError(t, err, fmt.Sprintf("invalid bik value: %s", bik))
Expand All @@ -119,12 +115,12 @@ func Test_Exists(t *testing.T) {
}

func BenchmarkValidateCorrect(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_, _ = Validate("044525225")
}
}
func BenchmarkGenerate(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
Generate()
}
}
3 changes: 3 additions & 0 deletions fts/tax_departs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,9 @@ var SupportedTaxDepartments = map[ConstitutionRegionCode]TaxDepart{
func init() {
supportedRegionsCodes = make([]ConstitutionRegionCode, 0, len(SupportedTaxDepartments))
for region := range SupportedTaxDepartments {
if _, ok := SupportedRegionsCodes[region]; !ok {
continue
}
supportedRegionsCodes = append(supportedRegionsCodes, region)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/sshaplygin/docs-code

go 1.21
go 1.25

require github.com/stretchr/testify v1.8.4

Expand Down
4 changes: 2 additions & 2 deletions inn/inn.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ func Validate(inn string) (bool, error) {

// Generate generate random type inn string value
func Generate() string {
return NewINN(INNType(utils.RandomDigits(1) % 3)).String()
return NewINN(_supportedTypes[utils.Random(0, len(_supportedTypes)-1)]).String()
}

// GenerateLegal generate legal type inn string value
func GenerateLegal() string {
return NewINN(INNType(utils.RandomDigits(1)%2 + 1)).String()
return NewINN(_supportedTypes[utils.Random(0, len(_supportedTypes)-1)]).String()
}

// GeneratePhysical generate physical type inn string value
Expand Down
20 changes: 8 additions & 12 deletions inn/inn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ func TestValidate(t *testing.T) {
},
}
for i, tc := range testCases {
tc := tc

isValid, err := Validate(tc.Code)
assert.Equal(t, tc.IsValid, isValid, tc.Code)
if err != nil {
Expand Down Expand Up @@ -83,8 +81,6 @@ func TestValidate(t *testing.T) {
},
}
for i, tc := range testCases {
tc := tc

isValid, err := Validate(tc.Code)
assert.Equal(t, tc.IsValid, isValid, tc.Code)
if err != nil {
Expand All @@ -102,7 +98,7 @@ func TestGenerate(t *testing.T) {
t.Run("generate legal inn", func(t *testing.T) {
var inn string

for i := 0; i < 10; i++ {
for range 10 {
inn = GenerateLegal()
isValid, err := Validate(inn)
require.NoError(t, err, inn)
Expand All @@ -114,7 +110,7 @@ func TestGenerate(t *testing.T) {
t.Run("generate physical inn", func(t *testing.T) {
var inn string

for i := 0; i < 10; i++ {
for range 10 {
inn = GeneratePhysical()
isValid, err := Validate(inn)
require.NoError(t, err, inn)
Expand All @@ -126,7 +122,7 @@ func TestGenerate(t *testing.T) {
t.Run("generate random inn", func(t *testing.T) {
var inn string

for i := 0; i < 10; i++ {
for range 10 {
inn = Generate()
isValid, err := Validate(inn)
require.NoError(t, err, inn)
Expand All @@ -137,31 +133,31 @@ func TestGenerate(t *testing.T) {
}

func BenchmarkValidateCorrectLegal(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_, _ = Validate("7707083893")
}
}

func BenchmarkValidateCorrectPhysical(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_, _ = Validate("526317984689")
}
}

func BenchmarkGenerate(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
Generate()
}
}

func BenchmarkGenerateLegal(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
GenerateLegal()
}
}

func BenchmarkGeneratePhysical(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
GeneratePhysical()
}
}
7 changes: 7 additions & 0 deletions inn/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const (
ForeignLegal
)

var _supportedTypes = []INNType{
Physical,
Legal,
ForeignLegal,
}

type SerialNumber struct {
val int
len int
Expand Down Expand Up @@ -124,6 +130,7 @@ func NewINN(innType INNType) *INNStruct {
taxRegionCode: taxRegionCode,
serialNumber: serialNumber,
checkSums: GenerateCheckSums(innType, append(taxRegionCode.Ints(), serialNumber.Ints()...)),
t: innType,
}
}

Expand Down
Loading
Loading