Skip to content

Commit e28678e

Browse files
committed
Merge branch 'release/v1.6.1'
2 parents cb9c72e + 45bad60 commit e28678e

File tree

5 files changed

+156
-20
lines changed

5 files changed

+156
-20
lines changed

.github/workflows/ci.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Go CI
2+
3+
on:
4+
pull_request:
5+
branches: [develop, master]
6+
push:
7+
branches: [develop, master]
8+
9+
jobs:
10+
build-linux:
11+
name: Build stringFormatter on linux
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/[email protected]
15+
- name: Set up Go
16+
uses: actions/[email protected]
17+
with:
18+
go-version: '1.21'
19+
- name: Build
20+
run: go version && go build -v ./...
21+
22+
build-windows:
23+
name: Build stringFormatter on windows
24+
runs-on: windows-latest
25+
steps:
26+
- uses: actions/[email protected]
27+
- name: Set up Go
28+
uses: actions/[email protected]
29+
with:
30+
go-version: '1.21'
31+
- name: Build
32+
run: go version && go build -v ./...
33+
34+
all-tests-linux:
35+
name: Run all tests on linux
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/[email protected]
39+
- name: Set up Go
40+
uses: actions/[email protected]
41+
with:
42+
go-version: '1.21'
43+
- name: Test all
44+
run: go version && go mod tidy && go test -v ./...
45+
46+
#all-tests-windows:
47+
# name: Run all tests on windows
48+
# runs-on: windows-latest
49+
# steps:
50+
# - uses: actions/[email protected]
51+
# - name: Set up Go
52+
# uses: actions/[email protected]
53+
# - name: Test all
54+
# run: go test -v ./...
55+
# on windows don't work linux containers by default
56+
57+
lint:
58+
name: Run golangci linters
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/[email protected]
62+
- name: Set up Go
63+
uses: actions/[email protected]
64+
with:
65+
go-version: '1.21'
66+
- name: Run golangci-lint
67+
uses: golangci/[email protected]
68+
with:
69+
version: v1.63.4
70+
args: --timeout 3m --config .golangci.yaml

.golangci.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
run:
2+
# timeout for analysis, e.g. 30s, 5m, default is 1m
3+
timeout: 30m
4+
5+
modules-download-mode: readonly
6+
7+
go: '1.21'
8+
9+
output:
10+
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
11+
# default is "colored-line-number"
12+
formats: code-climate
13+
14+
linters:
15+
enable-all: false
16+
disable:
17+
- exhaustruct
18+
- gofumpt
19+
- testpackage
20+
- depguard
21+
- tagliatelle
22+
- ireturn
23+
- varnamelen
24+
- wrapcheck
25+
26+
linters-settings:
27+
stylecheck:
28+
# Select the Go version to target. The default is '1.13'.
29+
# https://staticcheck.io/docs/options#checks
30+
checks: [ "all", "-ST1000" ]
31+
funlen:
32+
lines: 100
33+
gci:
34+
sections:
35+
- standard
36+
- default
37+
- prefix(github.com/wissance/stringFormatter)
38+
gocyclo:
39+
min-complexity: 5
40+
varnamelen:
41+
ignore-names:
42+
- id
43+
ignore-decls:
44+
- ok bool
45+
wrapcheck:
46+
ignorePackageGlobs:
47+
- google.golang.org/grpc/status
48+
- github.com/pkg/errors
49+
- golang.org/x/sync/errgroup
50+
gosec:
51+
excludes:
52+
- G204
53+
54+
issues:
55+
exclude-rules:
56+
- path: _test\.go
57+
linters:
58+
- containedctx
59+
- gocyclo
60+
- cyclop
61+
- funlen
62+
- goerr113
63+
- varnamelen
64+
- staticcheck
65+
- maintidx
66+
- lll
67+
- paralleltest
68+
- dupl
69+
- typecheck
70+
- wsl
71+
- govet
72+
- path: main\.go
73+
linters:
74+
- gochecknoglobals
75+
- lll
76+
- funlen
77+
version: 2

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/wissance/stringFormatter?style=plastic)
99
![GitHub issues](https://img.shields.io/github/issues/wissance/stringFormatter?style=plastic)
1010
![GitHub Release Date](https://img.shields.io/github/release-date/wissance/stringFormatter)
11-
![GitHub release (latest by date)](https://img.shields.io/github/downloads/wissance/stringFormatter/v1.6.0/total?style=plastic)
11+
![GitHub release (latest by date)](https://img.shields.io/github/downloads/wissance/stringFormatter/v1.6.1/total?style=plastic)
1212

1313
![String Formatter: a convenient string formatting tool](img/sf_cover.png)
1414

@@ -20,6 +20,7 @@
2020
- convert ***map to string*** using one of predefined formats (see `text_utils.go`)
2121
3. Code Style formatting utilities
2222
- convert `snake`/`kebab`/`camel` programming code to each other and vice versa (see `stringstyle_formatter.go`).
23+
4. `StringFormatter` aka `sf` **is safe** (`SAST` and tests were running automatically on push)
2324

2425
### 1. Text formatting from templates
2526

formatter.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func Format(template string, args ...any) string {
157157
// 2.2 Segment formatting
158158
if !isEven {
159159
j += repeatingOpenBrackets - 1
160-
argNumber := -1
160+
var argNumber int
161161
var err error
162162
var argFormatOptions string
163163
if len(argNumberStr) == 1 {
@@ -185,9 +185,6 @@ func Format(template string, args ...any) string {
185185
}
186186
if argNumber < 0 {
187187
argNumber, err = strconv.Atoi(argNumberStr)
188-
if err == nil {
189-
//rawWrite = false
190-
}
191188
}
192189
}
193190

@@ -410,7 +407,7 @@ func FormatComplex(template string, args map[string]any) string {
410407

411408
arg, ok = args[argKey]
412409
}
413-
if ok || (argFormatOptions != "" && !!repeatingOpenBracketsCollected) {
410+
if ok || argFormatOptions != "" {
414411
// get number from placeholder
415412
strVal := ""
416413
if arg != nil {
@@ -542,13 +539,12 @@ func getItemAsStr(item *any, itemFormat *string) string {
542539
dividerVal, err := strconv.ParseFloat(dividerStr, 32)
543540
if err == nil {
544541
// 1. Convert arg to float
545-
val := (*item).(interface{})
546542
var floatVal float64
547-
switch val.(type) {
543+
switch (*item).(type) {
548544
case float64:
549-
floatVal = val.(float64)
545+
floatVal = (*item).(float64)
550546
case int:
551-
floatVal = float64(val.(int))
547+
floatVal = float64((*item).(int))
552548
default:
553549
floatVal = 0
554550
}
@@ -566,10 +562,11 @@ func getItemAsStr(item *any, itemFormat *string) string {
566562

567563
// slice processing converting to {item}{delimiter}{item}{delimiter}{item}
568564
slice, ok := (*item).([]any)
565+
//nolint:ineffassign
569566
if ok {
570567
if len(slice) == 1 {
571568
// this is because slice in 0 item contains another slice, we should take it
572-
slice, ok = slice[0].([]any)
569+
slice, _ = slice[0].([]any)
573570
}
574571
return SliceToString(&slice, &separator)
575572
} else {

stringstyle_formatter.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ func SetStyle(text *string, style FormattingStyle, firstSymbol CaseSetting, text
6868
switch style {
6969
case Kebab:
7070
sb.WriteString("-")
71-
break
7271
case Snake:
7372
sb.WriteString("_")
74-
break
7573
case Camel:
7674
// in case of convert to Camel we should skip v.Index (because it is _ or -)
7775
if v.Style == Camel {
@@ -80,7 +78,6 @@ func SetStyle(text *string, style FormattingStyle, firstSymbol CaseSetting, text
8078
sb.WriteRune(unicode.ToUpper(rune((*text)[endIndex+1])))
8179
}
8280
startIndex += 1
83-
break
8481
}
8582
if v.Style != Camel {
8683
startIndex += 1
@@ -92,13 +89,10 @@ func SetStyle(text *string, style FormattingStyle, firstSymbol CaseSetting, text
9289
switch textCase {
9390
case ToUpper:
9491
result.WriteString(strings.ToUpper(sb.String()[1:]))
95-
break
9692
case ToLower:
9793
result.WriteString(strings.ToLower(sb.String()[1:]))
98-
break
9994
case NoChanges:
10095
result.WriteString(sb.String()[1:])
101-
break
10296
}
10397
} else {
10498
result.WriteString(sb.String()[1:])
@@ -128,13 +122,10 @@ func GetFormattingStyleOptions(style string) (FormattingStyle, CaseSetting, Case
128122
switch styleLower {
129123
case string(Camel):
130124
formattingStyle = Camel
131-
break
132125
case string(Snake):
133126
formattingStyle = Snake
134-
break
135127
case string(Kebab):
136128
formattingStyle = Kebab
137-
break
138129
}
139130

140131
runes := []rune(style)

0 commit comments

Comments
 (0)