Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Source ¶ added in v0.13.0
func Source(opts SourceOptions) ([]byte, error)
Source applies every fixable rule allowed by the effective config and returns the resulting bytes. The returned bytes equal the input when no rule produced an edit.
func SourceWithRules ¶ added in v0.13.0
func SourceWithRules(opts SourceOptions, names []string) ([]byte, error)
SourceWithRules is like Source but only the named rules are applied. An empty names slice produces no fixes.
Types ¶
type Fixer ¶
type Fixer struct {
Config *config.Config
Rules []rule.Rule
StripFrontMatter bool
Logger *vlog.Logger
// RootDir is the project root directory (parent of .mdsmith.yml).
// Used by rules that need to read files relative to the project root.
RootDir string
// MaxInputBytes is the maximum file size in bytes before a file is
// skipped with an error. Zero or negative means unlimited.
MaxInputBytes int64
// Explain, when true, attaches per-leaf rule provenance to each
// remaining diagnostic so output formatters can render an
// explanation trailer.
Explain bool
// SourceFS, when non-nil, overrides the per-file dirFS that
// prepareFile would otherwise derive from filepath.Dir(path).
// Used by Source / SourceWithRules so callers can pass a
// workspace-relative path for config matching while still giving
// include/catalog/cross-file rules a real filesystem rooted at
// the document's actual directory. Disk-based Fix() (path-based)
// leaves this nil and continues to derive dirFS from each file's
// absolute path.
SourceFS fs.FS
// contains filtered or unexported fields
}
Fixer applies auto-fixes for fixable rules and reports remaining diagnostics.
type Result ¶
type Result struct {
// FilesChecked is the number of files processed (after ignore filtering).
FilesChecked int
// Failures is the number of diagnostics found before attempting fixes.
Failures int
// Diagnostics contains remaining diagnostics after fixing (from non-fixable
// rules and any violations that could not be auto-fixed).
Diagnostics []lint.Diagnostic
// Modified lists file paths that were written back to disk.
Modified []string
// Errors contains any errors encountered during the fix process.
Errors []error
}
Result holds the outcome of a fix run.
type SourceOptions ¶ added in v0.13.0
type SourceOptions struct {
Config *config.Config
Rules []rule.Rule
Path string
Source []byte
RootDir string
StripFrontMatter bool
// MaxInputBytes caps Source size before any fix runs. Semantics
// match lint.ReadFileLimited: <= 0 or math.MaxInt64 means
// unlimited; > 0 means reject buffers larger than that many
// bytes. Callers that want the default 2 MB cap must pass
// lint.DefaultMaxInputBytes explicitly.
MaxInputBytes int64
// SourceFS, when non-nil, is the filesystem the fixable rules
// (include/catalog/cross-file) see for the buffer. Callers that
// pass a workspace-relative Path (for config glob matching) MUST
// also supply a SourceFS rooted at the document's real
// directory; otherwise the dirFS derived from the relative path
// would be resolved against the process CWD, breaking
// neighbour-file lookups when the editor is launched from
// elsewhere.
SourceFS fs.FS
}
SourceOptions configures an in-memory fix run. The fix functions (Source, SourceWithRules) do not touch disk; they reuse the same prep/apply machinery the path-based Fixer uses on a buffer.
Click to show internal directories.
Click to hide internal directories.