https://github.com/mdempsky/unconvert
Remove unnecessary type conversions from Go source
https://github.com/mdempsky/unconvert
Last synced: 9 months ago
JSON representation
Remove unnecessary type conversions from Go source
- Host: GitHub
- URL: https://github.com/mdempsky/unconvert
- Owner: mdempsky
- License: bsd-3-clause
- Created: 2016-02-19T21:59:07.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-09-07T12:55:36.000Z (over 2 years ago)
- Last Synced: 2024-10-14T11:52:56.992Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 71.3 KB
- Stars: 377
- Watchers: 12
- Forks: 26
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go-zh - unconvert
- awesome-go - unconvert - Remove unnecessary type conversions from Go source. (Code Analysis / Routers)
- awesome-go - unconvert - Remove unnecessary type conversions from Go source - ★ 226 (Code Analysis)
- awesome-go-plus - unconvert - Remove unnecessary type conversions from Go source.  (Code Analysis / Routers)
- awesome-go-cn - unconvert
- awesome-go - unconvert - | - | - | (Code Analysis / Routers)
- awesome-go - unconvert - Remove unnecessary type conversions from Go source. (Code Analysis / Routers)
- awesome-go - unconvert - Remove unnecessary type conversions from Go source. (Code Analysis / Routers)
- awesome-go - unconvert - Remove unnecessary type conversions from Go source. - :arrow_down:0 - :star:152 (Code Analysis / Routers)
- awesome-go-with-stars - unconvert - 02-16 | (Code Analysis / Routers)
- awesome-go - unconvert - Remove unnecessary type conversions from Go source. (Code Analysis / Routers)
- awesome-Char - unconvert - Remove unnecessary type conversions from Go source. (Code Analysis / Routers)
- awesome-go - unconvert - Remove unnecessary type conversions from Go source. (Code Analysis / Routers)
- fucking-static-analysis - unconvert
- awesome-go-cn - unconvert
- awesome-go-extra - unconvert - 02-19T21:59:07Z|2022-06-16T12:45:53Z| (Code Analysis / Routers)
- fucking-awesome-go - unconvert - Remove unnecessary type conversions from Go source. (Code Analysis / Routers)
- static-analysis - unconvert
- awesome-go-cn - unconvert
- awesome-go - unconvert - Remove unnecessary type conversions from Go source. (Code Analysis / Routers)
- awesome-go-cn - unconvert
- awesome-go - unconvert - Remove unnecessary type conversions from Go source. (Code Analysis / Routers)
- awesome-go - mdempsky/unconvert
- awesome-go - unconvert - Remove unnecessary type conversions from Go source. (Code Analysis / Routers)
README
# About
The unconvert program analyzes Go packages to identify unnecessary
type conversions; i.e., expressions T(x) where x already has type T.
# Install
go install github.com/mdempsky/unconvert@latest
# Usage
$ unconvert -v bytes fmt
GOROOT/src/bytes/reader.go:117:14: unnecessary conversion
abs = int64(r.i) + offset
^
GOROOT/src/fmt/print.go:411:21: unnecessary conversion
p.fmt.integer(int64(v), 16, unsigned, udigits)
^
# Flags
Using the -v flag, unconvert will also print the source line and a
caret to indicate the unnecessary conversion's position therein.
Using the -apply flag, unconvert will rewrite the Go source files
without the unnecessary type conversions.
Using the -all flag, unconvert will analyze the Go packages under all
possible GOOS/GOARCH combinations, and only identify conversions that
are unnecessary in all cases.
E.g., syscall.Timespec's Sec and Nsec fields are int64 under
linux/amd64 but int32 under linux/386. An int64(ts.Sec) conversion
that appears in a linux/amd64-only file will be identified as
unnecessary, but it will be preserved if it occurs in a file that's
compiled for both linux/amd64 and linux/386.