Skip to content

Commit

Permalink
chore: update Go, and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Sep 2, 2023
1 parent 745bb2f commit 66007ad
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 81 deletions.
24 changes: 8 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,24 @@ jobs:
name: Main Process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.18
GOLANGCI_LINT_VERSION: v1.47.2
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.54.2
CGO_ENABLED: 0

steps:

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

# https://github.com/marketplace/actions/checkout
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v2
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
go-version: ${{ env.GO_VERSION }}


- name: Check and get dependencies
run: |
Expand Down
29 changes: 6 additions & 23 deletions .github/workflows/go-cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,20 @@ jobs:

strategy:
matrix:
go-version: [ 1.17, 1.x ]
go-version: [ stable, oldstable ]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

# https://github.com/marketplace/actions/checkout
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v2
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ matrix.go-version }}-go-
go-version: ${{ matrix.go-version }}

- name: Test
run: go test -v -cover ./...
Expand Down
19 changes: 14 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@ linters-settings:
linters:
enable-all: true
disable:
- maligned # Deprecated
- scopelint # Deprecated
- golint # Deprecated
- interfacer # Deprecated
- exhaustivestruct # Deprecated
- deadcode # deprecated
- exhaustivestruct # deprecated
- golint # deprecated
- ifshort # deprecated
- interfacer # deprecated
- maligned # deprecated
- nosnakecase # deprecated
- scopelint # deprecated
- structcheck # deprecated
- varcheck # deprecated
- cyclop # duplicate of gocyclo
- sqlclosecheck # not relevant (SQL)
- rowserrcheck # not relevant (SQL)
- execinquery # not relevant (SQL)
- dupl
- lll
- nestif
Expand All @@ -54,6 +62,7 @@ linters:
- nosnakecase
- nonamedreturns
- nilerr
- depguard

issues:
exclude-use-default: false
Expand Down
1 change: 1 addition & 0 deletions cmd/revgrep/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main a CLI tool used to filter static analysis tools to only lines changed based on a commit reference.
package main

import (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/golangci/revgrep

go 1.17
go 1.19
58 changes: 23 additions & 35 deletions revgrep.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package revgrep filter static analysis tools to only lines changed based on a commit reference.
package revgrep

import (
Expand All @@ -17,31 +18,26 @@ import (
// Checker provides APIs to filter static analysis tools to specific commits,
// such as showing only issues since last commit.
type Checker struct {
// Patch file (unified) to read to detect lines being changed, if nil revgrep
// will attempt to detect the VCS and generate an appropriate patch. Auto
// detection will search for uncommitted changes first, if none found, will
// generate a patch from last committed change. File paths within patches
// must be relative to current working directory.
// Patch file (unified) to read to detect lines being changed,
// if nil revgrep will attempt to detect the VCS and generate an appropriate patch.
// Auto-detection will search for uncommitted changes first,
// if none found, will generate a patch from last committed change.
// File paths within patches must be relative to current working directory.
Patch io.Reader
// NewFiles is a list of file names (with absolute paths) where the entire
// contents of the file is new.
// NewFiles is a list of file names (with absolute paths) where the entire contents of the file is new.
NewFiles []string
// Debug sets the debug writer for additional output.
Debug io.Writer
// RevisionFrom check revision starting at, leave blank for auto detection
// ignored if patch is set.
// RevisionFrom check revision starting at, leave blank for auto-detection ignored if patch is set.
RevisionFrom string
// WholeFiles indicates that the user wishes to see all issues that comes up
// anywhere in any file that has been changed in this revision or patch.
// WholeFiles indicates that the user wishes to see all issues that comes up anywhere in any file that has been changed in this revision or patch.
WholeFiles bool
// RevisionTo checks revision finishing at, leave blank for auto detection
// ignored if patch is set.
// RevisionTo checks revision finishing at, leave blank for auto-detection ignored if patch is set.
RevisionTo string
// Regexp to match path, line number, optional column number, and message.
Regexp string
// AbsPath is used to make an absolute path of an issue's filename to be
// relative in order to match patch file. If not set, current working
// directory is used.
// AbsPath is used to make an absolute path of an issue's filename to be relative in order to match patch file.
// If not set, current working directory is used.
AbsPath string

// Calculated changes for next calls to IsNewIssue
Expand All @@ -56,9 +52,7 @@ type Issue struct {
LineNo int
// ColNo is the column number or 0 if none could be parsed.
ColNo int
// HunkPos is position from file's first @@, for new files this will be the
// line number.
//
// HunkPos is position from file's first @@, for new files this will be the line number.
// See also: https://developer.github.com/v3/pulls/comments/#create-a-comment
HunkPos int
// Issue text as it appeared from the tool.
Expand Down Expand Up @@ -135,16 +129,14 @@ func (c *Checker) IsNewIssue(i InputIssue) (hunkPos int, isNew bool) {
return 0, false
}

// Check scans reader and writes any lines to writer that have been added in
// Checker.Patch.
// Check scans reader and writes any lines to writer that have been added in Checker.Patch.
//
// Returns the issues written to writer when no error occurs.
//
// If no VCS could be found or other VCS errors occur, all issues are written
// to writer and an error is returned.
// If no VCS could be found or other VCS errors occur,
// all issues are written to writer and an error is returned.
//
// File paths in reader must be relative to current working directory or
// absolute.
// File paths in reader must be relative to current working directory or absolute.
func (c *Checker) Check(reader io.Reader, writer io.Writer) (issues []Issue, err error) {
returnErr := c.Prepare()
writeAll := returnErr != nil
Expand Down Expand Up @@ -265,8 +257,7 @@ func (c *Checker) preparePatch() error {
}

// linesChanges returns a map of file names to line numbers being changed.
// If key is nil, the file has been recently added, else it contains a slice
// of positions that have been added.
// If key is nil, the file has been recently added, else it contains a slice of positions that have been added.
func (c *Checker) linesChanged() map[string][]pos {
type state struct {
file string
Expand Down Expand Up @@ -343,14 +334,11 @@ func (c *Checker) linesChanged() map[string][]pos {
return changes
}

// GitPatch returns a patch from a git repository, if no git repository was
// was found and no errors occurred, nil is returned, else an error is returned
// revisionFrom and revisionTo defines the git diff parameters, if left blank
// and there are unstaged changes or untracked files, only those will be returned
// else only check changes since HEAD~. If revisionFrom is set but revisionTo
// is not, untracked files will be included, to exclude untracked files set
// revisionTo to HEAD~. It's incorrect to specify revisionTo without a
// revisionFrom.
// GitPatch returns a patch from a git repository,
// if no git repository was found and no errors occurred, nil is returned, else an error is returned revisionFrom and revisionTo defines the git diff parameters,
// if left blank and there are unstaged changes or untracked files, only those will be returned else only check changes since HEAD~.
// If revisionFrom is set but revisionTo is not, untracked files will be included, to exclude untracked files set revisionTo to HEAD~.
// It's incorrect to specify revisionTo without a revisionFrom.
func GitPatch(revisionFrom, revisionTo string) (io.Reader, []string, error) {
var patch bytes.Buffer

Expand Down
2 changes: 1 addition & 1 deletion revgrep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func setup(t *testing.T, stage, subdir string) (string, []byte) {
cmd.Dir = gitDir

goVetOutput, err := cmd.CombinedOutput()
if cmd.ProcessState.ExitCode() != 2 {
if cmd.ProcessState.ExitCode() != 1 {
t.Logf("%s: go vet: %s", stage, string(goVetOutput))
t.Fatalf("could not run go vet: %v", err)
}
Expand Down

0 comments on commit 66007ad

Please sign in to comment.