mirror of
				https://github.com/mgechev/revive.git
				synced 2025-10-30 23:37:49 +02:00 
			
		
		
		
	| @@ -251,7 +251,7 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if vs.Doc == nil && gd.Doc == nil { | ||||
| 	if vs.Doc == nil && vs.Comment == nil && gd.Doc == nil { | ||||
| 		if genDeclMissingComments[gd] { | ||||
| 			return | ||||
| 		} | ||||
| @@ -274,10 +274,16 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD | ||||
| 	} | ||||
| 	// The relevant text to check will be on either vs.Doc or gd.Doc. | ||||
| 	// Use vs.Doc preferentially. | ||||
| 	doc := vs.Doc | ||||
| 	if doc == nil { | ||||
| 	var doc *ast.CommentGroup | ||||
| 	switch { | ||||
| 	case vs.Doc != nil: | ||||
| 		doc = vs.Doc | ||||
| 	case vs.Comment != nil && gd.Doc == nil: | ||||
| 		doc = vs.Comment | ||||
| 	default: | ||||
| 		doc = gd.Doc | ||||
| 	} | ||||
|  | ||||
| 	prefix := name + " " | ||||
| 	s := normalizeText(doc.Text()) | ||||
| 	if !strings.HasPrefix(s, prefix) { | ||||
|   | ||||
							
								
								
									
										12
									
								
								testdata/golint/const-block.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								testdata/golint/const-block.go
									
									
									
									
										vendored
									
									
								
							| @@ -4,11 +4,14 @@ | ||||
| package foo | ||||
|  | ||||
| const ( | ||||
| 	InlineComment = "ShouldBeOK" // InlineComment is a valid comment | ||||
|  | ||||
| 	// Prefix for something. | ||||
| 	// MATCH /comment on exported const InlineWhatever should be of the form "InlineWhatever ..."/ | ||||
| 	InlineWhatever = "blah" | ||||
|  | ||||
| 	Whatsit = "missing_comment" // MATCH /exported const Whatsit should have comment (or a comment on this block) or be unexported/ | ||||
| 	Whatsit = "missing_comment" | ||||
| 	// MATCH:13 /exported const Whatsit should have comment (or a comment on this block) or be unexported/ | ||||
|  | ||||
| 	// We should only warn once per block for missing comments, | ||||
| 	// but always complain about malformed comments. | ||||
| @@ -29,8 +32,11 @@ const ( | ||||
|  | ||||
| // The comment on the previous const block shouldn't flow through to here. | ||||
|  | ||||
| const UndocAgain = 6 // MATCH /exported const UndocAgain should have comment or be unexported/ | ||||
| const UndocAgain = 6 | ||||
|  | ||||
| // MATCH:35 /exported const UndocAgain should have comment or be unexported/ | ||||
|  | ||||
| const ( | ||||
| 	SomeUndocumented = 7 // MATCH /exported const SomeUndocumented should have comment (or a comment on this block) or be unexported/ | ||||
| 	SomeUndocumented = 7 | ||||
| 	// MATCH:40 /exported const SomeUndocumented should have comment (or a comment on this block) or be unexported/ | ||||
| ) | ||||
|   | ||||
							
								
								
									
										4
									
								
								testdata/golint/error-naming.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								testdata/golint/error-naming.go
									
									
									
									
										vendored
									
									
								
							| @@ -11,7 +11,9 @@ import ( | ||||
| var unexp = errors.New("some unexported error") // MATCH /error var unexp should have name of the form errFoo/ | ||||
|  | ||||
| // Exp ... | ||||
| var Exp = errors.New("some exported error") // MATCH /error var Exp should have name of the form ErrFoo/ | ||||
| var Exp = errors.New("some exported error") | ||||
|  | ||||
| // MATCH:14 /error var Exp should have name of the form ErrFoo/ | ||||
|  | ||||
| var ( | ||||
| 	e1 = fmt.Errorf("blah %d", 4) // MATCH /error var e1 should have name of the form errFoo/ | ||||
|   | ||||
							
								
								
									
										15
									
								
								testdata/golint/value-spec.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								testdata/golint/value-spec.go
									
									
									
									
										vendored
									
									
								
							| @@ -24,15 +24,22 @@ type V string | ||||
|  | ||||
| func (*V) H() {} // MATCH /exported method V.H should have comment or be unexported/ | ||||
|  | ||||
| var W = "foo" // MATCH /exported var W should have comment or be unexported/ | ||||
| var W = "foo" | ||||
|  | ||||
| const X = "bar" // MATCH /exported const X should have comment or be unexported/ | ||||
| // MATCH:27 /exported var W should have comment or be unexported/ | ||||
|  | ||||
| var Y, Z int // MATCH /exported var Z should have its own declaration/ | ||||
| const X = "bar" | ||||
|  | ||||
| // MATCH:31 /exported const X should have comment or be unexported/ | ||||
|  | ||||
| var Y, Z int | ||||
|  | ||||
| // MATCH:35 /exported var Z should have its own declaration/ | ||||
|  | ||||
| // Location should be okay, since the other var name is an underscore. | ||||
| var Location, _ = time.LoadLocation("Europe/Istanbul") // not Constantinople | ||||
|  | ||||
| // this is improperly documented | ||||
| // MATCH /comment on exported const Thing should be of the form "Thing ..."/ | ||||
| const Thing = "wonderful" | ||||
|  | ||||
| // MATCH:42 /comment on exported const Thing should be of the form "Thing ..."/ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user