formatter

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package formatter provides output formatting for brfit.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileData

type FileData struct {
	// Path is the file path.
	Path string

	// Language is the detected language.
	Language string

	// Signatures is the list of extracted signatures.
	Signatures []parser.Signature

	// RawImports is the list of raw import/export statement text.
	RawImports []string

	// Calls is the list of function call references.
	Calls []parser.FunctionCall

	// Error is any error that occurred during extraction.
	Error error
}

FileData represents a file with its extracted data for formatting.

type Formatter

type Formatter interface {
	// Format formats the package data and returns the output bytes.
	Format(data *PackageData) ([]byte, error)

	// Name returns the formatter name (e.g., "xml", "markdown").
	Name() string
}

Formatter defines the interface for output formatting.

type ImportCount added in v0.20.0

type ImportCount struct {
	// Import is the raw import statement text.
	Import string
	// Count is the number of files that use this import.
	Count int
}

ImportCount represents an import with its usage count across files.

type JSONFormatter added in v0.19.0

type JSONFormatter struct{}

JSONFormatter implements Formatter for JSON output.

func NewJSONFormatter added in v0.19.0

func NewJSONFormatter() *JSONFormatter

NewJSONFormatter creates a new JSONFormatter.

Example
package main

import (
	"fmt"

	"github.com/indigo-net/Brf.it/pkg/formatter"
)

func main() {
	f := formatter.NewJSONFormatter()
	fmt.Println(f.Name())
}
Output:
json

func (*JSONFormatter) Format added in v0.19.0

func (f *JSONFormatter) Format(data *PackageData) ([]byte, error)

Format implements Formatter interface.

func (*JSONFormatter) Name added in v0.19.0

func (f *JSONFormatter) Name() string

Name returns the formatter name.

type MarkdownFormatter

type MarkdownFormatter struct{}

MarkdownFormatter implements Formatter for Markdown output.

func NewMarkdownFormatter

func NewMarkdownFormatter() *MarkdownFormatter

NewMarkdownFormatter creates a new MarkdownFormatter.

Example
package main

import (
	"fmt"

	"github.com/indigo-net/Brf.it/pkg/formatter"
)

func main() {
	f := formatter.NewMarkdownFormatter()
	fmt.Println(f.Name())
}
Output:
markdown

func (*MarkdownFormatter) Format

func (f *MarkdownFormatter) Format(data *PackageData) ([]byte, error)

Format implements Formatter interface.

func (*MarkdownFormatter) Name

func (f *MarkdownFormatter) Name() string

Name returns the formatter name.

type PackageData

type PackageData struct {
	// RootPath is the root path being packaged.
	RootPath string

	// Version is the brf.it version string.
	Version string

	// Tree is the directory tree string.
	Tree string

	// Files is the list of file data.
	Files []FileData

	// TotalSignatures is the total number of signatures.
	TotalSignatures int

	// TotalSize is the total size of processed files.
	TotalSize int64

	// IncludeImports indicates whether imports should be rendered.
	IncludeImports bool

	// DedupeImports indicates whether imports should be deduplicated across files.
	// When true, imports are collected globally and shown in a separate section.
	DedupeImports bool

	// GlobalImports holds deduplicated imports with their usage counts.
	// Only populated when DedupeImports is true.
	GlobalImports []ImportCount

	// MaxDocLength is the maximum length of documentation comments.
	// 0 means no limit (default).
	MaxDocLength int

	// NoSchema indicates whether to omit the schema section in output.
	NoSchema bool

	// IncludeCallGraph indicates whether to include function call references.
	IncludeCallGraph bool
}

PackageData contains all data needed for formatting output.

type XMLFormatter

type XMLFormatter struct{}

XMLFormatter implements Formatter for XML output.

func NewXMLFormatter

func NewXMLFormatter() *XMLFormatter

NewXMLFormatter creates a new XMLFormatter.

Example
package main

import (
	"fmt"

	"github.com/indigo-net/Brf.it/pkg/formatter"
)

func main() {
	f := formatter.NewXMLFormatter()
	fmt.Println(f.Name())
}
Output:
xml

func (*XMLFormatter) Format

func (f *XMLFormatter) Format(data *PackageData) ([]byte, error)

Format implements Formatter interface.

Example
package main

import (
	"fmt"

	"github.com/indigo-net/Brf.it/pkg/formatter"
)

func main() {
	f := formatter.NewXMLFormatter()
	data := &formatter.PackageData{
		RootPath: "/project",
		Version:  "1.0.0",
		Files: []formatter.FileData{
			{
				Path:     "main.go",
				Language: "go",
			},
		},
	}
	output, err := f.Format(data)
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	fmt.Println(len(output) > 0)
}
Output:
true

func (*XMLFormatter) Name

func (f *XMLFormatter) Name() string

Name returns the formatter name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL