Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed May 21, 2023
0 parents commit 3ff5453
Show file tree
Hide file tree
Showing 18 changed files with 1,061 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
liberapay: gavv
custom:
- "https://www.paypal.me/victorgaydov"
36 changes: 36 additions & 0 deletions .github/workflows/build.yaml
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
returnstyles
21 changes: 21 additions & 0 deletions LICENSE
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.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all: tidy build test

tidy:
go mod tidy -v

build:
go build .

test:
go test -v ./analyzer
126 changes: 126 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# 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/tags)

Go (golang) linter that checks function return styles according to rules of your choice.

## Install

```
go install github.com/gavv/returnstyles@latest
```

## Usage

```
returnstyles [options] [package]
```

## Options

| option | default | description |
|-------------------------------|---------|---------------------------------------------------------------------------|
| `-unnamed-allow` | true | allow functions with unnamed return variables |
| `-named-allow` | true | allow functions with named return variables |
| `-named-allow-partial` | true | allow functions with partially named return variables |
| `-named-allow-normal-returns` | true | allow normal (non-naked) returns in functions with named return variables |
| `-named-allow-naked-returns` | true | allow naked returns in functions with named return variables |
| `-named-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:

unnamed:
allow: true

named:
allow-partial: true
allow-normal-returns: true
allow-naked-returns: true
allow-mixing-returns: false
```

## Samples

#### `-unnamed-allow=false`

```go
func foo() (int, int) { // lint: functions with unnamed return variables not allowed
return 11, 22
}
```

#### `-named-allow=false`

```go
func foo() (a int, b int) { // lint: functions with named return variables not allowed
return 11, 22
}
```

#### `-named-allow-partial=false`

```go
func foo() (int, b int) { // lint: functions with partially named return variables not allowed
return 11, 22
}
```

#### `-named-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
}
```

#### `-named-allow-naked-returns=false`

```go
func foo() (a int, b int) {
a = 11
b = 22
return // lint: naked returns not allowed
}
```

#### `-named-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)

0 comments on commit 3ff5453

Please sign in to comment.