lint

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KindProcessingInstruction = ast.NewNodeKind("ProcessingInstruction")

KindProcessingInstruction is the ast.NodeKind for ProcessingInstruction.

Functions

func CollectCodeBlockLines

func CollectCodeBlockLines(f *File) map[int]bool

CollectCodeBlockLines walks the AST and returns a set of 1-based line numbers that belong to fenced code blocks (including fence lines) or indented code blocks.

func CountLines

func CountLines(b []byte) int

CountLines returns the number of newline-terminated lines in b.

func NewPIBlockParser added in v0.3.0

func NewPIBlockParser() parser.BlockParser

NewPIBlockParser returns a block parser for processing instructions.

func PIBlockParserPrioritized added in v0.3.0

func PIBlockParserPrioritized() util.PrioritizedValue

PIBlockParserPrioritized returns the PI parser with its priority for registration.

func ResolveFiles

func ResolveFiles(args []string) ([]string, error)

ResolveFiles takes positional arguments and returns deduplicated, sorted markdown file paths. It supports individual files, directories (recursive *.md and *.markdown), and glob patterns. Returns an error for nonexistent paths (that are not glob patterns). By default, directory walking respects .gitignore files.

func ResolveFilesWithOpts

func ResolveFilesWithOpts(args []string, opts ResolveOpts) ([]string, error)

ResolveFilesWithOpts is like ResolveFiles but accepts options to control behavior such as gitignore filtering.

func StripFrontMatter

func StripFrontMatter(source []byte) (prefix, content []byte)

StripFrontMatter removes YAML front matter delimited by "---\n" from the beginning of source. It returns the front matter block (including delimiters) and the remaining content. If no front matter is found, prefix is nil and content equals source.

Types

type Diagnostic

type Diagnostic struct {
	File            string
	Line            int
	Column          int
	RuleID          string
	RuleName        string
	Severity        Severity
	Message         string
	SourceLines     []string // context lines around the diagnostic; empty if unavailable
	SourceStartLine int      // 1-based line number of first entry in SourceLines
}

Diagnostic represents a single lint finding.

type File

type File struct {
	Path        string
	Source      []byte
	Lines       [][]byte
	AST         ast.Node
	FS          fs.FS
	RootFS      fs.FS
	FrontMatter []byte
	LineOffset  int

	// GitignoreFunc is a lazy factory for the gitignore matcher.
	// It is called at most once (on first access via GetGitignore)
	// and the result is cached. Rules that do not call GetGitignore
	// never trigger matcher construction.
	GitignoreFunc func() *GitignoreMatcher
	// contains filtered or unexported fields
}

File holds a parsed Markdown document and its source.

func NewFile

func NewFile(path string, source []byte) (*File, error)

NewFile parses source as Markdown and returns a File.

func NewFileFromSource

func NewFileFromSource(path string, source []byte, stripFrontMatter bool) (*File, error)

NewFileFromSource creates a File from raw source bytes. When stripFrontMatter is true it strips YAML front matter, stores the prefix in FrontMatter, computes LineOffset via CountLines, and parses only the stripped content.

func (*File) AdjustDiagnostics

func (f *File) AdjustDiagnostics(diags []Diagnostic)

AdjustDiagnostics adds the file's LineOffset to each diagnostic's Line.

func (*File) FullSource

func (f *File) FullSource(body []byte) []byte

FullSource prepends the stored FrontMatter to body. It allocates a new slice to avoid mutating FrontMatter's backing array.

func (*File) GetGitignore added in v0.5.0

func (f *File) GetGitignore() *GitignoreMatcher

GetGitignore returns the gitignore matcher for this file, creating it lazily on first call. Returns nil if no GitignoreFunc was configured.

func (*File) LineOfOffset

func (f *File) LineOfOffset(offset int) int

LineOfOffset converts a byte offset in Source to a 1-based line number.

type GitignoreMatcher

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

GitignoreMatcher checks whether a given path is ignored according to .gitignore rules. It supports multiple .gitignore files at different directory levels, including negation patterns.

func NewGitignoreMatcher

func NewGitignoreMatcher(root string) *GitignoreMatcher

NewGitignoreMatcher creates a matcher by collecting .gitignore files from the given root directory and all its subdirectories. It also looks for .gitignore files in ancestor directories up to the filesystem root.

func (*GitignoreMatcher) IsIgnored

func (m *GitignoreMatcher) IsIgnored(absPath string, isDir bool) bool

IsIgnored returns true if the given absolute path should be ignored. isDir indicates whether the path is a directory.

type ProcessingInstruction added in v0.3.0

type ProcessingInstruction struct {
	ast.BaseBlock
	ClosureLine text.Segment
	Name        string // directive name from <?name
}

ProcessingInstruction is a custom AST block node for processing-instruction blocks (<?name ... ?>). It replaces the default ast.HTMLBlock representation for this PI syntax in CommonMark/HTML.

func (*ProcessingInstruction) Dump added in v0.3.0

func (n *ProcessingInstruction) Dump(source []byte, level int)

Dump implements ast.Node.

func (*ProcessingInstruction) HasClosure added in v0.3.0

func (n *ProcessingInstruction) HasClosure() bool

HasClosure reports whether the PI was closed with ?>. Mirrors ast.HTMLBlock.

func (*ProcessingInstruction) IsRaw added in v0.3.0

func (n *ProcessingInstruction) IsRaw() bool

IsRaw implements ast.Node. Processing instructions contain raw content.

func (*ProcessingInstruction) Kind added in v0.3.0

Kind implements ast.Node.

type ResolveOpts

type ResolveOpts struct {
	// UseGitignore enables filtering of walked directories by .gitignore
	// rules. When true (the default), files matched by .gitignore patterns
	// are skipped during directory walking. Explicitly named file paths are
	// never filtered by gitignore. Defaults to true when the zero value is
	// used (see DefaultResolveOpts).
	UseGitignore *bool

	// NoFollowSymlinks is a list of glob patterns. Symbolic links
	// whose path matches any pattern are skipped during directory
	// walking and glob expansion.
	NoFollowSymlinks []string
}

ResolveOpts controls how file resolution behaves.

func DefaultResolveOpts

func DefaultResolveOpts() ResolveOpts

DefaultResolveOpts returns options with defaults applied.

type Severity

type Severity string

Severity indicates the severity level of a diagnostic.

const (
	Error   Severity = "error"
	Warning Severity = "warning"
)

Severity levels.

Jump to

Keyboard shortcuts

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