1
0
mirror of https://github.com/mgechev/revive.git synced 2025-03-17 20:57:58 +02:00

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
This commit is contained in:
Minko Gechev 2018-07-08 08:14:15 +10:00 committed by GitHub
parent c2e2dbac85
commit f966283f3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 3 deletions

View File

@ -3,4 +3,4 @@ language: go
go: "1.10.x"
install: make install
script: make build && make test.all
script: make build && make test

View File

@ -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/...

View File

@ -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/

View File

@ -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