Documentation
¶
Overview ¶
Package system provides a thin, swappable filesystem abstraction so the linter can read styles, dictionaries, vocabularies and other assets from the host OS (the default) or from an in-memory map (the WebAssembly host supplies one via the JavaScript API in cmd/valew).
All non-test code paths that previously called os.ReadFile, os.Open, filepath.Walk, filepath.Glob, etc. should go through the package-level helpers in this file. The pluggable backend is swapped with SetDefault.
Index ¶
- func AbsPath(path string) string
- func DeterminePath(fsys FS, configPath string, keyPath string) string
- func ExecuteWithInput(exe, text string, args ...string) (string, error)
- func ExecuteWithInputEnv(exe, text string, env []string, args ...string) (string, error)
- func FileExists(filename string) bool
- func FileNameWithoutExt(fileName string) string
- func Glob(pattern string) ([]string, error)
- func GlobRecursive(root, pattern string) ([]string, error)
- func IsDir(filename string) bool
- func IsLinux() bool
- func IsMac() bool
- func IsUnix() bool
- func IsWindows() bool
- func Mkdir(dir string) error
- func Name() string
- func NormalizePath(path string) string
- func Open(name string) (io.ReadCloser, error)
- func PlatformAndArch() string
- func ReadFile(name string) ([]byte, error)
- func Readlink(name string) (string, error)
- func RelInside(base, path string) (string, bool)
- func SetDefault(fsys FS)
- func Stat(name string) (fs.FileInfo, error)
- func Unarchive(src, dest string) error
- func Walk(path string, walkFn filepath.WalkFunc) error
- func Which(cmds []string) string
- type FS
- type MemFS
- func (m *MemFS) AddFile(name string, data []byte)
- func (m *MemFS) AddZip(dest string, data []byte) error
- func (m *MemFS) Exists(name string) bool
- func (m *MemFS) Glob(pattern string) ([]string, error)
- func (m *MemFS) GlobRecursive(root, pattern string) ([]string, error)
- func (m *MemFS) IsDir(name string) bool
- func (m *MemFS) List() []string
- func (m *MemFS) Open(name string) (io.ReadCloser, error)
- func (m *MemFS) ReadFile(name string) ([]byte, error)
- func (m *MemFS) Readlink(name string) (string, error)
- func (m *MemFS) Remove(name string)
- func (m *MemFS) Reset()
- func (m *MemFS) Stat(name string) (fs.FileInfo, error)
- func (m *MemFS) Walk(root string, fn filepath.WalkFunc) error
- type OSFS
- func (OSFS) Exists(name string) bool
- func (OSFS) Glob(pattern string) ([]string, error)
- func (OSFS) GlobRecursive(root, pattern string) ([]string, error)
- func (OSFS) IsDir(name string) bool
- func (OSFS) Open(name string) (io.ReadCloser, error)
- func (OSFS) ReadFile(name string) ([]byte, error)
- func (OSFS) Readlink(name string) (string, error)
- func (OSFS) Stat(name string) (fs.FileInfo, error)
- func (OSFS) Walk(root string, fn filepath.WalkFunc) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeterminePath ¶
DeterminePath determines the path of `keyPath` based on `configPath`.
If `keyPath` is an absolute path, it is returned as is.
If `keyPath` is a relative path, it is joined with `configPath`.
If `configPath` is not a directory, the directory part of `configPath` is used.
func ExecuteWithInput ¶
ExecuteWithInput runs a command with the given text as input.
func ExecuteWithInputEnv ¶ added in v3.23.0
ExecuteWithInputEnv is ExecuteWithInput with variables added to the command's environment.
func FileExists ¶
FileExists determines if the path given by `filename` exists.
func FileNameWithoutExt ¶
FileNameWithoutExt returns the filename without its extension.
func Glob ¶ added in v3.26.0
Glob returns the names matching a shell-style pattern in a single directory.
func GlobRecursive ¶ added in v3.26.0
GlobRecursive returns every file under root whose basename matches the supplied shell-style pattern.
func NormalizePath ¶
NormalizePath expands a tilde and returns the absolute path of `path`.
func Open ¶ added in v3.26.0
func Open(name string) (io.ReadCloser, error)
Open opens the named file from the active backend.
func PlatformAndArch ¶
func PlatformAndArch() string
PlatformAndArch returns the current platform and architecture.
func ReadFile ¶ added in v3.26.0
ReadFile returns the contents of the named file from the active backend.
func Readlink ¶ added in v3.26.0
Readlink returns the destination of a symlink (or an error from non-OS backends, which have no concept of links).
func RelInside ¶ added in v3.25.0
RelInside returns path relative to base when it lies inside base. A path outside base, or one that can't be made relative, is returned as given with false.
func SetDefault ¶ added in v3.26.0
func SetDefault(fsys FS)
SetDefault replaces the active filesystem backend.
Types ¶
type FS ¶ added in v3.26.0
type FS interface {
ReadFile(name string) ([]byte, error)
Open(name string) (io.ReadCloser, error)
Stat(name string) (fs.FileInfo, error)
Readlink(name string) (string, error)
Walk(root string, fn filepath.WalkFunc) error
Glob(pattern string) ([]string, error)
GlobRecursive(root, pattern string) ([]string, error)
Exists(name string) bool
IsDir(name string) bool
}
FS is the surface the linter needs from a filesystem. It intentionally follows the os/filepath naming so swapping callers is mechanical.
type MemFS ¶ added in v3.26.0
type MemFS struct {
// contains filtered or unexported fields
}
MemFS is an in-memory FS implementation. Paths are normalized to forward-slash form and treated as absolute under a single virtual root, so a Vale config with `StylesPath = /styles` and a MemFS populated under `/styles/<package>/<rule>.yml` behaves identically to a host-OS install.
func NewMemFS ¶ added in v3.26.0
func NewMemFS() *MemFS
NewMemFS returns an empty in-memory filesystem.
func (*MemFS) AddFile ¶ added in v3.26.0
AddFile writes the supplied bytes at the given virtual path.
func (*MemFS) AddZip ¶ added in v3.26.0
AddZip extracts every entry in the supplied ZIP archive under dest. Directory entries are skipped; their existence is inferred from the files inside them.
func (*MemFS) Glob ¶ added in v3.26.0
Glob implements FS. Patterns are matched against entries in the directory portion of the pattern with `path.Match` semantics, which is sufficient for everything the linter uses (currently `*.dic`).
func (*MemFS) GlobRecursive ¶ added in v3.26.0
GlobRecursive implements FS. The pattern is interpreted as a basename pattern that matches anywhere under root.
func (*MemFS) List ¶ added in v3.26.0
List returns every file path currently stored, sorted lexicographically.
func (*MemFS) Open ¶ added in v3.26.0
func (m *MemFS) Open(name string) (io.ReadCloser, error)
Open implements FS.
func (*MemFS) Readlink ¶ added in v3.26.0
Readlink implements FS. The in-memory store has no symlinks.
func (*MemFS) Remove ¶ added in v3.26.0
Remove deletes the file at the given virtual path. It is a no-op if the path does not exist.
func (*MemFS) Walk ¶ added in v3.26.0
Walk implements FS. We iterate over the entries in lexicographic order and synthesize directory callbacks at the boundary between entries so the walkFn observes the same shape it would on disk: paths carry the root as the caller wrote it, so a relative root yields relative paths (which is what lets a caller take them relative to that root again), and SkipDir leaves the rest of that directory unvisited.
type OSFS ¶ added in v3.26.0
type OSFS struct{}
OSFS is the host-OS implementation of FS, used by default.