Skip to content

Commit

Permalink
Merge pull request #22 from fatih/add-goreleser
Browse files Browse the repository at this point in the history
Add goreleaser support and -V flag for printing the version
  • Loading branch information
fatih authored Mar 8, 2021
2 parents eb3cc62 + cf259bd commit fd04803
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 27 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
name: build
on: [push, pull_request]

on:
push:
branches:
- master
- main
tags:
- 'v*'
pull_request:


jobs:

test-build:
name: Test & Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.13
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.16
id: go

- name: Check out code into the Go module directory
Expand All @@ -23,3 +33,13 @@ jobs:
- name: Build
run: go build ./...

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
# only release on tags
if: success() && startsWith(github.ref, 'refs/tags/')
with:
version: v0.156.1
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.FAILLINT_ACTIONS_BOT_TOKEN }}
37 changes: 37 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
project_name: faillint
release:
prerelease: auto # don't publish release with -rc1,-pre, etc suffixes
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
ldflags:
- -s -w -X main.version={{.Version}} -X main.date={{.Date}}
binary: "faillint"
nfpms:
- maintainer: Fatih Arslan
description: Report unwanted Go import path and declaration usages
homepage: https://github.com/fatih/faillint
license: BSD 3-Clause
formats:
- deb
- rpm
replacements:
darwin: macOS
archives:
- replacements:
darwin: macOS
format_overrides:
- goos: windows
format: zip
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,30 @@ you can configure to fail on such single function of `fmt` as well.
## Install

```bash
go get github.com/fatih/faillint
go install github.com/fatih/faillint@latest
```

## Example

Assume we have the following file:

```go
package a

import (
"errors"
)

func foo() error {
return errors.New("bar!")
}
```

Let's run `faillint` to check if `errors` import is used and report it:

```
$ faillint -paths "errors=github.com/pkg/errors" a.go
a.go:4:2: package "errors" shouldn't be imported, suggested: "github.com/pkg/errors"
```

## Usage
Expand Down Expand Up @@ -121,29 +144,6 @@ func foo() error {
}
```

## Example

Assume we have the following file:

```go
package a

import (
"errors"
)

func foo() error {
return errors.New("bar!")
}
```

Let's run `faillint` to check if `errors` import is used and report it:

```
$ faillint -paths "errors=github.com/pkg/errors" a.go
a.go:4:2: package "errors" shouldn't be imported, suggested: "github.com/pkg/errors"
```

## The need for this tool?

Most of these checks should be probably detected during the review cycle. But
Expand Down
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/fatih/faillint/faillint"
"golang.org/x/tools/go/analysis/singlechecker"
)

var (
version string
date string
)

func main() {
// this is a small hack to implement the -V flag that is part of
// go/analysis framework. It'll allow us to print the version with -V, but
// the --help message will print the flags of the analyzer
ff := flag.NewFlagSet("faillint", flag.ContinueOnError)
v := ff.Bool("V", false, "print version and exit")
ff.Usage = func() {}
ff.Parse(os.Args[1:])
if *v {
fmt.Printf("faillint version %s (%s)\n", version, date)
os.Exit(0)
}

singlechecker.Main(faillint.NewAnalyzer())
}

0 comments on commit fd04803

Please sign in to comment.