Skip to content

Commit

Permalink
Use strings.ReplaceAll() rather than strings.Replace() with -1
Browse files Browse the repository at this point in the history
Also, added a pre-commit hook. To install it:

go install github.com/go-critic/go-critic/cmd/gocritic@latest
go install golang.org/x/tools/cmd/goimports@latest
go install golang.org/x/lint/golint@latest
go install github.com/gordonklaus/ineffassign@latest
pip install pre-commit
pre-commit install

It will then run on every `git commit` invocation. To run manually on
all files:

pre-commit run --all-files
  • Loading branch information
jessp01 committed Nov 1, 2023
1 parent 95e16f2 commit 8bc6897
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
repos:
- repo: https://github.com/jessp01/pre-commit-golang.git
rev: v0.5.9
hooks:
- id: go-fmt
- id: go-imports
- id: go-vet
- id: go-lint
- id: go-critic
- id: go-ineffassign
- id: shellcheck
10 changes: 5 additions & 5 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,11 @@ func getMetricType(metricType string, metricsType map[string]string) prometheus.
}

func cleanName(s string) string {
s = strings.Replace(s, " ", "_", -1) // Remove spaces
s = strings.Replace(s, "(", "", -1) // Remove open parenthesis
s = strings.Replace(s, ")", "", -1) // Remove close parenthesis
s = strings.Replace(s, "/", "", -1) // Remove forward slashes
s = strings.Replace(s, "*", "", -1) // Remove asterisks
s = strings.ReplaceAll(s, " ", "_") // Remove spaces
s = strings.ReplaceAll(s, "(", "") // Remove open parenthesis
s = strings.ReplaceAll(s, ")", "") // Remove close parenthesis
s = strings.ReplaceAll(s, "/", "") // Remove forward slashes
s = strings.ReplaceAll(s, "*", "") // Remove asterisks
s = strings.ToLower(s)
return s
}
Expand Down

0 comments on commit 8bc6897

Please sign in to comment.