lint
This commit is contained in:
parent
194b5647ee
commit
14f68cbf8e
|
@ -8,10 +8,21 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrNullReceiver is raised when a null receiver is provided
|
||||||
var ErrNullReceiver = fmt.Errorf("receiver must not be null")
|
var ErrNullReceiver = fmt.Errorf("receiver must not be null")
|
||||||
|
|
||||||
|
// ErrInvalidReceiver is raised when an invalid receiver is provided
|
||||||
var ErrInvalidReceiver = fmt.Errorf("receiver must be compatible with *[]*Line")
|
var ErrInvalidReceiver = fmt.Errorf("receiver must be compatible with *[]*Line")
|
||||||
|
|
||||||
|
// ErrUnexpectedSectionClose is raised when reading a section close '}' without an
|
||||||
|
// open section
|
||||||
var ErrUnexpectedSectionClose = fmt.Errorf("unexpected section close")
|
var ErrUnexpectedSectionClose = fmt.Errorf("unexpected section close")
|
||||||
|
|
||||||
|
// ErrUnclosedSection is raised when there is unclosed sections reaching the end
|
||||||
|
// of the file
|
||||||
var ErrUnclosedSection = fmt.Errorf("unclosed section")
|
var ErrUnclosedSection = fmt.Errorf("unclosed section")
|
||||||
|
|
||||||
|
// ErrInvalidSyntax is raised when a line cannot be understood
|
||||||
var ErrInvalidSyntax = fmt.Errorf("invalid syntax")
|
var ErrInvalidSyntax = fmt.Errorf("invalid syntax")
|
||||||
|
|
||||||
// decoder implements parser.Decoder
|
// decoder implements parser.Decoder
|
||||||
|
@ -62,7 +73,7 @@ func (d *decoder) Decode(v interface{}) error {
|
||||||
|
|
||||||
// 3. get indentation
|
// 3. get indentation
|
||||||
var firstChar int
|
var firstChar int
|
||||||
for firstChar = 0; in_array(" \t", notrim[firstChar]); firstChar++ {
|
for firstChar = 0; inArray(" \t", notrim[firstChar]); firstChar++ {
|
||||||
}
|
}
|
||||||
l.Indent = notrim[0:firstChar]
|
l.Indent = notrim[0:firstChar]
|
||||||
|
|
||||||
|
@ -154,7 +165,7 @@ func (d *decoder) Decode(v interface{}) error {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func in_array(haystack string, needle byte) bool {
|
func inArray(haystack string, needle byte) bool {
|
||||||
for i, l := 0, len(haystack); i < l; i++ {
|
for i, l := 0, len(haystack); i < l; i++ {
|
||||||
if haystack[i] == needle {
|
if haystack[i] == needle {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -137,7 +137,7 @@ func TestNestedSections(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check each component individually
|
// check each component individually
|
||||||
var current []*Line = receiver.Lines
|
current := receiver.Lines
|
||||||
for s, sec := range test.SectionChain {
|
for s, sec := range test.SectionChain {
|
||||||
|
|
||||||
// check that section exists in <current>
|
// check that section exists in <current>
|
||||||
|
|
|
@ -4,18 +4,27 @@ import (
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LineType enumerates available line types
|
||||||
type LineType byte
|
type LineType byte
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NONE LineType = iota
|
// NONE is the default line type (invalid syntax)
|
||||||
COMMENT // # comment
|
NONE LineType = iota
|
||||||
COLONCOMMENT // ; comment
|
// COMMENT represents a #-comment
|
||||||
|
COMMENT
|
||||||
|
// COLONCOMMENT represents a ;-comment
|
||||||
|
COLONCOMMENT
|
||||||
|
// ASSIGNMENT line
|
||||||
ASSIGNMENT
|
ASSIGNMENT
|
||||||
|
// INCLUDE line
|
||||||
INCLUDE
|
INCLUDE
|
||||||
|
// SECTION start
|
||||||
SECTION
|
SECTION
|
||||||
|
// SECTIONEND line '}'
|
||||||
SECTIONEND
|
SECTIONEND
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Line represents a meaningful line
|
||||||
type Line struct {
|
type Line struct {
|
||||||
// Number of the line in the input file
|
// Number of the line in the input file
|
||||||
Number int
|
Number int
|
||||||
|
@ -42,6 +51,7 @@ type nginx struct {
|
||||||
Lines []*Line
|
Lines []*Line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDecoder implements parser.T
|
||||||
func (n *nginx) NewDecoder(r io.Reader) *decoder {
|
func (n *nginx) NewDecoder(r io.Reader) *decoder {
|
||||||
return &decoder{reader: r}
|
return &decoder{reader: r}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,10 @@ import (
|
||||||
osexec "os/exec"
|
osexec "os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Default executor
|
||||||
type Default struct{}
|
type Default struct{}
|
||||||
|
|
||||||
|
// Command implements exec.Executor
|
||||||
func (d *Default) Command(cmd string, args ...string) Command {
|
func (d *Default) Command(cmd string, args ...string) Command {
|
||||||
return osexec.Command(cmd, args...)
|
return osexec.Command(cmd, args...)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue