From 38782dd09724fe51b2c44c9719f7b6c664a8867c Mon Sep 17 00:00:00 2001 From: Isaev Denis Date: Tue, 5 May 2020 17:51:55 +0300 Subject: [PATCH] dev: use golangci-lint action (#1066) --- .github/workflows/pr.yml | 17 ++++++++++++++++- .golangci.example.yml | 4 ++++ .golangci.yml | 6 ++++++ README.md | 17 +++++++++++++++-- README.tmpl.md | 7 +++++-- go.sum | 1 + pkg/result/processors/skip_dirs.go | 1 + pkg/result/processors/skip_files.go | 1 + pkg/result/processors/utils.go | 16 ++++++++++++++++ 9 files changed, 65 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 28199571..7a998a39 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,5 +1,5 @@ --- -name: PR build +name: CI on: push: tags: @@ -8,7 +8,20 @@ on: - master pull_request: jobs: + # We already run the current golangci-lint in tests, but here we test + # our GitHub action with the latest stable golangci-lint. + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: lint + uses: golangci/golangci-lint-action@v0.1.3 + with: + version: v1.26 + github-token: ${{ secrets.GOLANGCI_LINT_TOKEN }} tests-on-windows: + needs: golangci-lint # run after golangci-lint action to not produce duplicated errors runs-on: windows-latest strategy: matrix: @@ -25,6 +38,7 @@ jobs: run: make.exe test continue-on-error: true tests-on-unix: + needs: golangci-lint # run after golangci-lint action to not produce duplicated errors runs-on: ${{ matrix.os }} strategy: matrix: @@ -49,6 +63,7 @@ jobs: - name: Run tests on Unix-like operating systems run: make test check_generated: + needs: golangci-lint # run after golangci-lint action to not produce duplicated errors runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/.golangci.example.yml b/.golangci.example.yml index 7afed939..93debadb 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -23,6 +23,8 @@ run: # can use regexp here: generated.*, regexp is applied on full path; # default value is empty list, but default dirs are skipped independently # from this option's value (see skip-dirs-use-default). + # "/" will be replaced by current OS file path separator to properly work + # on Windows. skip-dirs: - src/external_libs - autogenerated_by_my_lib @@ -35,6 +37,8 @@ run: # won't be reported. Default value is empty list, but there is # no need to include all autogenerated files, we confidently recognize # autogenerated files. If it's not please let us know. + # "/" will be replaced by current OS file path separator to properly work + # on Windows. skip-files: - ".*\\.my\\.go$" - lib/bad.go diff --git a/.golangci.yml b/.golangci.yml index c59782da..c1b63e34 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -103,11 +103,17 @@ linters: - whitespace # don't enable: + # - asciicheck # - gochecknoglobals # - gocognit + # - godot # - godox + # - goerr113 # - maligned + # - nestif # - prealloc + # - testpackage + # - wsl issues: # Excluding configuration per-path, per-linter, per-text and per-source diff --git a/README.md b/README.md index 3aa2a2d6..efc11914 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # GolangCI-Lint -[![Build Status](https://travis-ci.com/golangci/golangci-lint.svg?branch=master)](https://travis-ci.com/golangci/golangci-lint) -[![GolangCI](https://golangci.com/badges/github.com/golangci/golangci-lint.svg)](https://golangci.com) +![Build Status](https://github.com/golangci/golangci-lint/workflows/CI/badge.svg) [![License](https://img.shields.io/github/license/golangci/golangci-lint)](/LICENSE) [![Release](https://img.shields.io/github/release/golangci/golangci-lint.svg)](https://github.com/golangci/golangci-lint/releases/latest) [![Docker](https://img.shields.io/docker/pulls/golangci/golangci-lint)](https://hub.docker.com/r/golangci/golangci-lint) @@ -44,6 +43,10 @@ Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running lint - [Configuration](#configuration) - [Command-Line Options](#command-line-options) - [Config File](#config-file) + - [Custom Linters](#custom-linters) + - [Create a Copy of `golangci-lint` that Can Run with Plugins](#create-a-copy-of-golangci-lint-that-can-run-with-plugins) + - [Configure Your Project for Linting](#configure-your-project-for-linting) + - [To Create Your Own Custom Linter](#to-create-your-own-custom-linter) - [False Positives](#false-positives) - [Nolint](#nolint) - [FAQ](#faq) @@ -646,6 +649,8 @@ run: # can use regexp here: generated.*, regexp is applied on full path; # default value is empty list, but default dirs are skipped independently # from this option's value (see skip-dirs-use-default). + # "/" will be replaced by current OS file path separator to properly work + # on Windows. skip-dirs: - src/external_libs - autogenerated_by_my_lib @@ -658,6 +663,8 @@ run: # won't be reported. Default value is empty list, but there is # no need to include all autogenerated files, we confidently recognize # autogenerated files. If it's not please let us know. + # "/" will be replaced by current OS file path separator to properly work + # on Windows. skip-files: - ".*\\.my\\.go$" - lib/bad.go @@ -1104,11 +1111,17 @@ linters: - whitespace # don't enable: + # - asciicheck # - gochecknoglobals # - gocognit + # - godot # - godox + # - goerr113 # - maligned + # - nestif # - prealloc + # - testpackage + # - wsl issues: # Excluding configuration per-path, per-linter, per-text and per-source diff --git a/README.tmpl.md b/README.tmpl.md index d7e22a37..0a52f322 100644 --- a/README.tmpl.md +++ b/README.tmpl.md @@ -1,7 +1,6 @@ # GolangCI-Lint -[![Build Status](https://travis-ci.com/golangci/golangci-lint.svg?branch=master)](https://travis-ci.com/golangci/golangci-lint) -[![GolangCI](https://golangci.com/badges/github.com/golangci/golangci-lint.svg)](https://golangci.com) +![Build Status](https://github.com/golangci/golangci-lint/workflows/CI/badge.svg) [![License](https://img.shields.io/github/license/golangci/golangci-lint)](/LICENSE) [![Release](https://img.shields.io/github/release/golangci/golangci-lint.svg)](https://github.com/golangci/golangci-lint/releases/latest) [![Docker](https://img.shields.io/docker/pulls/golangci/golangci-lint)](https://hub.docker.com/r/golangci/golangci-lint) @@ -44,6 +43,10 @@ Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running lint - [Configuration](#configuration) - [Command-Line Options](#command-line-options) - [Config File](#config-file) + - [Custom Linters](#custom-linters) + - [Create a Copy of `golangci-lint` that Can Run with Plugins](#create-a-copy-of-golangci-lint-that-can-run-with-plugins) + - [Configure Your Project for Linting](#configure-your-project-for-linting) + - [To Create Your Own Custom Linter](#to-create-your-own-custom-linter) - [False Positives](#false-positives) - [Nolint](#nolint) - [FAQ](#faq) diff --git a/go.sum b/go.sum index 3708fe06..d13fb507 100644 --- a/go.sum +++ b/go.sum @@ -266,6 +266,7 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM github.com/spf13/viper v1.6.1 h1:VPZzIkznI1YhVMRi6vNFLHSwhnhReBfgTxIPccpfdZk= github.com/spf13/viper v1.6.1/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= diff --git a/pkg/result/processors/skip_dirs.go b/pkg/result/processors/skip_dirs.go index 5107814f..6488c109 100644 --- a/pkg/result/processors/skip_dirs.go +++ b/pkg/result/processors/skip_dirs.go @@ -31,6 +31,7 @@ const goFileSuffix = ".go" func NewSkipDirs(patterns []string, log logutils.Log, runArgs []string) (*SkipDirs, error) { var patternsRe []*regexp.Regexp for _, p := range patterns { + p = normalizePathInRegex(p) patternRe, err := regexp.Compile(p) if err != nil { return nil, errors.Wrapf(err, "can't compile regexp %q", p) diff --git a/pkg/result/processors/skip_files.go b/pkg/result/processors/skip_files.go index 92fd1a29..522b07e4 100644 --- a/pkg/result/processors/skip_files.go +++ b/pkg/result/processors/skip_files.go @@ -16,6 +16,7 @@ var _ Processor = SkipFiles{} func NewSkipFiles(patterns []string) (*SkipFiles, error) { var patternsRe []*regexp.Regexp for _, p := range patterns { + p = normalizePathInRegex(p) patternRe, err := regexp.Compile(p) if err != nil { return nil, fmt.Errorf("can't compile regexp %q: %s", p, err) diff --git a/pkg/result/processors/utils.go b/pkg/result/processors/utils.go index 8bc3d847..7108fd3b 100644 --- a/pkg/result/processors/utils.go +++ b/pkg/result/processors/utils.go @@ -1,6 +1,10 @@ package processors import ( + "path/filepath" + "regexp" + "strings" + "github.com/pkg/errors" "github.com/golangci/golangci-lint/pkg/result" @@ -44,3 +48,15 @@ func transformIssues(issues []result.Issue, transform func(i *result.Issue) *res return retIssues } + +var separatorToReplace = regexp.QuoteMeta(string(filepath.Separator)) + +func normalizePathInRegex(path string) string { + if filepath.Separator == '/' { + return path + } + + // This replacing should be safe because "/" are disallowed in Windows + // https://docs.microsoft.com/ru-ru/windows/win32/fileio/naming-a-file + return strings.ReplaceAll(path, "/", separatorToReplace) +}