-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: added separate list of methods & update readme
- Loading branch information
Showing
2 changed files
with
195 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<table><tr> | ||
<td><nobr><code>func (b *bufio.Writer) Write(p []byte) (int, error)</code></nobr></td> | ||
<td><nobr><code>func (b *bufio.Writer) WriteString(s string) (int, error)</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func (b *bytes.Buffer) Write(p []byte) (int, error)</code></nobr></td> | ||
<td><nobr><code>func (b *bytes.Buffer) WriteString(s string) (int, error)</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.Compare(a, b []byte) int</code></nobr></td> | ||
<td><nobr><code>func strings.Compare(a, b string) int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.Contains(b, subslice []byte) bool</code></nobr></td> | ||
<td><nobr><code>func strings.Contains(s, substr string) bool</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.ContainsAny(b []byte, chars string) bool</code></nobr></td> | ||
<td><nobr><code>func strings.ContainsAny(s, chars string) bool</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.ContainsRune(b []byte, r rune) bool</code></nobr></td> | ||
<td><nobr><code>func strings.ContainsRune(s string, r rune) bool</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.Count(s, sep []byte) int</code></nobr></td> | ||
<td><nobr><code>func strings.Count(s, substr string) int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.EqualFold(s, t []byte) bool</code></nobr></td> | ||
<td><nobr><code>func strings.EqualFold(s, t string) bool</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.HasPrefix(s, prefix []byte) bool</code></nobr></td> | ||
<td><nobr><code>func strings.HasPrefix(s, prefix string) bool</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.HasSuffix(s, suffix []byte) bool</code></nobr></td> | ||
<td><nobr><code>func strings.HasSuffix(s, suffix string) bool</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.Index(s, sep []byte) int</code></nobr></td> | ||
<td><nobr><code>func strings.Index(s, substr string) int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.IndexAny(s []byte, chars string) int</code></nobr></td> | ||
<td><nobr><code>func strings.IndexAny(s, chars string) int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.IndexByte(b []byte, c byte) int</code></nobr></td> | ||
<td><nobr><code>func strings.IndexByte(s string, c byte) int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.IndexFunc(s []byte, f func(r rune) bool) int</code></nobr></td> | ||
<td><nobr><code>func strings.IndexFunc(s string, f func(rune) bool) int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.IndexRune(s []byte, r rune) int</code></nobr></td> | ||
<td><nobr><code>func strings.IndexRune(s string, r rune) int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.LastIndex(s, sep []byte) int</code></nobr></td> | ||
<td><nobr><code>func strings.LastIndex(s, sep string) int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.LastIndexAny(s []byte, chars string) int</code></nobr></td> | ||
<td><nobr><code>func strings.LastIndexAny(s, chars string) int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.LastIndexByte(s []byte, c byte) int</code></nobr></td> | ||
<td><nobr><code>func strings.LastIndexByte(s string, c byte) int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func bytes.LastIndexFunc(s []byte, f func(r rune) bool) int</code></nobr></td> | ||
<td><nobr><code>func strings.LastIndexFunc(s string, f func(rune) bool) int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>bytes.NewBufferString</code></nobr></td> | ||
<td><nobr><code>bytes.NewBuffer</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func (h *hash/maphash.Hash) Write(b []byte) (int, error)</code></nobr></td> | ||
<td><nobr><code>func (h *hash/maphash.Hash) WriteString(s string) (int, error)</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func (rw *net/http/httptest.ResponseRecorder) Write(buf []byte) (int, error)</code></nobr></td> | ||
<td><nobr><code>func (rw *net/http/httptest.ResponseRecorder) WriteString(str string) (int, error)</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func (f *os.File) Write(b []byte) (n int, err error)</code></nobr></td> | ||
<td><nobr><code>func (f *os.File) WriteString(s string) (n int, err error)</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func regexp.Match(pattern string, b []byte) (bool, error)</code></nobr></td> | ||
<td><nobr><code>func regexp.MatchString(pattern string, s string) (bool, error)</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func (re *regexp.Regexp) FindAllIndex(b []byte, n int) [][]int</code></nobr></td> | ||
<td><nobr><code>func (re *regexp.Regexp) FindAllStringIndex(s string, n int) [][]int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func (re *regexp.Regexp) FindAllSubmatch(b []byte, n int) [][][]byte</code></nobr></td> | ||
<td><nobr><code>func (re *regexp.Regexp) FindAllStringSubmatch(s string, n int) [][]string</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func (re *regexp.Regexp) FindIndex(b []byte) (loc []int)</code></nobr></td> | ||
<td><nobr><code>func (re *regexp.Regexp) FindStringIndex(s string) (loc []int)</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func (re *regexp.Regexp) FindSubmatchIndex(b []byte) []int</code></nobr></td> | ||
<td><nobr><code>func (re *regexp.Regexp) FindStringSubmatchIndex(s string) []int</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func (re *regexp.Regexp) Match(b []byte) bool</code></nobr></td> | ||
<td><nobr><code>func (re *regexp.Regexp) MatchString(s string) bool</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func (b *strings.Builder) Write(p []byte) (int, error)</code></nobr></td> | ||
<td><nobr><code>func (b *strings.Builder) WriteByte(c byte) error</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func utf8.Valid(p []byte) bool</code></nobr></td> | ||
<td><nobr><code>func utf8.ValidString(s string) bool</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func utf8.FullRune(p []byte) bool</code></nobr></td> | ||
<td><nobr><code>func utf8.FullRuneInString(s string) bool</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func utf8.RuneCount(p []byte) int</code></nobr></td> | ||
<td><nobr><code>func utf8.RuneCountInString(s string) (n int)</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func utf8.DecodeLastRune(p []byte) (rune, int)</code></nobr></td> | ||
<td><nobr><code>func utf8.DecodeLastRuneInString(s string) (rune, int)</code></nobr></td> | ||
</tr> | ||
<tr> | ||
<td><nobr><code>func utf8.DecodeRune(p []byte) (rune, int)</code></nobr></td> | ||
<td><nobr><code>func utf8.DecodeRuneInString(s string) (une, int)</code></nobr></td> | ||
</tr> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,171 +1,76 @@ | ||
# `mirror` [![Code Coverage](https://coveralls.io/repos/github/butuzov/mirror/badge.svg?branch=main)](https://coveralls.io/github/butuzov/mirror?branch=main) [![build status](https://github.com/butuzov/mirror/actions/workflows/main.yaml/badge.svg?branch=main)]() | ||
|
||
`mirror` help to suggest use of alternative methods, in order to avoid additional convertion of `[]byte`/`string`. | ||
`mirror` suggests use of alternative functions/methods in order to gain performance boosts by avoiding unnecessary `[]byte/string` convertion calls. See [MIRROR_FUNCS.md](MIRROR_FUNCS.md) list of mirror functions you can use in go's stdlib. | ||
|
||
## 🇺🇦 PLEASE HELP ME 🇺🇦 | ||
Fundrise for scout drone **DJI Matrice 30T** See more details at [butuzov/README.md](https://github.com/butuzov/butuzov/) | ||
Fundrise for scout drone **DJI Matrice 30T** for my squad (Ukrainian Forces). See more details at [butuzov/README.md](https://github.com/butuzov/butuzov/) | ||
|
||
## Examples | ||
## Linter Use Cases | ||
|
||
<table> | ||
<thead><tr><th>Bad</th><th>Good</th></tr></thead> | ||
<tbody> | ||
<tr><td> | ||
### `github.com/argoproj/argo-cd` | ||
|
||
```go | ||
regexp.Match("foo", []byte("foobar1")) | ||
// Before | ||
func IsValidHostname(hostname string, fqdn bool) bool { | ||
if !fqdn { | ||
return validHostNameRegexp.Match([]byte(hostname)) || validIPv6Regexp.Match([]byte(hostname)) | ||
} else { | ||
return validFQDNRegexp.Match([]byte(hostname)) | ||
} | ||
} | ||
|
||
// After: With alternative method (and lost `else` case) | ||
func IsValidHostname(hostname string, fqdn bool) bool { | ||
if !fqdn { | ||
return validHostNameRegexp.MatchString(hostname) || validIPv6Regexp.MatchString(hostname) | ||
} | ||
|
||
return validFQDNRegexp.MatchString(hostname) | ||
} | ||
``` | ||
|
||
</td><td> | ||
## Install | ||
|
||
```go | ||
regexp.MatchString("foo", "foobar1") | ||
``` | ||
go install github.com/butuzov/mirrror/cmd/mirror@latest | ||
``` | ||
|
||
</td></tr> | ||
</tbody></table> | ||
|
||
## Supported Checks | ||
<table><tr> | ||
<td><code>func (b *bufio.Writer) Write(p []byte) (int, error)</code></td> | ||
<td><code>func (b *bufio.Writer) WriteString(s string) (int, error)</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func (b *bytes.Buffer) Write(p []byte) (int, error)</code></td> | ||
<td><code>func (b *bytes.Buffer) WriteString(s string) (int, error)</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.Compare(a, b []byte) int</code></td> | ||
<td><code>func strings.Compare(a, b string) int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.Contains(b, subslice []byte) bool</code></td> | ||
<td><code>func strings.Contains(s, substr string) bool</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.ContainsAny(b []byte, chars string) bool</code></td> | ||
<td><code>func strings.ContainsAny(s, chars string) bool</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.ContainsRune(b []byte, r rune) bool</code></td> | ||
<td><code>func strings.ContainsRune(s string, r rune) bool</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.Count(s, sep []byte) int</code></td> | ||
<td><code>func strings.Count(s, substr string) int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.EqualFold(s, t []byte) bool</code></td> | ||
<td><code>func strings.EqualFold(s, t string) bool</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.HasPrefix(s, prefix []byte) bool</code></td> | ||
<td><code>func strings.HasPrefix(s, prefix string) bool</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.HasSuffix(s, suffix []byte) bool</code></td> | ||
<td><code>func strings.HasSuffix(s, suffix string) bool</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.Index(s, sep []byte) int</code></td> | ||
<td><code>func strings.Index(s, substr string) int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.IndexAny(s []byte, chars string) int</code></td> | ||
<td><code>func strings.IndexAny(s, chars string) int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.IndexByte(b []byte, c byte) int</code></td> | ||
<td><code>func strings.IndexByte(s string, c byte) int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.IndexFunc(s []byte, f func(r rune) bool) int</code></td> | ||
<td><code>func strings.IndexFunc(s string, f func(rune) bool) int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.IndexRune(s []byte, r rune) int</code></td> | ||
<td><code>func strings.IndexRune(s string, r rune) int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.LastIndex(s, sep []byte) int</code></td> | ||
<td><code>func strings.LastIndex(s, sep string) int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.LastIndexAny(s []byte, chars string) int</code></td> | ||
<td><code>func strings.LastIndexAny(s, chars string) int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.LastIndexByte(s []byte, c byte) int</code></td> | ||
<td><code>func strings.LastIndexByte(s string, c byte) int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func bytes.LastIndexFunc(s []byte, f func(r rune) bool) int</code></td> | ||
<td><code>func strings.LastIndexFunc(s string, f func(rune) bool) int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>bytes.NewBufferString</code></td> | ||
<td><code>bytes.NewBuffer</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func (h *maphash.Hash) Write(b []byte) (int, error)</code></td> | ||
<td><code>func (h *maphash.Hash) WriteString(s string) (int, error)</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func (rw *httptest.ResponseRecorder) Write(buf []byte) (int, error)</code></td> | ||
<td><code>func (rw *httptest.ResponseRecorder) WriteString(str string) (int, error)</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func (f *os.File) Write(b []byte) (n int, err error)</code></td> | ||
<td><code>func (f *os.File) WriteString(s string) (n int, err error)</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func regexp.Match(pattern string, b []byte) (bool, error)</code></td> | ||
<td><code>func regexp.MatchString(pattern string, s string) (bool, error)</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func (re *regexp.Regexp) FindAllIndex(b []byte, n int) [][]int</code></td> | ||
<td><code>func (re *regexp.Regexp) FindAllStringIndex(s string, n int) [][]int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func (re *regexp.Regexp) FindAllSubmatch(b []byte, n int) [][][]byte</code></td> | ||
<td><code>func (re *regexp.Regexp) FindAllStringSubmatch(s string, n int) [][]string</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func (re *regexp.Regexp) FindIndex(b []byte) (loc []int)</code></td> | ||
<td><code>func (re *regexp.Regexp) FindStringIndex(s string) (loc []int)</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func (re *regexp.Regexp) FindSubmatchIndex(b []byte) []int</code></td> | ||
<td><code>func (re *regexp.Regexp) FindStringSubmatchIndex(s string) []int</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func (re *regexp.Regexp) Match(b []byte) bool</code></td> | ||
<td><code>func (re *regexp.Regexp) MatchString(s string) bool</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func (b *strings.Builder) Write(p []byte) (int, error)</code></td> | ||
<td><code>func (b *strings.Builder) WriteByte(c byte) error</code></td> | ||
</tr> | ||
<tr> | ||
<td><code>func utf8.Valid(p []byte) bool</code></td> | ||
<td><code>func utf8.ValidString(s string) bool</code></td> | ||
</tr> | ||
</table> | ||
Or with [`golangci-lint`](https://github.com/golangci/golangci-lint/issue/NNNNN) | ||
|
||
## Install | ||
|
||
### Compile From Source | ||
## How to use | ||
|
||
You can get `mirror` with `go install` command. | ||
You run `mirror` with [`go vet`](https://pkg.go.dev/cmd/vet): | ||
|
||
``` | ||
go vet -vettool=$(which mirror) ./... | ||
# github.com/jcmoraisjr/haproxy-ingress/pkg/common/net/ssl | ||
pkg/common/net/ssl/ssl.go:64:11: avoid allocations with (*os.File).WriteString | ||
pkg/common/net/ssl/ssl.go:161:12: avoid allocations with (*os.File).WriteString | ||
pkg/common/net/ssl/ssl.go:166:3: avoid allocations with (*os.File).WriteString | ||
``` | ||
|
||
```shell | ||
go install github.com/butuzov/mirror/cmd/mirror@latest | ||
Can be called directly: | ||
``` | ||
mirror ./... | ||
# https://github.com/cosmtrek/air | ||
/air/runner/util.go:149:6: avoid allocations with (*regexp.Regexp).MatchString | ||
/air/runner/util.go:173:14: avoid allocations with (*os.File).WriteString | ||
``` | ||
|
||
## Usage | ||
With [`golangci-lint`](https://github.com/golangci/golangci-lint) | ||
|
||
```shell | ||
# include test files reports | ||
mirror --with-tests ./... | ||
``` | ||
// TODO | ||
``` | ||
|
||
|
||
## Command line | ||
|
||
- You can add checks for `_test.go` files with cli option `--with-tests` | ||
|
||
### `golangci-lint` | ||
|
||
```yaml | ||
# TODO: add mirror to golangci-ling | ||
``` |