diagnostics

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: 5 Imported by: 0

Documentation

Overview

Package diagnostics provides shared diagnostic checks for markdown files.

This package contains diagnostic rules that are used by both the LSP server and the CLI lint command to ensure consistent issue reporting across tools.

Diagnostic Types

The package detects the following issues:

  • broken-wikilink: Wikilinks pointing to non-existent posts
  • unknown-mention: Mentions (@handle) not found in blogroll
  • h1-in-content: H1 headings in content (templates add H1 from title)
  • duplicate-key: Duplicate YAML keys in frontmatter
  • invalid-date: Invalid date formats (non-ISO 8601)
  • missing-alt-text: Images without alt text
  • protocol-less-url: URLs without protocol (//example.com)
  • admonition-fenced-code: Fenced code blocks in admonitions without blank line

Usage

The main entry point is the Check function which runs all diagnostic checks:

issues := diagnostics.Check(filePath, content, nil)

For wikilink and mention checking, provide a Resolver:

issues := diagnostics.Check(filePath, content, resolver)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Issue

type Issue struct {
	File     string   // File path
	Range    Range    // Position in the file
	Code     string   // Issue code (e.g., "duplicate-key", "broken-wikilink")
	Severity Severity // Severity level
	Message  string   // Human-readable message
	Fixable  bool     // Whether this issue can be automatically fixed
}

Issue represents a diagnostic issue found in a file.

func Check

func Check(filePath, content string, resolver Resolver) []Issue

Check runs all diagnostic checks on the content and returns any issues found. The resolver is optional; if nil, wikilink and mention checks are skipped.

type Range

type Range struct {
	StartLine int // 0-based line number
	StartCol  int // 0-based column (character offset)
	EndLine   int // 0-based line number
	EndCol    int // 0-based column
}

Range represents a position range in a document.

type Resolver

type Resolver interface {
	// ResolveSlug returns true if a post with the given slug exists.
	ResolveSlug(slug string) bool
	// ResolveHandle returns true if a mention handle exists in the blogroll.
	ResolveHandle(handle string) bool
}

Resolver provides lookup functionality for wikilinks and mentions. This interface allows the diagnostics package to check if references exist without directly depending on the LSP index or any specific implementation.

type Severity

type Severity int

Severity indicates the severity of a diagnostic 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