Skip to content

Commit

Permalink
chore(types): remove unused/duplicate code (#949)
Browse files Browse the repository at this point in the history
Part of the TODOs to address ;)

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Feb 22, 2022
1 parent 0550268 commit 1569a6b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pkg/renderer/sgml/paragraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/types/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 6 additions & 43 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -63,7 +58,6 @@ type WithTitle interface {
type WithLocation interface {
WithAttributes
GetLocation() *Location
SetLocation(*Location) // TODO: unused?
}

type Referencable interface {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -767,8 +761,6 @@ type List struct {
Elements []ListElement
}

var _ WithConditionalElementAddition = &List{}

var _ WithElements = &List{}

func (l *List) GetAttributes() Attributes {
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -1287,7 +1279,7 @@ type UnorderedListElement struct {
BulletStyle UnorderedListElementBulletStyle
CheckStyle UnorderedListElementCheckStyle
Attributes Attributes
Elements []interface{} // TODO: rename to `Blocks`?
Elements []interface{}
}

var _ ListElement = &UnorderedListElement{}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2009,10 +1986,6 @@ func (i *InlineImage) GetLocation() *Location {
return i.Location
}

func (i *InlineImage) SetLocation(value *Location) {
i.Location = value
}

// ------------------------------------------
// Icons
// ------------------------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2653,7 +2626,6 @@ func NewLineBreak() (*LineBreak, error) {
// ------------------------------------------

// QuotedText the structure for quoted text
// TODO implement RawText
type QuotedText struct {
Kind QuotedTextKind
Elements []interface{}
Expand Down Expand Up @@ -2805,7 +2777,6 @@ const (
)

// QuotedString a quoted string
// TODO implement RawText
type QuotedString struct {
Kind QuotedStringKind
Elements []interface{}
Expand Down Expand Up @@ -2940,10 +2911,6 @@ func (l *InlineLink) GetLocation() *Location {
return l.Location
}

func (l *InlineLink) SetLocation(value *Location) {
l.Location = value
}

// ------------------------------------------
// Conditionals
// ------------------------------------------
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1569a6b

Please sign in to comment.