From f966283f3eafb48e4dc64587db3559531082a310 Mon Sep 17 00:00:00 2001 From: Minko Gechev Date: Sun, 8 Jul 2018 08:14:15 +1000 Subject: [PATCH] Fix rule for documentation of exported types (#29) * Fix rule for documentation of exported types The rule was failing in the following case: ```go // A is an awesome type type A = int ``` Because revive was skipping the leading `A`, considering it as an article. * Add "This" article and update Makefile --- .travis.yml | 2 +- Makefile | 4 +++- fixtures/golint/exported.go | 15 +++++++++++++++ rule/exported.go | 5 ++++- 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 fixtures/golint/exported.go diff --git a/.travis.yml b/.travis.yml index 625ef4a..c10f5a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,4 @@ language: go go: "1.10.x" install: make install -script: make build && make test.all +script: make build && make test diff --git a/Makefile b/Makefile index 0fafbe7..6faa8aa 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +.PHONY: test + deps.devtools: @go get github.com/golang/dep/cmd/dep @@ -7,6 +9,6 @@ install: deps.devtools build: @go build -test.all: +test: @go test -v ./test/... diff --git a/fixtures/golint/exported.go b/fixtures/golint/exported.go new file mode 100644 index 0000000..fb2880e --- /dev/null +++ b/fixtures/golint/exported.go @@ -0,0 +1,15 @@ +// Package golint comment +package golint + +type ( + // O is a shortcut (alias) for map[string]interface{}, e.g. a JSON object. + O = map[string]interface{} + + // A is shortcut for []O. + A = []O + + // This Person type is simple + Person = map[string]interface{} +) + +type Foo struct{} // MATCH /exported type Foo should have comment or be unexported/ diff --git a/rule/exported.go b/rule/exported.go index bb95599..1bf2e48 100644 --- a/rule/exported.go +++ b/rule/exported.go @@ -146,8 +146,11 @@ func (w *lintExported) lintTypeDoc(t *ast.TypeSpec, doc *ast.CommentGroup) { } s := doc.Text() - articles := [...]string{"A", "An", "The"} + articles := [...]string{"A", "An", "The", "This"} for _, a := range articles { + if t.Name.Name == a { + continue + } if strings.HasPrefix(s, a+" ") { s = s[len(a)+1:] break