@@ -13,30 +13,33 @@ var DefaultLocations = [...]string{"CODEOWNERS", "docs/CODEOWNERS", ".github/COD
1313// Decoder providers functionality to read CODEOWNERS data
1414type Decoder struct {
1515 scanner * bufio.Scanner
16- line * string
16+ line string
1717 done bool
1818}
1919
20- // New generates a new CodeOwnersScanner instance. The reader should be a reader containing the contents of the CODEOWNERS file
21- func New (r io.Reader ) * Decoder {
20+ // NewDecoder generates a new CodeOwnersScanner instance. The reader should be a reader containing the contents of the CODEOWNERS file
21+ func NewDecoder (r io.Reader ) * Decoder {
2222 return & Decoder {
2323 scanner : bufio .NewScanner (r ),
24- line : nil ,
24+ line : "" ,
2525 done : false ,
2626 }
2727}
2828
29+ // peek will scan the next line
2930func (s * Decoder ) peek () {
3031 if ! s .scanner .Scan () {
3132 s .done = true
33+ return
3234 }
3335 line := sanitiseLine (s .scanner .Text ())
34- s .line = & line
35- if len (* s .line ) == 0 && ! s .done {
36+ s .line = line
37+ if len (s .line ) == 0 && ! s .done {
3638 s .peek ()
3739 }
3840}
3941
42+ // sanitiseLine removes all empty space and comments from a given line
4043func sanitiseLine (line string ) string {
4144 i := strings .Index (line , "#" )
4245 if i >= 0 {
@@ -45,15 +48,18 @@ func sanitiseLine(line string) string {
4548 return strings .Trim (line , " " )
4649}
4750
48- // More returns if there are available CODEOWNERS lines to be scanned
51+ // More returns true if there are available CODEOWNERS lines to be scanned.
52+ // And also advances to the next line.
4953func (s * Decoder ) More () bool {
5054 s .peek ()
5155 return ! s .done
5256}
5357
54- // Token parses the next available line in the CODEOWNERS file
58+ // Token parses the next available line in the CODEOWNERS file.
59+ // If More was never called it will return an empty token.
60+ // After end of file Token will always return the last line.
5561func (s * Decoder ) Token () Token {
56- line := strings .ReplaceAll (* s .line , "\\ " , "\\ s" )
62+ line := strings .ReplaceAll (s .line , "\\ " , "\\ s" )
5763
5864 data := strings .Split (line , " " )
5965
0 commit comments