https://github.com/stapelberg/expanderr
expands the Go Call Expression under your cursor to check errors
https://github.com/stapelberg/expanderr
Last synced: 4 months ago
JSON representation
expands the Go Call Expression under your cursor to check errors
- Host: GitHub
- URL: https://github.com/stapelberg/expanderr
- Owner: stapelberg
- License: bsd-3-clause
- Created: 2017-08-23T06:54:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-10-29T06:30:14.000Z (over 2 years ago)
- Last Synced: 2025-03-16T09:32:39.984Z (4 months ago)
- Language: Go
- Size: 7.42 MB
- Stars: 142
- Watchers: 6
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# expanderr
[](https://goreportcard.com/report/github.com/stapelberg/expanderr)
The expanderr (think “expander”, pronounced with a pirate accent) is a tool
which expands the Go Call Expression under your cursor to check errors. As an
example, assuming your cursor is positioned on this call expression:```go
os.Remove("/tmp/state.bin")
```…invoking the expanderr will leave you with this If Statement instead:
```go
if err := os.Remove("/tmp/state.bin"); err != nil {
return err
}
```Of course, the return values match the enclosing function signature, functions
returning more than one argument are supported, and the local scope is
considered to ensure that your code still compiles.
## Setup
Start by running `go get -u github.com/stapelberg/expanderr`. Then, follow the
section for the editor you use:### Emacs
Add `(load "~/go/src/github.com/stapelberg/expanderr/lisp/go-expanderr.el")` to your Emacs configuration.
From now on, use `C-c C-e` to invoke the expanderr.
## Opportunities to contribute
* [vim integration](https://github.com/stapelberg/expanderr/issues/1)
* use log.Fatal if within main()
* integration for your favorite editor
* [investigate support for the errors package](https://github.com/stapelberg/expanderr/issues/8)## How does this differ from goreturns?
goreturns only inserts a return statement with zero values for the current
function.expanderr understands the signature of the call expression under your cursor and
inserts the appropriate error checking statement (including a return
statement). In practice, this eliminates the need of combining goreturns with an
editor snippet, with the additional bonus of working correctly in a larger
number of situations.