Skip to content

Commit

Permalink
all: enable linters and tests on github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
quasilyte committed Dec 17, 2021
1 parent fb7320c commit db4e633
Show file tree
Hide file tree
Showing 21 changed files with 177 additions and 47 deletions.
22 changes: 22 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See: https://github.com/marketplace/actions/release-drafter

name-template: "v$NEXT_PATCH_VERSION"
tag-template: "v$NEXT_PATCH_VERSION"
categories:
- title: "Features"
labels:
- "feature"
- title: "Bug Fixes"
labels:
- "fix"
- "bugfix"
- "bug"
- title: "Maintenance"
labels:
- "task"
- "documentation"
change-template: "- $TITLE @$AUTHOR (#$NUMBER)"
template: |
## Changes
$CHANGES
27 changes: 27 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file adheres to the YAML5 style.
{
name: "Go",
on: ["push", "pull_request"],
jobs: {
build: {
name: "Build",
"runs-on": "ubuntu-latest",
steps: [
{
name: "Set up Go 1.16",
uses: "actions/setup-go@v1",
"with": {"go-version": 1.16},
id: "go",
},
{name: "Check out code into the Go module directory", uses: "actions/checkout@v1"},
{name: "Linter", run: "make ci-lint"},
{name: "Test", run: "make test"},
{
name: "Upload coverage",
uses: "codecov/codecov-action@v2",
"with": {token: "${{secrets.CODECOV_TOKEN}}", file: "./coverage.txt", fail_ci_if_error: false},
},
],
},
},
}
16 changes: 16 additions & 0 deletions .github/workflows/release-management.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Release Management

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master

jobs:
update_draft_release:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: toolmantim/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
.vscode
coverage.txt
bin
49 changes: 49 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"run": {
# timeout for analysis, e.g. 30s, 5m, default is 1m
"deadline": "3m",
},
"fast": false,
"linters": {
"enable": [
"deadcode",
"errcheck",
"gas",
"gocritic",
"gofmt",
"goimports",
"revive",
"govet",
"gosimple",
"ineffassign",
"megacheck",
"misspell",
"nakedret",
"staticcheck",
"structcheck",
"typecheck",
"unconvert",
"unused",
"varcheck",
],
},
"disable": [
"depguard",
"dupl",
"gocyclo",
"interfacer",
"lll",
"maligned",
"prealloc",
],
"linters-settings": {
"gocritic": {
"enabled-tags": [
"style",
"diagnostic",
"performance",
"experimental",
],
},
},
}
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GOPATH_DIR=`go env GOPATH`

test:
go test -count 2 -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic ./...
go test -bench=. ./...
@echo "everything is OK"

ci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH_DIR)/bin v1.43.0
$(GOPATH_DIR)/bin/golangci-lint run ./...
go install github.com/quasilyte/go-consistent@latest
$(GOPATH_DIR)/bin/go-consistent ./...
@echo "everything is OK"

lint:
golangci-lint run ./...
@echo "everything is OK"

.PHONY: ci-lint lint test
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# gogrep

![logo](https://github.com/quasilyte/vscode-gogrep/blob/master/docs/logo.png?raw=true)

![Build Status](https://github.com/quasilyte/perf-heatmap/workflows/Go/badge.svg)
[![PkgGoDev](https://pkg.go.dev/badge/mod/github.com/quasilyte/perf-heatmap/heatmap)](https://pkg.go.dev/github.com/quasilyte/perf-heatmap/heatmap)
[![Go Report Card](https://goreportcard.com/badge/github.com/quasilyte/go-ruleguard)](https://goreportcard.com/report/github.com/quasilyte/go-ruleguard)
![Code Coverage](https://codecov.io/gh/quasilyte/perf-heatmap/branch/master/graph/badge.svg)

# gogrep

WIP: this is an attempt to move modified [gogrep](https://github.com/mvdan/gogrep) from the [go-ruleguard](https://github.com/quasilyte/go-ruleguard) project, so it can be used outside of the ruleguard as a library.

## Acknowledgements
Expand Down
5 changes: 2 additions & 3 deletions cmd/gogrep/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"go/token"
"io"
"io/fs"
"io/ioutil"
"log"
"math"
"os"
Expand Down Expand Up @@ -473,7 +472,7 @@ func (p *program) walkTarget(target string, filenameQueue chan<- string, ticker
}

numMatches := atomic.LoadUint64(&p.numMatches)
if numMatches > uint64(p.args.limit) {
if numMatches > p.args.limit {
return io.EOF
}

Expand Down Expand Up @@ -548,7 +547,7 @@ func (p *program) printMatches() error {
func (p *program) finishProfiling() error {
if p.args.cpuProfile != "" {
pprof.StopCPUProfile()
err := ioutil.WriteFile(p.args.cpuProfile, p.cpuProfile.Bytes(), 0666)
err := os.WriteFile(p.args.cpuProfile, p.cpuProfile.Bytes(), 0o600)
if err != nil {
return fmt.Errorf("write CPU profile: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/gogrep/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"strings"

"github.com/quasilyte/gogrep"
Expand Down Expand Up @@ -39,7 +39,7 @@ type worker struct {
}

func (w *worker) grepFile(filename string) (int, error) {
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return 0, fmt.Errorf("read file: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment: false
7 changes: 4 additions & 3 deletions compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,12 @@ func (c *compiler) compileOptFieldList(n *ast.FieldList) {
// `func (...) $*result` - result could be anything
// `func (...) $result` - result is a field list of 1 element
info := decodeWildName(ident.Name)
if info.Seq {
switch {
case info.Seq:
c.compileWildIdent(ident, true)
} else if info.Name == "_" {
case info.Name == "_":
c.emitInstOp(opFieldNode)
} else {
default:
c.emitInst(instruction{
op: opNamedFieldNode,
valueIndex: c.internVar(n, info.Name),
Expand Down
2 changes: 1 addition & 1 deletion filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Info struct {
OpTab *OperationsTable
}

func (info Info) String() string {
func (info *Info) String() string {
var parts []string
for _, f := range info.FilePredicates {
negate := ""
Expand Down
4 changes: 3 additions & 1 deletion filters/operation_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 2 additions & 22 deletions filters/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func (p *filterParser) Parse(s string) (*Expr, Info, error) {
return nil, Info{}, err
}

p.varnameToID = map[string]int32{}
p.functionFilterSet = map[SpecialPredicate]struct{}{}
p.varnameToID = make(map[string]int32)
p.functionFilterSet = make(map[SpecialPredicate]struct{})

p.info.OpTab = p.tab

Expand Down Expand Up @@ -195,26 +195,6 @@ func (p *filterParser) convertBinaryExpr(root *ast.BinaryExpr) (*Expr, error) {
return p.convertBinaryExprXY(root.Op, root.X, root.Y)
}

func (p *filterParser) invertOp(op token.Token) token.Token {
switch op {
case token.EQL:
return token.NEQ
case token.NEQ:
return token.EQL
case token.LSS:
return token.GEQ
case token.GTR:
return token.LEQ
case token.LEQ:
return token.GTR
case token.GEQ:
return token.LSS

default:
return token.ILLEGAL
}
}

func (p *filterParser) convertBinaryExprXY(op token.Token, x, y ast.Expr) (*Expr, error) {
switch op {
case token.LOR:
Expand Down
3 changes: 2 additions & 1 deletion filters/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ func TestParse(t *testing.T) {
t.Fatalf("compile %q: %v", test.input, err)
}
if test.info != info.String() {
t.Fatalf("info mismatch for %q:\nhave: %s\nwant: %s", test.input, info, test.info)
t.Fatalf("info mismatch for %q:\nhave: %s\nwant: %s",
test.input, info.String(), test.info)
}
have := Sprint(&info, compiled)
if test.expr != have {
Expand Down
2 changes: 1 addition & 1 deletion gogrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ func Compile(config CompileConfig) (*Pattern, PatternInfo, error) {

func newPatternInfo() PatternInfo {
return PatternInfo{
Vars: map[string]struct{}{},
Vars: make(map[string]struct{}),
}
}
7 changes: 3 additions & 4 deletions match.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func (m *matcher) MatchNode(state *MatcherState, n ast.Node, accept func(MatchDa
m.walkExprSlice(state, n.Results, accept)
}
case opMultiDecl:
switch n := n.(type) {
case *ast.File:
if n, ok := n.(*ast.File); ok {
m.walkDeclSlice(state, n.Decls, accept)
}
default:
Expand Down Expand Up @@ -609,7 +608,7 @@ func (m *matcher) matchSpecSlice(state *MatcherState, specs []ast.Spec) bool {

// matchNodeList matches two lists of nodes. It uses a common algorithm to match
// wildcard patterns with any number of nodes without recursion.
func (m *matcher) matchNodeList(state *MatcherState, nodes NodeSlice, partial bool) (ast.Node, int) {
func (m *matcher) matchNodeList(state *MatcherState, nodes NodeSlice, partial bool) (matched ast.Node, offset int) {
sliceLen := nodes.Len()
inst := m.nextInst(state)
if inst.op == opEnd {
Expand Down Expand Up @@ -656,7 +655,7 @@ func (m *matcher) matchNodeList(state *MatcherState, nodes NodeSlice, partial bo
stack = stack[:len(stack)-1]
pcNext = 0
jNext = 0
if len(stack) > 0 {
if len(stack) != 0 {
pcNext = stack[len(stack)-1].pc
jNext = stack[len(stack)-1].j
}
Expand Down
4 changes: 2 additions & 2 deletions match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ func TestMatch(t *testing.T) {
{`switch $*x {}`, 1, `switch {}`},
{`switch $*_; b {}`, 1, `switch b := f(); b {}`},
{`switch $*_; b {}`, 0, `switch b := f(); c {}`},
//{`switch $*x {}`, 1, `switch a(); b {}`},
//{`switch $*x {}; switch $*x {}`, 1, `{ switch a(); b {}; switch a(); b {} }`},
// TODO {`switch $*x {}`, 1, `switch a(); b {}`},
// TODO {`switch $*x {}; switch $*x {}`, 1, `{ switch a(); b {}; switch a(); b {} }`},
{`switch $*x {}; switch $*x {}`, 0, `{ switch a(); b {}; switch b {} }`},
{`switch a(); $*_ {}`, 0, `for b {}`},

Expand Down
4 changes: 3 additions & 1 deletion nodetag/nodetag.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nodetag

import "go/ast"
import (
"go/ast"
)

type Value int

Expand Down
4 changes: 3 additions & 1 deletion operation_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@ func tokenize(src []byte) ([]fullToken, error) {
}
toks = append(toks, wt)
if caseStat == caseHere {
toks = append(toks, fullToken{wt.pos, token.COLON, ""})
toks = append(toks, fullToken{wt.pos, token.IDENT, "gogrep_body"})
toks = append(toks,
fullToken{wt.pos, token.COLON, ""},
fullToken{wt.pos, token.IDENT, "gogrep_body"})
}
}
return toks, err
Expand Down Expand Up @@ -341,7 +342,7 @@ func encodeWildName(name string, any bool) string {
func decodeWildName(s string) varInfo {
s = s[len(wildSeparator):]
nameEnd := strings.Index(s, wildSeparator)
name := s[:nameEnd]
name := s[:nameEnd+0]
s = s[nameEnd:]
s = s[len(wildSeparator):]
kind := s
Expand Down

0 comments on commit db4e633

Please sign in to comment.