@@ -2,11 +2,11 @@ package lll
22
33import (
44 "bufio"
5+ "bytes"
56 "errors"
67 "fmt"
78 "go/token"
89 "os"
9- "strings"
1010 "sync"
1111 "unicode/utf8"
1212
@@ -21,7 +21,7 @@ import (
2121
2222const linterName = "lll"
2323
24- const goCommentDirectivePrefix = "//go:"
24+ var goCommentDirectivePrefix = [] byte ( "//go:" )
2525
2626func New (settings * config.LllSettings ) * goanalysis.Linter {
2727 var mu sync.Mutex
@@ -61,7 +61,7 @@ func New(settings *config.LllSettings) *goanalysis.Linter {
6161func runLll (pass * analysis.Pass , settings * config.LllSettings ) ([]goanalysis.Issue , error ) {
6262 fileNames := internal .GetFileNames (pass )
6363
64- spaces := strings .Repeat (" " , settings .TabWidth )
64+ spaces := bytes .Repeat ([] byte { ' ' } , settings .TabWidth )
6565
6666 var issues []goanalysis.Issue
6767 for _ , f := range fileNames {
@@ -78,7 +78,7 @@ func runLll(pass *analysis.Pass, settings *config.LllSettings) ([]goanalysis.Iss
7878 return issues , nil
7979}
8080
81- func getLLLIssuesForFile (filename string , maxLineLen int , tabSpaces string ) ([]result.Issue , error ) {
81+ func getLLLIssuesForFile (filename string , maxLineLen int , tabSpaces [] byte ) ([]result.Issue , error ) {
8282 var res []result.Issue
8383
8484 f , err := os .Open (filename )
@@ -87,34 +87,32 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r
8787 }
8888 defer f .Close ()
8989
90- lineNumber := 0
90+ lineNumber := 1
9191 multiImportEnabled := false
9292
9393 scanner := bufio .NewScanner (f )
94- for scanner .Scan () {
95- lineNumber ++
94+ for ; scanner .Scan (); lineNumber ++ {
95+ line := scanner .Bytes ()
96+ line = bytes .ReplaceAll (line , []byte {'\t' }, tabSpaces )
9697
97- line := scanner .Text ()
98- line = strings .ReplaceAll (line , "\t " , tabSpaces )
99-
100- if strings .HasPrefix (line , goCommentDirectivePrefix ) {
98+ if bytes .HasPrefix (line , goCommentDirectivePrefix ) {
10199 continue
102100 }
103101
104- if strings .HasPrefix (line , "import" ) {
105- multiImportEnabled = strings .HasSuffix (line , "(" )
102+ if bytes .HasPrefix (line , [] byte ( "import" ) ) {
103+ multiImportEnabled = bytes .HasSuffix (line , [] byte { '(' } )
106104 continue
107105 }
108106
109107 if multiImportEnabled {
110- if line == ")" {
108+ if bytes . Equal ( line , [] byte { ')' }) {
111109 multiImportEnabled = false
112110 }
113111
114112 continue
115113 }
116114
117- lineLen := utf8 .RuneCountInString (line )
115+ lineLen := utf8 .RuneCount (line )
118116 if lineLen > maxLineLen {
119117 res = append (res , result.Issue {
120118 Pos : token.Position {
0 commit comments