@@ -26,7 +26,7 @@ type Needs uint
2626
2727const commentMark = "//"
2828
29- var commentPattern = regexp .MustCompile (`^// \s*( nolint)(:\s*[\w-]+\s*(?:,\s*[\w-]+\s*)*)?\b` )
29+ var commentPattern = regexp .MustCompile (`^(//( \s*) nolint)(?: :\s*[\w-]+\s*(?:,\s*[\w-]+\s*)*)?\b` )
3030
3131// matches a complete nolint directive
3232var fullDirectivePattern = regexp .MustCompile (`^//\s*nolint(?::(\s*[\w-]+\s*(?:,\s*[\w-]+\s*)*))?\s*(//.*)?\s*\n?$` )
@@ -49,10 +49,7 @@ func NewLinter(needs Needs, excludes []string) (*Linter, error) {
4949 }, nil
5050}
5151
52- var (
53- leadingSpacePattern = regexp .MustCompile (`^//(\s*)` )
54- trailingBlankExplanation = regexp .MustCompile (`\s*(//\s*)?$` )
55- )
52+ var trailingBlankExplanation = regexp .MustCompile (`\s*(//\s*)?$` )
5653
5754//nolint:funlen,gocyclo // the function is going to be refactored in the future
5855func (l Linter ) Run (pass * analysis.Pass ) ([]goanalysis.Issue , error ) {
@@ -61,25 +58,13 @@ func (l Linter) Run(pass *analysis.Pass) ([]goanalysis.Issue, error) {
6158 for _ , file := range pass .Files {
6259 for _ , c := range file .Comments {
6360 for _ , comment := range c .List {
64- if ! commentPattern .MatchString (comment .Text ) {
61+ m := commentPattern .FindStringSubmatch (comment .Text )
62+ if m == nil {
6563 continue
6664 }
6765
68- // check for a space between the "//" and the directive
69- leadingSpaceMatches := leadingSpacePattern .FindStringSubmatch (comment .Text )
70-
71- var leadingSpace string
72- if len (leadingSpaceMatches ) > 0 {
73- leadingSpace = leadingSpaceMatches [1 ]
74- }
75-
76- directiveWithOptionalLeadingSpace := commentMark
77- if leadingSpace != "" {
78- directiveWithOptionalLeadingSpace += " "
79- }
80-
81- split := strings .Split (strings .SplitN (comment .Text , ":" , 2 )[0 ], commentMark )
82- directiveWithOptionalLeadingSpace += strings .TrimSpace (split [1 ])
66+ directiveWithOptionalLeadingSpace := m [1 ]
67+ leadingSpace := m [2 ]
8368
8469 pos := pass .Fset .Position (comment .Pos ())
8570 end := pass .Fset .Position (comment .End ())
0 commit comments