Code linted.
diff --git a/etree.go b/etree.go
index cb7e4e5..d7f0ffb 100644
--- a/etree.go
+++ b/etree.go
@@ -17,11 +17,15 @@
)
const (
- NoIndent = -1 // Use with Indent to turn off indenting
+ // NoIndent is used with Indent to disable all indenting.
+ NoIndent = -1
)
var (
- ErrXml = errors.New("etree: invalid XML format")
+ // ErrXML is returned when XML parsing fails due to incorrect formatting.
+ ErrXML = errors.New("etree: invalid XML format")
+
+ // ErrPath is returned when an invalid etree path is provided.
ErrPath = errors.New("etree: invalid path")
)
@@ -89,8 +93,8 @@
}
// Copy returns a recursive, deep copy of the document.
-func (doc *Document) Copy() *Document {
- return &Document{*(doc.dup(nil).(*Element))}
+func (d *Document) Copy() *Document {
+ return &Document{*(d.dup(nil).(*Element))}
}
// Root returns the root element of the document, or nil if there is no root
@@ -110,7 +114,7 @@
return d.Element.readFrom(r)
}
-// ReadFromString reads XML from the string s into the document d.
+// ReadFromFile reads XML from the string s into the document d.
func (d *Document) ReadFromFile(filename string) error {
f, err := os.Open(filename)
if err != nil {
@@ -285,7 +289,7 @@
case err != nil:
return r.bytes, err
case stack.empty():
- return r.bytes, ErrXml
+ return r.bytes, ErrXML
}
top := stack.peek().(*Element)
@@ -341,7 +345,7 @@
// ChildElements returns all elements that are children of the
// receiving element.
func (e *Element) ChildElements() []*Element {
- elements := make([]*Element, 0)
+ var elements []*Element
for _, t := range e.Child {
if c, ok := t.(*Element); ok {
elements = append(elements, c)
@@ -366,7 +370,7 @@
// The tag may be prefixed by a namespace and a colon.
func (e *Element) SelectElements(tag string) []*Element {
space, stag := spaceDecompose(tag)
- elements := make([]*Element, 0)
+ var elements []*Element
for _, t := range e.Child {
if c, ok := t.(*Element); ok && spaceMatch(space, c.Space) && stag == c.Tag {
elements = append(elements, c)
diff --git a/helpers.go b/helpers.go
index 1460626..f3b0256 100644
--- a/helpers.go
+++ b/helpers.go
@@ -57,9 +57,8 @@
func (f *fifo) len() int {
if f.tail >= f.head {
return f.tail - f.head
- } else {
- return len(f.data) - f.head + f.tail
}
+ return len(f.data) - f.head + f.tail
}
func (f *fifo) grow() {
diff --git a/path.go b/path.go
index 4ae9b3b..f0c792a 100644
--- a/path.go
+++ b/path.go
@@ -180,7 +180,7 @@
}
// Split path into segment objects
- segments := make([]segment, 0)
+ var segments []segment
for _, s := range strings.Split(path, "/") {
segments = append(segments, c.parseSegment(s))
if c.err != nil {
diff --git a/path_test.go b/path_test.go
index d0f6620..2a52f0e 100644
--- a/path_test.go
+++ b/path_test.go
@@ -8,7 +8,7 @@
"testing"
)
-var testXml string = `
+var testXML = `
<?xml version="1.0" encoding="UTF-8"?>
<bookstore xmlns:p="urn:books-com:prices">
@@ -115,7 +115,7 @@
func TestPath(t *testing.T) {
doc := NewDocument()
- err := doc.ReadFromString(testXml)
+ err := doc.ReadFromString(testXML)
if err != nil {
t.Error(err)
}