Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elliotchance/ghost
👻 Locate and fix overly complex lines of code in Go.
https://github.com/elliotchance/ghost
go golang linter
Last synced: 1 day ago
JSON representation
👻 Locate and fix overly complex lines of code in Go.
- Host: GitHub
- URL: https://github.com/elliotchance/ghost
- Owner: elliotchance
- Created: 2018-10-06T07:52:55.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-15T11:19:44.000Z (almost 6 years ago)
- Last Synced: 2024-06-20T17:46:53.342Z (3 months ago)
- Topics: go, golang, linter
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 54
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
👻 ghost
========[![Build Status](https://travis-ci.org/elliotchance/ghost.svg?branch=master)](https://travis-ci.org/elliotchance/ghost)
`ghost` is a command-line tool for locating overly complex lines of code in Go.
It is designed with the intention that code should strive to be written in a
linear, rather than nested way. This makes code easier to understand, highlights
duplicate logic and ultimately leads to less bugs.Installation
------------```bash
go get -u github.com/elliotchance/ghost
```Usage
-----Pass one or multiple Go files:
```bash
ghost file1.go file2.go
```### CLI Options
- `-ignore-tests` - Ignore test files.
- `-max-line-complexity` - The maximum allowed line complexity. (default 5)
- `-never-fail` - Always exit with 0.Example
-------The output of ghost (with default options) describes that line 50 is too
complex:```
jaro.go:50: complexity is 8 (in JaroWinkler)
```The line is:
```go
prefixSize = int(math.Min(float64(len(a)), math.Min(float64(prefixSize), float64(len(b)))))
```There is nothing logically incorrect with that line, but it is long, difficult
to understand and can be tricky to inspect with a debugger.There are lots of different ways the above code can be rewritten. For me, once I
understand what it's really doing I can create the function:```go
func minInt(values ...int) int {
sort.Ints(values)return values[0]
}
```Now it can be simply written as:
```go
prefixSize = minInt(prefixSize, len(a), len(b))
```Ignoring Lines
--------------Any comment that contains the string `ghost:ignore` will cause the next
proceeding line to be ignored:```go
// ghost:ignore
a := lastName[baz() : foo + bar : qux()]
```