Skip to content

Commit 38782dd

Browse files
authored
dev: use golangci-lint action (#1066)
1 parent 01b726a commit 38782dd

File tree

9 files changed

+65
-5
lines changed

9 files changed

+65
-5
lines changed

.github/workflows/pr.yml

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: PR build
2+
name: CI
33
on:
44
push:
55
tags:
@@ -8,7 +8,20 @@ on:
88
- master
99
pull_request:
1010
jobs:
11+
# We already run the current golangci-lint in tests, but here we test
12+
# our GitHub action with the latest stable golangci-lint.
13+
golangci-lint:
14+
name: golangci-lint
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: lint
19+
uses: golangci/[email protected]
20+
with:
21+
version: v1.26
22+
github-token: ${{ secrets.GOLANGCI_LINT_TOKEN }}
1123
tests-on-windows:
24+
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
1225
runs-on: windows-latest
1326
strategy:
1427
matrix:
@@ -25,6 +38,7 @@ jobs:
2538
run: make.exe test
2639
continue-on-error: true
2740
tests-on-unix:
41+
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
2842
runs-on: ${{ matrix.os }}
2943
strategy:
3044
matrix:
@@ -49,6 +63,7 @@ jobs:
4963
- name: Run tests on Unix-like operating systems
5064
run: make test
5165
check_generated:
66+
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
5267
runs-on: ubuntu-latest
5368
steps:
5469
- uses: actions/checkout@v2

.golangci.example.yml

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ run:
2323
# can use regexp here: generated.*, regexp is applied on full path;
2424
# default value is empty list, but default dirs are skipped independently
2525
# from this option's value (see skip-dirs-use-default).
26+
# "/" will be replaced by current OS file path separator to properly work
27+
# on Windows.
2628
skip-dirs:
2729
- src/external_libs
2830
- autogenerated_by_my_lib
@@ -35,6 +37,8 @@ run:
3537
# won't be reported. Default value is empty list, but there is
3638
# no need to include all autogenerated files, we confidently recognize
3739
# autogenerated files. If it's not please let us know.
40+
# "/" will be replaced by current OS file path separator to properly work
41+
# on Windows.
3842
skip-files:
3943
- ".*\\.my\\.go$"
4044
- lib/bad.go

.golangci.yml

+6
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,17 @@ linters:
103103
- whitespace
104104

105105
# don't enable:
106+
# - asciicheck
106107
# - gochecknoglobals
107108
# - gocognit
109+
# - godot
108110
# - godox
111+
# - goerr113
109112
# - maligned
113+
# - nestif
110114
# - prealloc
115+
# - testpackage
116+
# - wsl
111117

112118
issues:
113119
# Excluding configuration per-path, per-linter, per-text and per-source

README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# GolangCI-Lint
22

3-
[![Build Status](https://travis-ci.com/golangci/golangci-lint.svg?branch=master)](https://travis-ci.com/golangci/golangci-lint)
4-
[![GolangCI](https://golangci.com/badges/github.com/golangci/golangci-lint.svg)](https://golangci.com)
3+
![Build Status](https://github.com/golangci/golangci-lint/workflows/CI/badge.svg)
54
[![License](https://img.shields.io/github/license/golangci/golangci-lint)](/LICENSE)
65
[![Release](https://img.shields.io/github/release/golangci/golangci-lint.svg)](https://github.com/golangci/golangci-lint/releases/latest)
76
[![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
4443
- [Configuration](#configuration)
4544
- [Command-Line Options](#command-line-options)
4645
- [Config File](#config-file)
46+
- [Custom Linters](#custom-linters)
47+
- [Create a Copy of `golangci-lint` that Can Run with Plugins](#create-a-copy-of-golangci-lint-that-can-run-with-plugins)
48+
- [Configure Your Project for Linting](#configure-your-project-for-linting)
49+
- [To Create Your Own Custom Linter](#to-create-your-own-custom-linter)
4750
- [False Positives](#false-positives)
4851
- [Nolint](#nolint)
4952
- [FAQ](#faq)
@@ -646,6 +649,8 @@ run:
646649
# can use regexp here: generated.*, regexp is applied on full path;
647650
# default value is empty list, but default dirs are skipped independently
648651
# from this option's value (see skip-dirs-use-default).
652+
# "/" will be replaced by current OS file path separator to properly work
653+
# on Windows.
649654
skip-dirs:
650655
- src/external_libs
651656
- autogenerated_by_my_lib
@@ -658,6 +663,8 @@ run:
658663
# won't be reported. Default value is empty list, but there is
659664
# no need to include all autogenerated files, we confidently recognize
660665
# autogenerated files. If it's not please let us know.
666+
# "/" will be replaced by current OS file path separator to properly work
667+
# on Windows.
661668
skip-files:
662669
- ".*\\.my\\.go$"
663670
- lib/bad.go
@@ -1104,11 +1111,17 @@ linters:
11041111
- whitespace
11051112
11061113
# don't enable:
1114+
# - asciicheck
11071115
# - gochecknoglobals
11081116
# - gocognit
1117+
# - godot
11091118
# - godox
1119+
# - goerr113
11101120
# - maligned
1121+
# - nestif
11111122
# - prealloc
1123+
# - testpackage
1124+
# - wsl
11121125
11131126
issues:
11141127
# Excluding configuration per-path, per-linter, per-text and per-source

README.tmpl.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# GolangCI-Lint
22

3-
[![Build Status](https://travis-ci.com/golangci/golangci-lint.svg?branch=master)](https://travis-ci.com/golangci/golangci-lint)
4-
[![GolangCI](https://golangci.com/badges/github.com/golangci/golangci-lint.svg)](https://golangci.com)
3+
![Build Status](https://github.com/golangci/golangci-lint/workflows/CI/badge.svg)
54
[![License](https://img.shields.io/github/license/golangci/golangci-lint)](/LICENSE)
65
[![Release](https://img.shields.io/github/release/golangci/golangci-lint.svg)](https://github.com/golangci/golangci-lint/releases/latest)
76
[![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
4443
- [Configuration](#configuration)
4544
- [Command-Line Options](#command-line-options)
4645
- [Config File](#config-file)
46+
- [Custom Linters](#custom-linters)
47+
- [Create a Copy of `golangci-lint` that Can Run with Plugins](#create-a-copy-of-golangci-lint-that-can-run-with-plugins)
48+
- [Configure Your Project for Linting](#configure-your-project-for-linting)
49+
- [To Create Your Own Custom Linter](#to-create-your-own-custom-linter)
4750
- [False Positives](#false-positives)
4851
- [Nolint](#nolint)
4952
- [FAQ](#faq)

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
266266
github.com/spf13/viper v1.6.1 h1:VPZzIkznI1YhVMRi6vNFLHSwhnhReBfgTxIPccpfdZk=
267267
github.com/spf13/viper v1.6.1/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k=
268268
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
269+
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
269270
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
270271
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
271272
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=

pkg/result/processors/skip_dirs.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const goFileSuffix = ".go"
3131
func NewSkipDirs(patterns []string, log logutils.Log, runArgs []string) (*SkipDirs, error) {
3232
var patternsRe []*regexp.Regexp
3333
for _, p := range patterns {
34+
p = normalizePathInRegex(p)
3435
patternRe, err := regexp.Compile(p)
3536
if err != nil {
3637
return nil, errors.Wrapf(err, "can't compile regexp %q", p)

pkg/result/processors/skip_files.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var _ Processor = SkipFiles{}
1616
func NewSkipFiles(patterns []string) (*SkipFiles, error) {
1717
var patternsRe []*regexp.Regexp
1818
for _, p := range patterns {
19+
p = normalizePathInRegex(p)
1920
patternRe, err := regexp.Compile(p)
2021
if err != nil {
2122
return nil, fmt.Errorf("can't compile regexp %q: %s", p, err)

pkg/result/processors/utils.go

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package processors
22

33
import (
4+
"path/filepath"
5+
"regexp"
6+
"strings"
7+
48
"github.com/pkg/errors"
59

610
"github.com/golangci/golangci-lint/pkg/result"
@@ -44,3 +48,15 @@ func transformIssues(issues []result.Issue, transform func(i *result.Issue) *res
4448

4549
return retIssues
4650
}
51+
52+
var separatorToReplace = regexp.QuoteMeta(string(filepath.Separator))
53+
54+
func normalizePathInRegex(path string) string {
55+
if filepath.Separator == '/' {
56+
return path
57+
}
58+
59+
// This replacing should be safe because "/" are disallowed in Windows
60+
// https://docs.microsoft.com/ru-ru/windows/win32/fileio/naming-a-file
61+
return strings.ReplaceAll(path, "/", separatorToReplace)
62+
}

0 commit comments

Comments
 (0)