@@ -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,33 @@ 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
96
97
- line := scanner .Text ()
98
- line = strings .ReplaceAll (line , "\t " , tabSpaces )
99
-
100
- if strings .HasPrefix (line , goCommentDirectivePrefix ) {
97
+ if bytes .HasPrefix (line , goCommentDirectivePrefix ) {
101
98
continue
102
99
}
103
100
104
- if strings .HasPrefix (line , "import" ) {
105
- multiImportEnabled = strings .HasSuffix (line , "(" )
101
+ if bytes .HasPrefix (line , [] byte ( "import" ) ) {
102
+ multiImportEnabled = bytes .HasSuffix (line , [] byte { '(' } )
106
103
continue
107
104
}
108
105
109
106
if multiImportEnabled {
110
- if line == ")" {
107
+ if bytes . Equal ( line , [] byte { ')' }) {
111
108
multiImportEnabled = false
112
109
}
113
110
114
111
continue
115
112
}
116
113
117
- lineLen := utf8 .RuneCountInString (line )
114
+ line = bytes .ReplaceAll (line , []byte {'\t' }, tabSpaces )
115
+
116
+ lineLen := utf8 .RuneCount (line )
118
117
if lineLen > maxLineLen {
119
118
res = append (res , result.Issue {
120
119
Pos : token.Position {
0 commit comments