mirror of
https://github.com/mgechev/revive.git
synced 2024-11-24 08:32:22 +02:00
parent
fa5acbc1f0
commit
84deee4163
@ -13,3 +13,23 @@ type (
|
||||
)
|
||||
|
||||
type Foo struct{} // MATCH /exported type Foo should have comment or be unexported/
|
||||
|
||||
// The following cases are no-regression tests for issue 229
|
||||
|
||||
/* Bar something */
|
||||
type Bar struct{}
|
||||
|
||||
/* Toto something */
|
||||
func Toto() {}
|
||||
|
||||
/* FirstLetter something */
|
||||
const FirstLetter = "A"
|
||||
|
||||
/*Bar2 something */
|
||||
type Bar2 struct{}
|
||||
|
||||
/*Toto2 something */
|
||||
func Toto2() {}
|
||||
|
||||
/*SecondLetter something */
|
||||
const SecondLetter = "B"
|
||||
|
@ -85,7 +85,7 @@ func (w *lintExported) lintFuncDoc(fn *ast.FuncDecl) {
|
||||
})
|
||||
return
|
||||
}
|
||||
s := fn.Doc.Text()
|
||||
s := normalizeText(fn.Doc.Text())
|
||||
prefix := fn.Name.Name + " "
|
||||
if !strings.HasPrefix(s, prefix) {
|
||||
w.onFailure(lint.Failure{
|
||||
@ -141,7 +141,7 @@ func (w *lintExported) lintTypeDoc(t *ast.TypeSpec, doc *ast.CommentGroup) {
|
||||
return
|
||||
}
|
||||
|
||||
s := doc.Text()
|
||||
s := normalizeText(doc.Text())
|
||||
articles := [...]string{"A", "An", "The", "This"}
|
||||
for _, a := range articles {
|
||||
if t.Name.Name == a {
|
||||
@ -217,7 +217,8 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD
|
||||
doc = gd.Doc
|
||||
}
|
||||
prefix := name + " "
|
||||
if !strings.HasPrefix(doc.Text(), prefix) {
|
||||
s := normalizeText(doc.Text())
|
||||
if !strings.HasPrefix(s, prefix) {
|
||||
w.onFailure(lint.Failure{
|
||||
Confidence: 1,
|
||||
Node: doc,
|
||||
@ -227,6 +228,14 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD
|
||||
}
|
||||
}
|
||||
|
||||
// normalizeText is a helper function that normalizes comment strings by:
|
||||
// * removing one leading space
|
||||
//
|
||||
// This function is needed because ast.CommentGroup.Text() does not handle //-style and /*-style comments uniformly
|
||||
func normalizeText(t string) string {
|
||||
return strings.TrimPrefix(t, " ")
|
||||
}
|
||||
|
||||
func (w *lintExported) Visit(n ast.Node) ast.Visitor {
|
||||
switch v := n.(type) {
|
||||
case *ast.GenDecl:
|
||||
|
Loading…
Reference in New Issue
Block a user