From 1569a6b053112a2f3607eb55a9979f05e5081850 Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Tue, 22 Feb 2022 22:59:05 +0100 Subject: [PATCH] chore(types): remove unused/duplicate code (#949) Part of the TODOs to address ;) Signed-off-by: Xavier Coulon --- pkg/renderer/sgml/paragraph.go | 2 +- pkg/types/attributes.go | 2 ++ pkg/types/types.go | 49 +++++----------------------------- 3 files changed, 9 insertions(+), 44 deletions(-) diff --git a/pkg/renderer/sgml/paragraph.go b/pkg/renderer/sgml/paragraph.go index 596d140c..c2e548e3 100644 --- a/pkg/renderer/sgml/paragraph.go +++ b/pkg/renderer/sgml/paragraph.go @@ -187,7 +187,7 @@ func withRenderer(f renderFunc) lineRendererOption { } func (r *sgmlRenderer) renderParagraphElements(ctx *renderer.Context, p *types.Paragraph, opts ...lineRendererOption) (string, error) { - hardbreaks := p.Attributes.HasOption(types.AttrHardBreaks) || ctx.Attributes.HasOption(types.DocumentAttrHardBreaks) + hardbreaks := p.Attributes.HasOption(types.AttrHardBreaks) || ctx.Attributes.HasOption(types.AttrHardBreaks) lr := r.newLineRenderer(append(opts, withHardBreaks(hardbreaks))...) buf := &strings.Builder{} for _, e := range p.Elements { diff --git a/pkg/types/attributes.go b/pkg/types/attributes.go index 711c2bb8..b1a3b241 100644 --- a/pkg/types/attributes.go +++ b/pkg/types/attributes.go @@ -163,6 +163,8 @@ const ( AttrExperimental = "experimental" // AttrButtonLabel the label of a button AttrButtonLabel = "label" + // AttrHardBreaks the attribute to set on a paragraph to render with hard breaks on each line + AttrHardBreaks = "hardbreaks" ) // Attribute is a key/value pair wrapper diff --git a/pkg/types/types.go b/pkg/types/types.go index bba5505b..42fccbfa 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -39,11 +39,6 @@ type WithElementAddition interface { AddElement(interface{}) error } -type WithConditionalElementAddition interface { // TODO: still needed? - WithElementAddition - CanAddElement(interface{}) bool -} - type WithElements interface { WithAttributes GetElements() []interface{} @@ -63,7 +58,6 @@ type WithTitle interface { type WithLocation interface { WithAttributes GetLocation() *Location - SetLocation(*Location) // TODO: unused? } type Referencable interface { @@ -106,7 +100,7 @@ func NewErrorFragment(p Position, err error) DocumentFragment { // Document the top-level structure for a document type Document struct { - Elements []interface{} // TODO: rename to `Blocks`? + Elements []interface{} ElementReferences ElementReferences Footnotes []*Footnote TableOfContents *TableOfContents @@ -767,8 +761,6 @@ type List struct { Elements []ListElement } -var _ WithConditionalElementAddition = &List{} - var _ WithElements = &List{} func (l *List) GetAttributes() Attributes { @@ -1153,8 +1145,8 @@ const ( // OrderedListElement the structure for the ordered list items type OrderedListElement struct { Attributes Attributes - Style string // TODO: rename to `OrderedListElementNumberingStyle`? TODO: define as an attribute instead? - Elements []interface{} // TODO: rename to `Blocks`? + Style string // TODO: rename to `OrderedListElementNumberingStyle`? TODO: define as an attribute instead? + Elements []interface{} } // making sure that the `ListElement` interface is implemented by `OrderedListElement` @@ -1287,7 +1279,7 @@ type UnorderedListElement struct { BulletStyle UnorderedListElementBulletStyle CheckStyle UnorderedListElementCheckStyle Attributes Attributes - Elements []interface{} // TODO: rename to `Blocks`? + Elements []interface{} } var _ ListElement = &UnorderedListElement{} @@ -1541,7 +1533,7 @@ type LabeledListElement struct { Term []interface{} Attributes Attributes Style LabeledListElementStyle - Elements []interface{} // TODO: rename to `Blocks`? + Elements []interface{} } // NewLabeledListElement initializes a new LabeledListElement @@ -1688,13 +1680,6 @@ type Paragraph struct { Elements []interface{} } -// AttrHardBreaks the attribute to set on a paragraph to render with hard breaks on each line -// TODO: remove? -const AttrHardBreaks = "hardbreaks" - -// DocumentAttrHardBreaks the attribute to set at the document level to render with hard breaks on each line of all paragraphs -const DocumentAttrHardBreaks = "hardbreaks" - // NewParagraph initializes a new `Paragraph` func NewParagraph(elements ...interface{}) (*Paragraph, error) { // log.Debugf("new paragraph with attributes: '%v'", attributes) @@ -1895,10 +1880,6 @@ func (x *ExternalCrossReference) GetLocation() *Location { return x.Location } -func (x *ExternalCrossReference) SetLocation(l *Location) { - x.Location = l -} - // GetAttributes returns the attributes of this paragraph so that substitutions can be applied onto them func (x *ExternalCrossReference) GetAttributes() Attributes { return x.Attributes @@ -1963,10 +1944,6 @@ func (i *ImageBlock) GetLocation() *Location { return i.Location } -func (i *ImageBlock) SetLocation(value *Location) { - i.Location = value -} - // InlineImage the structure for the inline image macros type InlineImage struct { Location *Location @@ -2009,10 +1986,6 @@ func (i *InlineImage) GetLocation() *Location { return i.Location } -func (i *InlineImage) SetLocation(value *Location) { - i.Location = value -} - // ------------------------------------------ // Icons // ------------------------------------------ @@ -2146,7 +2119,7 @@ func (s *sequence) nextVal() int { // Delimited blocks // ------------------------------------------ -type BlockDelimiterKind string // TODO: use it +type BlockDelimiterKind string const ( // Fenced a fenced block @@ -2653,7 +2626,6 @@ func NewLineBreak() (*LineBreak, error) { // ------------------------------------------ // QuotedText the structure for quoted text -// TODO implement RawText type QuotedText struct { Kind QuotedTextKind Elements []interface{} @@ -2805,7 +2777,6 @@ const ( ) // QuotedString a quoted string -// TODO implement RawText type QuotedString struct { Kind QuotedStringKind Elements []interface{} @@ -2940,10 +2911,6 @@ func (l *InlineLink) GetLocation() *Location { return l.Location } -func (l *InlineLink) SetLocation(value *Location) { - l.Location = value -} - // ------------------------------------------ // Conditionals // ------------------------------------------ @@ -3264,10 +3231,6 @@ func (f *FileInclusion) GetLocation() *Location { return f.Location } -func (f *FileInclusion) SetLocation(value *Location) { - f.Location = value -} - // GetAttributes returns this elements's attributes func (f *FileInclusion) GetAttributes() Attributes { return f.Attributes