Skip to content

Commit

Permalink
Merge branch 'master' into use-acmd
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Jan 26, 2022
2 parents 5e2731b + 352ed07 commit 62704a2
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
run: |
make ci-linter
- name: Precompiled
run: |
make ci-generate
- name: Test
run: |
make ci-tests
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ docs:
cd ./cmd/makedocs && go run main.go

ci:
@if [ "$(TEST_SUITE)" = "linter" ]; then make ci-linter; else make ci-tidy; make ci-tests; fi
@if [ "$(TEST_SUITE)" = "linter" ]; then make ci-linter; else make ci-tidy; make ci-generate; make ci-tests; fi

ci-tidy:
go mod tidy
Expand All @@ -35,6 +35,10 @@ ci-tidy:
ci-tests:
GOCRITIC_EXTERNAL_TESTS=1 go test -v -race -count=1 -coverprofile=coverage.out ./...

ci-generate:
go generate ./...
git diff --exit-code --quiet || (echo "Please run 'go generate ./...' to update precompiled rules."; false)

ci-linter:
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH_DIR)/bin v1.30.0
@$(GOPATH_DIR)/bin/golangci-lint run -v
Expand Down
10 changes: 10 additions & 0 deletions checkers/testdata/todoCommentWithoutDetail/negative_tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package checker_test

func ExampleFoo() {
// TODO: something important
// TODO(jim)
// FIX fix this
// FIXME(bob)
// TODO this
// BUG: oh no this is broken
}
16 changes: 16 additions & 0 deletions checkers/testdata/todoCommentWithoutDetail/positive_tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package checker_test

func singleLineCode() {

/*! may want to add detail/assignee to this TODO/FIXME/BUG comment */
// TODO

/*! may want to add detail/assignee to this TODO/FIXME/BUG comment */
// FIX

/*! may want to add detail/assignee to this TODO/FIXME/BUG comment */
// FIXME

/*! may want to add detail/assignee to this TODO/FIXME/BUG comment */
// BUG
}
50 changes: 50 additions & 0 deletions checkers/todoCommentWithoutDetail_checker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package checkers

import (
"go/ast"
"regexp"

"github.com/go-critic/go-critic/checkers/internal/astwalk"
"github.com/go-critic/go-critic/framework/linter"
)

func init() {
var info linter.CheckerInfo
info.Name = "todoCommentWithoutDetail"
info.Tags = []string{"style", "opinionated", "experimental"}
info.Summary = "Detects TODO comments without detail/assignee"
info.Before = `
// TODO
fiiWithCtx(nil, a, b)
`
info.After = `
// TODO(admin): pass context.TODO() instead of nil
fiiWithCtx(nil, a, b)
`
collection.AddChecker(&info, func(ctx *linter.CheckerContext) (linter.FileWalker, error) {
visitor := &todoCommentWithoutCodeChecker{
ctx: ctx,
regex: regexp.MustCompile(`^(//|/\*)?\s*(TODO|FIX|FIXME|BUG)\s*(\*/)?$`),
}
return astwalk.WalkerForComment(visitor), nil
})
}

type todoCommentWithoutCodeChecker struct {
astwalk.WalkHandler
ctx *linter.CheckerContext
regex *regexp.Regexp
}

func (c *todoCommentWithoutCodeChecker) VisitComment(cg *ast.CommentGroup) {
for _, comment := range cg.List {
if c.regex.MatchString(comment.Text) {
c.warn(cg)
break
}
}
}

func (c *todoCommentWithoutCodeChecker) warn(cause ast.Node) {
c.ctx.Warn(cause, "may want to add detail/assignee to this TODO/FIXME/BUG comment")
}

0 comments on commit 62704a2

Please sign in to comment.