From 14f68cbf8ed0c2562f8320a663e7207d15cf4d58 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 12 Nov 2018 12:08:54 +0100 Subject: [PATCH] lint --- internal/cnf/parser/nginx/decoder.go | 15 +++++++++++++-- internal/cnf/parser/nginx/decoder_test.go | 2 +- internal/cnf/parser/nginx/nginx.go | 16 +++++++++++++--- internal/exec/os.go | 2 ++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/internal/cnf/parser/nginx/decoder.go b/internal/cnf/parser/nginx/decoder.go index 21f981e..b20c2b5 100644 --- a/internal/cnf/parser/nginx/decoder.go +++ b/internal/cnf/parser/nginx/decoder.go @@ -8,10 +8,21 @@ import ( "strings" ) +// ErrNullReceiver is raised when a null receiver is provided 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") + +// ErrUnexpectedSectionClose is raised when reading a section close '}' without an +// open section 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") + +// ErrInvalidSyntax is raised when a line cannot be understood var ErrInvalidSyntax = fmt.Errorf("invalid syntax") // decoder implements parser.Decoder @@ -62,7 +73,7 @@ func (d *decoder) Decode(v interface{}) error { // 3. get indentation 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] @@ -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++ { if haystack[i] == needle { return true diff --git a/internal/cnf/parser/nginx/decoder_test.go b/internal/cnf/parser/nginx/decoder_test.go index aac16d0..8a3b056 100644 --- a/internal/cnf/parser/nginx/decoder_test.go +++ b/internal/cnf/parser/nginx/decoder_test.go @@ -137,7 +137,7 @@ func TestNestedSections(t *testing.T) { } // check each component individually - var current []*Line = receiver.Lines + current := receiver.Lines for s, sec := range test.SectionChain { // check that section exists in diff --git a/internal/cnf/parser/nginx/nginx.go b/internal/cnf/parser/nginx/nginx.go index 11e9e59..fdbb577 100644 --- a/internal/cnf/parser/nginx/nginx.go +++ b/internal/cnf/parser/nginx/nginx.go @@ -4,18 +4,27 @@ import ( "io" ) +// LineType enumerates available line types type LineType byte const ( - NONE LineType = iota - COMMENT // # comment - COLONCOMMENT // ; comment + // NONE is the default line type (invalid syntax) + NONE LineType = iota + // COMMENT represents a #-comment + COMMENT + // COLONCOMMENT represents a ;-comment + COLONCOMMENT + // ASSIGNMENT line ASSIGNMENT + // INCLUDE line INCLUDE + // SECTION start SECTION + // SECTIONEND line '}' SECTIONEND ) +// Line represents a meaningful line type Line struct { // Number of the line in the input file Number int @@ -42,6 +51,7 @@ type nginx struct { Lines []*Line } +// NewDecoder implements parser.T func (n *nginx) NewDecoder(r io.Reader) *decoder { return &decoder{reader: r} } diff --git a/internal/exec/os.go b/internal/exec/os.go index 969385a..b1f9f51 100644 --- a/internal/exec/os.go +++ b/internal/exec/os.go @@ -4,8 +4,10 @@ import ( osexec "os/exec" ) +// Default executor type Default struct{} +// Command implements exec.Executor func (d *Default) Command(cmd string, args ...string) Command { return osexec.Command(cmd, args...) }