Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
👷 Add golangci-lint and linter-pleasing
Browse files Browse the repository at this point in the history
  • Loading branch information
MeneDev committed May 5, 2020
1 parent 2705c92 commit 49c2d91
Show file tree
Hide file tree
Showing 31 changed files with 165 additions and 200 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Go

on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]
create:
tags:
- v*

jobs:
build:
name: Lint
runs-on: ubuntu-18.04
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Run golangci-lint
uses: actions-contrib/golangci-lint@v1
62 changes: 50 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,43 @@ linters-settings:
- dupImport # https://github.com/go-critic/go-critic/issues/845

linters:
enable-all: true
disable:
- maligned
- prealloc
- gochecknoglobals
- nakedret
- goimports
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- interfacer
- unparam
- lll
- goconst
- gochecknoinits
- errcheck
- funlen
# - gochecknoinits
# - goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
# - gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
# - interfacer
# - lll
- misspell
# - nakedret
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
# - unparam
- unused
- varcheck
- whitespace
run:
skip-dirs:
- test/testdata_etc
Expand All @@ -68,9 +92,17 @@ issues:
- dupl
- gosec
- scopelint
- dogsled
- funlen
- nakedret
- path: cmd/dockmoor/markdown\.go
linters:
- errcheck
- dupl
- path: cmd/dockmoor/asciidoc\.go
linters:
- errcheck
- dupl
- text: "singleCaseSwitch"
linters:
- gocritic
Expand Down Expand Up @@ -110,6 +142,12 @@ issues:
- text: "getPredicate"
linters:
- gocyclo
- text: "SA5008"
linters:
- staticcheck
- text: "Function 'getPredicate' has too many statements"
linters:
- funlen

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
Expand Down
11 changes: 6 additions & 5 deletions cmd/dockmoor/00_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package main
import (
"bytes"
"fmt"
"github.com/MeneDev/dockmoor/dockfmt"
_ "github.com/MeneDev/dockmoor/dockfmt/dockerfile"
"github.com/MeneDev/dockmoor/dockmoor"
"github.com/jessevdk/go-flags"
"github.com/sirupsen/logrus"
"io"
"os"
"path"
"path/filepath"
"strings"

"github.com/MeneDev/dockmoor/dockfmt"
_ "github.com/MeneDev/dockmoor/dockfmt/dockerfile"
"github.com/MeneDev/dockmoor/dockmoor"
"github.com/jessevdk/go-flags"
"github.com/sirupsen/logrus"
)

type ExitCodeCommander interface {
Expand Down
10 changes: 5 additions & 5 deletions cmd/dockmoor/00_main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package main

import (
"bytes"
"github.com/jessevdk/go-flags"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"os"
"strings"
"testing"

"github.com/jessevdk/go-flags"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

var NotADockerfile = "notDocker"
Expand Down Expand Up @@ -99,7 +100,6 @@ func TestMarkdownIsNotError(t *testing.T) {
}

func TestOpensStdin(t *testing.T) {

optionsTest := mainOptionsTestNew()
opener := defaultReadableOpener(optionsTest.mainOptions)

Expand Down
10 changes: 4 additions & 6 deletions cmd/dockmoor/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package main

import (
"bytes"
"github.com/jessevdk/go-flags"
"github.com/mattn/go-shellwords"
"github.com/stretchr/testify/assert"
"html/template"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"testing"

"github.com/jessevdk/go-flags"
"github.com/mattn/go-shellwords"
"github.com/stretchr/testify/assert"
)

func dockerfile(content string) (fileName string) {
Expand Down Expand Up @@ -133,7 +134,6 @@ func TestContainsInvalidOptions(t *testing.T) {
}

func TestMainVersion(t *testing.T) {

os.Args = []string{"exe", "--version"}

mainOptions := mainOptionsACNew(addContainsCommand)
Expand All @@ -143,7 +143,6 @@ func TestMainVersion(t *testing.T) {
}

func TestMainManpage(t *testing.T) {

os.Args = []string{"exe", "--manpage"}
mainOptions := mainOptionsACNew(addContainsCommand)
exitCode := doMain(mainOptions)
Expand All @@ -152,7 +151,6 @@ func TestMainManpage(t *testing.T) {
}

func TestMainMarkdown(t *testing.T) {

os.Args = []string{"exe", "--markdown"}

mainOptions := mainOptionsACNew()
Expand Down
6 changes: 2 additions & 4 deletions cmd/dockmoor/asciidoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package main

import (
"fmt"
"github.com/jessevdk/go-flags"
"io"
"strings"

"github.com/jessevdk/go-flags"
)

func WriteASCIIDoc(parser *flags.Parser, writer io.Writer) {
Expand Down Expand Up @@ -34,12 +35,10 @@ func WriteASCIIDoc(parser *flags.Parser, writer io.Writer) {
}

func WriteASCIIDocUsage(commands []*flags.Command, writer io.Writer) {

commands = visibleCommands(commands)

mdPrintf(writer, "> ")
for idxCommand, command := range commands {

isFirstCommand := idxCommand == 0
isLastCommand := idxCommand+1 == len(commands)

Expand Down Expand Up @@ -92,7 +91,6 @@ func WriteASCIIDocUsage(commands []*flags.Command, writer io.Writer) {
}

func WriteASCIIDocGroups(writer io.Writer, groups []*flags.Group, level int) {

for _, group := range groups {
if group.Hidden {
continue
Expand Down
3 changes: 2 additions & 1 deletion cmd/dockmoor/cmd_contains.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"errors"
"io"

"github.com/MeneDev/dockmoor/dockfmt"
"github.com/MeneDev/dockmoor/dockproc"
"github.com/MeneDev/dockmoor/dockref"
"github.com/jessevdk/go-flags"
"io"
)

type containsOptions struct {
Expand Down
12 changes: 5 additions & 7 deletions cmd/dockmoor/cmd_contains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"testing"

"github.com/MeneDev/dockmoor/dockfmt"
"github.com/MeneDev/dockmoor/dockproc"
"github.com/MeneDev/dockmoor/dockref"
"github.com/jessevdk/go-flags"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"io"
"io/ioutil"
"os"
"testing"
)

type containsOptionsTest struct {
Expand Down Expand Up @@ -167,7 +168,6 @@ func TestExecuteReturnsErrorWithContains(t *testing.T) {
}

func TestMainMarkdownWithContains(t *testing.T) {

os.Args = []string{"exe", "--markdown"}

mainOptions := mainOptionsACNew(addContainsCommand)
Expand All @@ -181,7 +181,6 @@ func TestMainMarkdownWithContains(t *testing.T) {
}

func TestMainAsciiDocWithContains(t *testing.T) {

os.Args = []string{"exe", "--asciidoc-usage"}

mainOptions := mainOptionsACNew(addContainsCommand)
Expand All @@ -195,7 +194,6 @@ func TestMainAsciiDocWithContains(t *testing.T) {
}

func TestContainsHelpIsNotAnError(t *testing.T) {

os.Args = []string{"exe", "contains", "--help"}

mainOptions := mainOptionsACNew(addContainsCommand)
Expand Down
4 changes: 2 additions & 2 deletions cmd/dockmoor/cmd_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"errors"
"fmt"
"io"

"github.com/MeneDev/dockmoor/dockfmt"
"github.com/MeneDev/dockmoor/dockproc"
"github.com/MeneDev/dockmoor/dockref"
"github.com/jessevdk/go-flags"
"io"
)

type listOptions struct {
Expand Down Expand Up @@ -71,7 +72,6 @@ func (lo *listOptions) ExecuteWithExitCode(args []string) (exitCode ExitCode, er
}

func (lo *listOptions) applyFormatProcessor(predicate dockproc.Predicate, processor dockfmt.FormatProcessor) error {

return processor.Process(func(r dockref.Reference) (dockref.Reference, error) {
if predicate.Matches(r) {
lo.matches = true
Expand Down
10 changes: 4 additions & 6 deletions cmd/dockmoor/cmd_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package main

import (
"bytes"
"io"
"os"
"testing"

"github.com/MeneDev/dockmoor/dockfmt"
"github.com/MeneDev/dockmoor/dockproc"
"github.com/MeneDev/dockmoor/dockref"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"io"
"os"
"testing"
)

type listOptionsTest struct {
Expand Down Expand Up @@ -49,7 +50,6 @@ func TestListCallsFindExecute(t *testing.T) {
}

func TestMainMarkdownWithList(t *testing.T) {

os.Args = []string{"exe", "--markdown"}

mainOptions := mainOptionsACNew(addListCommand)
Expand All @@ -63,7 +63,6 @@ func TestMainMarkdownWithList(t *testing.T) {
}

func TestMainAsciiDocWithList(t *testing.T) {

os.Args = []string{"exe", "--asciidoc-usage"}

mainOptions := mainOptionsACNew(addListCommand)
Expand All @@ -77,7 +76,6 @@ func TestMainAsciiDocWithList(t *testing.T) {
}

func TestListHelpIsNotAnError(t *testing.T) {

os.Args = []string{"exe", "list", "--help"}

mainOptions := mainOptionsACNew(addListCommand)
Expand Down
Loading

0 comments on commit 49c2d91

Please sign in to comment.