@@ -2,11 +2,11 @@ package lll
2
2
3
3
import (
4
4
"bufio"
5
+ "bytes"
5
6
"errors"
6
7
"fmt"
7
8
"go/token"
8
9
"os"
9
- "strings"
10
10
"sync"
11
11
"unicode/utf8"
12
12
@@ -21,7 +21,7 @@ import (
21
21
22
22
const linterName = "lll"
23
23
24
- const goCommentDirectivePrefix = "//go:"
24
+ var goCommentDirectivePrefix = [] byte ( "//go:" )
25
25
26
26
func New (settings * config.LllSettings ) * goanalysis.Linter {
27
27
var mu sync.Mutex
@@ -61,7 +61,7 @@ func New(settings *config.LllSettings) *goanalysis.Linter {
61
61
func runLll (pass * analysis.Pass , settings * config.LllSettings ) ([]goanalysis.Issue , error ) {
62
62
fileNames := internal .GetFileNames (pass )
63
63
64
- spaces := strings .Repeat (" " , settings .TabWidth )
64
+ spaces := bytes .Repeat ([] byte { ' ' } , settings .TabWidth )
65
65
66
66
var issues []goanalysis.Issue
67
67
for _ , f := range fileNames {
@@ -78,7 +78,7 @@ func runLll(pass *analysis.Pass, settings *config.LllSettings) ([]goanalysis.Iss
78
78
return issues , nil
79
79
}
80
80
81
- func getLLLIssuesForFile (filename string , maxLineLen int , tabSpaces string ) ([]result.Issue , error ) {
81
+ func getLLLIssuesForFile (filename string , maxLineLen int , tabSpaces [] byte ) ([]result.Issue , error ) {
82
82
var res []result.Issue
83
83
84
84
f , err := os .Open (filename )
@@ -87,34 +87,32 @@ func getLLLIssuesForFile(filename string, maxLineLen int, tabSpaces string) ([]r
87
87
}
88
88
defer f .Close ()
89
89
90
- lineNumber := 0
90
+ lineNumber := 1
91
91
multiImportEnabled := false
92
92
93
93
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 )
96
97
97
- line := scanner .Text ()
98
- line = strings .ReplaceAll (line , "\t " , tabSpaces )
99
-
100
- if strings .HasPrefix (line , goCommentDirectivePrefix ) {
98
+ if bytes .HasPrefix (line , goCommentDirectivePrefix ) {
101
99
continue
102
100
}
103
101
104
- if strings .HasPrefix (line , "import" ) {
105
- multiImportEnabled = strings .HasSuffix (line , "(" )
102
+ if bytes .HasPrefix (line , [] byte ( "import" ) ) {
103
+ multiImportEnabled = bytes .HasSuffix (line , [] byte { '(' } )
106
104
continue
107
105
}
108
106
109
107
if multiImportEnabled {
110
- if line == ")" {
108
+ if bytes . Equal ( line , [] byte { ')' }) {
111
109
multiImportEnabled = false
112
110
}
113
111
114
112
continue
115
113
}
116
114
117
- lineLen := utf8 .RuneCountInString (line )
115
+ lineLen := utf8 .RuneCount (line )
118
116
if lineLen > maxLineLen {
119
117
res = append (res , result.Issue {
120
118
Pos : token.Position {
0 commit comments