linter

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package linter provides the shared lint pipeline used by both the CLI and the LSP server.

The pipeline: config discovery → parse → semantic model → rule execution → violation collection. Callers use LintFile to run the pipeline and then apply their own processor chain (via CLIProcessors or LSPProcessors) to filter and transform the results.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CLIProcessors

func CLIProcessors() (*processor.Chain, *processor.InlineDirectiveFilter)

CLIProcessors returns the standard CLI processor chain and the inline directive filter (the caller needs it for processor.InlineDirectiveFilter.AdditionalViolations).

func EnabledRuleCodes

func EnabledRuleCodes(cfg *config.Config) []string

EnabledRuleCodes returns the set of rule codes that are active for the given config. Includes registered rules, BuildKit captured rules, and semantic construction rules.

func LSPProcessors

func LSPProcessors() *processor.Chain

LSPProcessors returns the LSP processor chain. The LSP chain omits path normalization, path exclusion, and snippet attachment since those are CLI-specific concerns.

Types

type Channel

type Channel interface {
	Log(level Level, msg string)
	Progress(title string, pct int) // -1 = indeterminate
	Warn(msg string)
}

Channel receives diagnostic output from the lint/fix pipeline. Implementations map to environment-specific UX (LSP notifications, CLI stderr, etc.).

type Input

type Input struct {
	// FilePath is used for config discovery and violation locations.
	FilePath string

	// Content is the file content to lint. If nil, LintFile reads from FilePath.
	Content []byte

	// Config is the resolved configuration. If nil, LintFile loads from FilePath.
	Config *config.Config

	// ParseResult is a pre-parsed Dockerfile result. If non-nil, LintFile
	// reuses it instead of parsing again. This avoids double-parsing when
	// the caller has already parsed for syntax checks.
	ParseResult *dockerfile.ParseResult

	// BuildContext provides context-aware checks (e.g. .dockerignore).
	// If nil, context-aware checks are skipped.
	BuildContext rules.BuildContext

	// Channel receives progress and diagnostic output. Nil means silent.
	Channel Channel

	// SkipRules forces specific rules to be skipped even if enabled by config.
	// This is useful for "fast pass" linting modes (e.g., LSP diagnostics)
	// where expensive analyzers can be deferred without changing user config.
	SkipRules []string
}

Input configures a single invocation of LintFile.

type Level

type Level int

Level is a log level for the Channel interface.

const (
	LevelDebug Level = iota
	LevelInfo
	LevelWarn
	LevelError
)

type Result

type Result struct {
	// Violations are raw violations before processor filtering.
	Violations []rules.Violation

	// AsyncPlan contains planned async check requests from AsyncRule implementations.
	// The caller is responsible for executing these (if slow checks are enabled).
	AsyncPlan []async.CheckRequest

	// ParseResult is the parsed Dockerfile (AST, stages, source, BuildKit warnings).
	ParseResult *dockerfile.ParseResult

	// Config is the resolved config (loaded or passed in via Input).
	Config *config.Config
}

Result contains the output of LintFile.

func LintFile

func LintFile(input Input) (*Result, error)

LintFile runs the full lint pipeline for one file. It returns raw violations before processor filtering.

Content resolution order:

  1. input.Content — used as-is when provided.
  2. input.ParseResult.Source — used when a pre-parsed result is provided without Content, keeping sourcemap.New, directive.Parse, and semantic.NewBuilder in sync with the bytes that were actually parsed.
  3. os.ReadFile(input.FilePath) — last resort when neither is set.

ParseResult resolution follows the same priority: input.ParseResult is reused directly (avoiding a second parse); otherwise the file is parsed from the resolved content.

Jump to

Keyboard shortcuts

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