lint

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package lint provides linting functionality for markata-go. This file contains blogroll-specific lint checks.

Package lint provides markdown linting functionality for markata-go.

Package lint provides markdown linting functionality for markata-go. It detects common issues in markdown files that can cause build failures.

Supported Checks

The linter detects the following issues (via pkg/diagnostics):

  • Duplicate YAML keys in frontmatter
  • Invalid date formats (non-ISO 8601)
  • Malformed image links (missing alt text)
  • Protocol-less URLs (//example.com instead of https://example.com)
  • H1 headings in content (templates add H1 from frontmatter title)
  • Fenced code blocks in admonitions without blank line (goldmark limitation)

All issues can be auto-fixed using the Fix function (except H1 headings).

Index

Constants

View Source
const (
	// DefaultDateFormat is the ISO 8601 date format (YYYY-MM-DD).
	DefaultDateFormat = "2006-01-02"

	// DefaultDateTimeFormat is the ISO 8601 datetime format (RFC3339 simplified).
	DefaultDateTimeFormat = "2006-01-02T15:04:05Z"

	// AmbiguousFormatMDY interprets ambiguous dates as month/day/year (US format).
	AmbiguousFormatMDY = "mdy"

	// AmbiguousFormatDMY interprets ambiguous dates as day/month/year (European format).
	AmbiguousFormatDMY = "dmy"

	// MissingDateSkip returns empty string for missing dates.
	MissingDateSkip = "skip"

	// MissingDateToday uses current date for missing dates.
	MissingDateToday = "today"

	// MissingDateError returns an error for missing dates.
	MissingDateError = "error"
)

Date format and configuration constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlogrollIssue added in v0.5.0

type BlogrollIssue struct {
	Code     string   // Issue code (e.g., "LBL001")
	Severity Severity // Severity level
	Message  string   // Human-readable message
	FeedURL  string   // Feed URL where issue was found (if applicable)
	Handle   string   // Handle involved (if applicable)
}

BlogrollIssue represents a linting issue found in blogroll configuration.

type BlogrollResult added in v0.5.0

type BlogrollResult struct {
	Issues []BlogrollIssue
}

BlogrollResult contains the linting results for blogroll configuration.

func Blogroll added in v0.5.0

func Blogroll(config *models.BlogrollConfig) *BlogrollResult

Blogroll checks blogroll configuration for common issues. Returns a BlogrollResult containing all issues found.

Supported checks:

  • LBL001: Duplicate Handle Detection - errors if same handle appears multiple times
  • LBL002: Duplicate URL Detection - errors if same feed URL appears multiple times
  • LBL003: Primary Person Validation - errors if primary_person references non-existent handle

func (*BlogrollResult) ErrorCount added in v0.5.0

func (r *BlogrollResult) ErrorCount() int

ErrorCount returns the number of error-severity issues.

func (*BlogrollResult) HasErrors added in v0.5.0

func (r *BlogrollResult) HasErrors() bool

HasErrors returns true if any issues are errors.

func (*BlogrollResult) WarningCount added in v0.5.0

func (r *BlogrollResult) WarningCount() int

WarningCount returns the number of warning-severity issues.

type DateFixChange added in v0.5.0

type DateFixChange struct {
	Key      string // The frontmatter key (e.g., "date", "published_date")
	OldValue string // The original date value
	NewValue string // The normalized date value
}

DateFixChange records a date fix that was applied.

type DateTimeFixer added in v0.5.0

type DateTimeFixer struct {
	// contains filtered or unexported fields
}

DateTimeFixer normalizes various date formats to ISO 8601.

func NewDateTimeFixer added in v0.5.0

func NewDateTimeFixer(config DateTimeFixerConfig) *DateTimeFixer

NewDateTimeFixer creates a new DateTimeFixer with the given configuration.

func (*DateTimeFixer) Fix added in v0.5.0

func (f *DateTimeFixer) Fix(dateStr string) (string, error)

Fix attempts to parse the input date string and return it in ISO 8601 format. Returns the normalized date string and any error encountered.

func (*DateTimeFixer) FixDateInContent added in v0.5.0

func (f *DateTimeFixer) FixDateInContent(content string) (string, []DateFixChange)

FixDateInContent finds and fixes date values in frontmatter content. It returns the fixed content and a list of changes made.

type DateTimeFixerConfig added in v0.5.0

type DateTimeFixerConfig struct {
	// Format is the output date format. Default: "2006-01-02" (ISO 8601 date)
	Format string

	// DateTimeFormat is the output datetime format. Default: "2006-01-02T15:04:05Z" (RFC3339 simplified)
	DateTimeFormat string

	// PreserveTime indicates whether to preserve time components when present in input.
	// Default: true
	PreserveTime bool

	// AmbiguousFormat specifies how to interpret ambiguous dates like "01/02/2024".
	// "mdy" interprets as month/day/year (US format)
	// "dmy" interprets as day/month/year (European format)
	// Default: "mdy"
	AmbiguousFormat string

	// MissingDate specifies behavior when date is empty or missing.
	// "today" uses current date
	// "skip" returns empty string
	// "error" returns an error
	// Default: "skip"
	MissingDate string

	// WarnFuture logs a warning for future dates
	WarnFuture bool

	// WarnOld logs a warning for dates older than 50 years
	WarnOld bool

	// ReferenceTime is the time to use for relative date calculations.
	// If nil, time.Now() is used. Useful for testing.
	ReferenceTime *time.Time
}

DateTimeFixerConfig configures the datetime fixer behavior.

func DefaultDateTimeFixerConfig added in v0.5.0

func DefaultDateTimeFixerConfig() DateTimeFixerConfig

DefaultDateTimeFixerConfig returns a configuration with sensible defaults.

type Issue

type Issue struct {
	File       string   // File path
	Line       int      // Line number (1-indexed)
	Column     int      // Column number (1-indexed, 0 if not applicable)
	Type       string   // Issue type (e.g., "duplicate-key", "invalid-date")
	Severity   Severity // Severity level
	Message    string   // Human-readable message
	Fixable    bool     // Whether this issue can be automatically fixed
	FixApplied bool     // Whether fix was applied
}

Issue represents a linting issue found in a file.

type Result

type Result struct {
	File    string  // File path
	Issues  []Issue // Issues found
	Content string  // Original content
	Fixed   string  // Fixed content (same as Content if no fixes)
}

Result contains the linting results for a file.

func Fix

func Fix(filePath, content string) *Result

Fix applies automatic fixes to the content and returns the fixed content.

func Lint

func Lint(filePath, content string) *Result

Lint analyzes content and returns any issues found.

func WithResolver added in v0.7.0

func WithResolver(filePath, content string, resolver diagnostics.Resolver) *Result

WithResolver analyzes content and returns any issues found, including wikilink and mention checks using the provided resolver.

func (*Result) FixableCount added in v0.5.0

func (r *Result) FixableCount() int

FixableCount returns the number of fixable issues.

func (*Result) HasErrors

func (r *Result) HasErrors() bool

HasErrors returns true if any issues are errors.

type Severity

type Severity int

Severity indicates the severity of a linting issue.

const (
	SeverityError Severity = iota
	SeverityWarning
	SeverityInfo
)

func (Severity) String

func (s Severity) String() string

Jump to

Keyboard shortcuts

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