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:
parent
c2e2dbac85
commit
f966283f3e
@ -3,4 +3,4 @@ language: go
|
||||
go: "1.10.x"
|
||||
|
||||
install: make install
|
||||
script: make build && make test.all
|
||||
script: make build && make test
|
||||
|
4
Makefile
4
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/...
|
||||
|
||||
|
15
fixtures/golint/exported.go
Normal file
15
fixtures/golint/exported.go
Normal 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/
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user