-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9b908be
Showing
18 changed files
with
1,104 additions
and
0 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,3 @@ | ||
liberapay: gavv | ||
custom: | ||
- "https://www.paypal.me/victorgaydov" |
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,36 @@ | ||
name: build | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
push: | ||
branches: | ||
- main | ||
tags: | ||
- v* | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
go: [1.18, 1.x] | ||
|
||
name: Go ${{ matrix.go }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
|
||
- name: Build | ||
run: make build | ||
|
||
- name: Run tests | ||
run: make test |
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 @@ | ||
returnstyles |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Victor Gaydov and contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,15 @@ | ||
all: tidy build test | ||
|
||
tidy: | ||
go mod tidy -v | ||
|
||
build: | ||
go build . | ||
go build -o returnstyles ./cmd | ||
|
||
test: | ||
ifneq ($(shell which gotest),) | ||
gotest -v . | ||
else | ||
go test -v . | ||
endif |
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,137 @@ | ||
# returnstyles [![GoDev](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/gavv/returnstyles) [![Build](https://github.com/gavv/returnstyles/workflows/build/badge.svg)](https://github.com/gavv/returnstyles/actions) [![GitHub release](https://img.shields.io/github/tag/gavv/returnstyles.svg)](https://github.com/gavv/returnstyles/releases) | ||
|
||
Go (golang) linter to check function return styles according to rules of your choice. | ||
|
||
## Install | ||
|
||
``` | ||
go install -v github.com/gavv/returnstyles/cmd@latest | ||
``` | ||
|
||
## Usage | ||
|
||
``` | ||
returnstyles [options] <package> | ||
``` | ||
|
||
For example: | ||
|
||
``` | ||
returnstyles -allow-naked-returns=false . | ||
``` | ||
|
||
## Options | ||
|
||
| option | default | description | | ||
|--------------------------|---------|---------------------------------------------------------------------------| | ||
| `-allow-unnamed` | true | allow functions with unnamed return variables | | ||
| `-allow-named` | true | allow functions with named return variables | | ||
| `-allow-partially-named` | false | allow functions with partially named return variables | | ||
| `-allow-normal-returns` | true | allow normal (non-naked) returns in functions with named return variables | | ||
| `-allow-naked-returns` | true | allow naked returns in functions with named return variables | | ||
| `-allow-mixing-returns` | false | allow mixing normal and naked in functions with named return variables | | ||
|
||
## Config | ||
|
||
Instead of specifying individual command-line options, you can provide a single configuration file in YAML format: | ||
|
||
``` | ||
returnstyles -config path/to/config.yaml <package> | ||
``` | ||
|
||
It should have the following format: | ||
|
||
```yaml | ||
returnstyles: | ||
allow-unnamed: true | ||
allow-named: true | ||
allow-partially-named: false | ||
allow-normal-returns: true | ||
allow-naked-returns: true | ||
allow-mixing-returns: false | ||
``` | ||
|
||
## Package | ||
|
||
```go | ||
import "github.com/gavv/returnstyles" | ||
``` | ||
|
||
Global variable `returnstyles.Analyzer` follows guidelines in the [golang.org/x/tools/go/analysis](https://pkg.go.dev/golang.org/x/tools/go/analysis) package. | ||
|
||
## Samples | ||
|
||
#### `-allow-unnamed=false` | ||
|
||
```go | ||
func foo() (int, int) { // lint: functions with unnamed return variables not allowed | ||
return 11, 22 | ||
} | ||
``` | ||
|
||
#### `-allow-named=false` | ||
|
||
```go | ||
func foo() (a int, b int) { // lint: functions with named return variables not allowed | ||
return 11, 22 | ||
} | ||
``` | ||
|
||
#### `-allow-partially-named=false` | ||
|
||
```go | ||
func foo() (int, b int) { // lint: functions with partially named return variables not allowed | ||
return 11, 22 | ||
} | ||
``` | ||
|
||
#### `-allow-normal-returns=false` | ||
|
||
```go | ||
func foo() (a int, b int) { | ||
return 11, 22 // lint: normal (non-naked) returns not allowed | ||
// in functions with named return variables | ||
} | ||
``` | ||
|
||
#### `-allow-naked-returns=false` | ||
|
||
```go | ||
func foo() (a int, b int) { | ||
a = 11 | ||
b = 22 | ||
return // lint: naked returns not allowed | ||
} | ||
``` | ||
|
||
#### `-allow-mixing-returns=false` | ||
|
||
```go | ||
func foo() (a int, b int) { | ||
if cond() { | ||
return 11, 22 | ||
} else { | ||
a = 11 | ||
b = 22 | ||
return // lint: mixing normal and naked returns not allowed | ||
} | ||
} | ||
|
||
func bar() (a int, b int) { | ||
if cond() { | ||
a = 11 | ||
b = 22 | ||
return | ||
} else { | ||
return 11, 22 // lint: mixing normal and naked returns not allowed | ||
} | ||
} | ||
``` | ||
|
||
## Authors | ||
|
||
See [here](https://github.com/gavv/returnstyles/graphs/contributors). | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
Oops, something went wrong.