Jelajahi Sumber

refactor(misc): fix a handful of TODO

jvoisin 8 bulan lalu
induk
melakukan
485baf9654

+ 0 - 5
internal/reader/atom/atom_03_adapter.go

@@ -18,11 +18,6 @@ type atom03Adapter struct {
 	atomFeed *atom03Feed
 }
 
-// TODO No need for a constructor, as it's only used in this package
-func NewAtom03Adapter(atomFeed *atom03Feed) *atom03Adapter {
-	return &atom03Adapter{atomFeed}
-}
-
 func (a *atom03Adapter) buildFeed(baseURL string) *model.Feed {
 	feed := new(model.Feed)
 

+ 5 - 5
internal/reader/atom/atom_10_adapter.go

@@ -18,15 +18,15 @@ import (
 	"miniflux.app/v2/internal/urllib"
 )
 
-type Atom10Adapter struct {
+type atom10Adapter struct {
 	atomFeed *atom10Feed
 }
 
-func NewAtom10Adapter(atomFeed *atom10Feed) *Atom10Adapter {
-	return &Atom10Adapter{atomFeed}
+func NewAtom10Adapter(atomFeed *atom10Feed) *atom10Adapter {
+	return &atom10Adapter{atomFeed}
 }
 
-func (a *Atom10Adapter) BuildFeed(baseURL string) *model.Feed {
+func (a *atom10Adapter) BuildFeed(baseURL string) *model.Feed {
 	feed := new(model.Feed)
 
 	// Populate the feed URL.
@@ -72,7 +72,7 @@ func (a *Atom10Adapter) BuildFeed(baseURL string) *model.Feed {
 	return feed
 }
 
-func (a *Atom10Adapter) populateEntries(siteURL string) model.Entries {
+func (a *atom10Adapter) populateEntries(siteURL string) model.Entries {
 	entries := make(model.Entries, 0, len(a.atomFeed.Entries))
 
 	for _, atomEntry := range a.atomFeed.Entries {

+ 4 - 2
internal/reader/atom/parser.go

@@ -19,12 +19,14 @@ func Parse(baseURL string, r io.ReadSeeker, version string) (*model.Feed, error)
 		if err := xml_decoder.NewXMLDecoder(r).Decode(atomFeed); err != nil {
 			return nil, fmt.Errorf("atom: unable to parse Atom 0.3 feed: %w", err)
 		}
-		return NewAtom03Adapter(atomFeed).buildFeed(baseURL), nil
+		adapter := &atom03Adapter{atomFeed}
+		return adapter.buildFeed(baseURL), nil
 	default:
 		atomFeed := new(atom10Feed)
 		if err := xml_decoder.NewXMLDecoder(r).Decode(atomFeed); err != nil {
 			return nil, fmt.Errorf("atom: unable to parse Atom 1.0 feed: %w", err)
 		}
-		return NewAtom10Adapter(atomFeed).BuildFeed(baseURL), nil
+		adapter := &atom10Adapter{atomFeed}
+		return adapter.BuildFeed(baseURL), nil
 	}
 }

+ 0 - 5
internal/reader/opml/opml.go

@@ -16,11 +16,6 @@ type opmlDocument struct {
 	Outlines opmlOutlineCollection `xml:"body>outline"`
 }
 
-// TODO remove as this is only used in the opml package
-func NewOPMLDocument() *opmlDocument {
-	return &opmlDocument{}
-}
-
 type opmlHeader struct {
 	Title       string `xml:"title,omitempty"`
 	DateCreated string `xml:"dateCreated,omitempty"`

+ 1 - 1
internal/reader/opml/parser.go

@@ -13,7 +13,7 @@ import (
 
 // parse reads an OPML file and returns a SubcriptionList.
 func parse(data io.Reader) (subcriptionList, error) {
-	opmlDocument := NewOPMLDocument()
+	opmlDocument := &opmlDocument{}
 	decoder := xml.NewDecoder(data)
 	decoder.Entity = xml.HTMLEntity
 	decoder.Strict = false

+ 1 - 1
internal/reader/opml/serializer.go

@@ -32,7 +32,7 @@ func serialize(subscriptions subcriptionList) string {
 }
 
 func convertSubscriptionsToOPML(subscriptions subcriptionList) *opmlDocument {
-	opmlDocument := NewOPMLDocument()
+	opmlDocument := &opmlDocument{}
 	opmlDocument.Version = "2.0"
 	opmlDocument.Header.Title = "Miniflux"
 	opmlDocument.Header.DateCreated = time.Now().Format("Mon, 02 Jan 2006 15:04:05 MST")

+ 0 - 7
internal/reader/sanitizer/sanitizer.go

@@ -197,13 +197,6 @@ type SanitizerOptions struct {
 	OpenLinksInNewTab bool
 }
 
-// TODO: replace with SanitizeHTML, as it's only used in tests.
-func sanitizeHTMLWithDefaultOptions(baseURL, rawHTML string) string {
-	return SanitizeHTML(baseURL, rawHTML, &SanitizerOptions{
-		OpenLinksInNewTab: true,
-	})
-}
-
 func SanitizeHTML(baseURL, rawHTML string, sanitizerOptions *SanitizerOptions) string {
 	var tagStack []string
 	var parentTag string

+ 6 - 0
internal/reader/sanitizer/sanitizer_test.go

@@ -13,6 +13,12 @@ import (
 	"miniflux.app/v2/internal/config"
 )
 
+func sanitizeHTMLWithDefaultOptions(baseURL, rawHTML string) string {
+	return SanitizeHTML(baseURL, rawHTML, &SanitizerOptions{
+		OpenLinksInNewTab: true,
+	})
+}
+
 func BenchmarkSanitize(b *testing.B) {
 	var testCases = map[string][]string{
 		"miniflux_github.html":    {"https://github.com/miniflux/v2", ""},

+ 1 - 1
internal/reader/xml/decoder.go

@@ -88,7 +88,7 @@ func filterValidXMLChar(r rune) rune {
 
 // This function is copied from encoding/xml's procInst and adapted for []bytes instead of string
 func getEncoding(b []byte) string {
-	// TODO: this parsing is somewhat lame and not exact.
+	// This parsing is somewhat lame and not exact.
 	// It works for all actual cases, though.
 	idx := bytes.Index(b, []byte("encoding="))
 	if idx == -1 {