Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Productionization #1

Merged
merged 9 commits into from
Oct 18, 2023
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
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI

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

jobs:
main:
runs-on: ubuntu-latest
env:
GO_VERSION: '1.20'
Antonboom marked this conversation as resolved.
Show resolved Hide resolved
GOLANGCI_LINT_VERSION: 1.54.2
CGO_ENABLED: 0
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
go-version: ^${{ env.GO_VERSION }}

- name: Checkout code
uses: actions/checkout@v3

- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Check and get dependencies
run: |
go mod tidy
git diff --exit-code go.mod
git diff --exit-code go.sum
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}

- name: Make
run: make
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.PHONY: fmt tidy lint test bench install

default: fmt tidy lint test install

fmt:
go fmt ./...

tidy:
go mod tidy

lint:
golangci-lint run

test:
go test ./...

bench:
go test -bench=Bench ./...

install:
go install .
gostrconv -h 2>&1 | head -n1
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
# gostrconv
Gostrconv: Golang linter for performance, aiming at usages of `fmt.Sprintf` which have faster alternatives.

# Usage
[![CI](https://github.com/catenacyber/gostrconv/actions/workflows/ci.yml/badge.svg)](https://github.com/catenacyber/gostrconv/actions/workflows/ci.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/catenacyber/gostrconv)](https://goreportcard.com/report/github.com/catenacyber/gostrconv?dummy=unused)

./gostrconv file.go
Golang linter for performance, aiming at usages of `fmt.Sprintf` which have faster alternatives.

Rewrites `fmt.Sprintf("%d",` into faster `strconv.Itoa` and such
## Installation

```sh
go get github.com/catenacyber/gostrconv@latest
```

## Usage

```sh
gostrconv --fix ./...
```

### Replacements

```
fmt.Sprintf("%s", strVal) -> strVal
fmt.Sprintf("%t", boolVal) -> strconv.FormatBool(boolBal)
fmt.Sprintf("%x", hash) -> hex.EncodeToString(hash)
fmt.Sprintf("%d", id) -> strconv.Itoa(id)
fmt.Sprintf("%v", version) -> strconv.FormatUint(uint64(version), 10)
```

More in [tests](./analyzer/testdata/src/p/p.go).
Loading