pub struct Config {
pub engines: EngineConfig,
pub rules: HashMap<String, RuleConfig>,
pub include: Vec<String>,
pub file_types: Vec<String>,
pub exclude: Vec<String>,
pub auto_fix: Vec<AutoFixRule>,
pub performance: PerformanceConfig,
pub dictionaries: DictionaryConfig,
pub languages: LanguageConfig,
pub workspace: WorkspaceConfig,
pub names: NameConfig,
pub morphology: MorphologyConfig,
}Fields§
§engines: EngineConfig§rules: HashMap<String, RuleConfig>§include: Vec<String>Which files this project checks, as workspace-relative globs.
Empty means every file the editor opens and every file the indexer
finds, which is the behaviour this had before the key existed and the
right default for a repository that is mostly prose. It is the wrong
one for a repository that is mostly code with a docs/ in it: there
the exclude list has to name every directory that is not prose, and
it silently stops being right the moment someone adds another one.
include and exclude compose the way a type-checker’s do – include
selects, exclude subtracts from the selection – so narrowing to
docs/** and then dropping docs/_build/** needs no knowledge of
what else is in the tree.
file_types: Vec<String>Which file types to check, as extensions without the leading dot.
Empty means every type the grammars recognise, which is the default
and what this did before the key existed. ["md"] restricts the whole
project to Markdown however wide include is, which is the common
case that include alone can only express by repeating the extension
in every pattern.
Matched case-insensitively, and a leading dot is accepted and ignored,
because .md is how half of everyone will write it.
exclude: Vec<String>Paths not to check, as workspace-relative globs.
The built-in list is always in force; anything written here is added
to it. Replacing it instead was the obvious reading and the wrong one:
a config that excluded one directory of its own silently stopped
excluding node_modules/**, so adding a single pattern could multiply
the work by a hundred with nothing to say it had.
auto_fix: Vec<AutoFixRule>§performance: PerformanceConfig§dictionaries: DictionaryConfig§languages: LanguageConfig§workspace: WorkspaceConfig§names: NameConfig§morphology: MorphologyConfigImplementations§
Source§impl Config
impl Config
Sourcepub fn load_or_warn(workspace_root: &Path) -> Self
pub fn load_or_warn(workspace_root: &Path) -> Self
Load configuration, warning and falling back to defaults if it cannot be read.
load fails on a malformed .languagecheck.yaml — a bad indent, a typo’d enum — and
callers used to answer that with a bare Config::default(), so a rejected file was
indistinguishable from an absent one and the user’s overrides silently did nothing.
A missing file is not an error and is not reported; an unreadable one is.
Callers with no tracing subscriber installed (the CLI binary) must report to stderr
themselves rather than call this, or the warning goes nowhere.
Sourcepub fn excludes(&self, path: &Path, workspace_root: &Path) -> bool
pub fn excludes(&self, path: &Path, workspace_root: &Path) -> bool
Whether exclude covers this path.
path may be absolute or already relative to workspace_root; it is
reduced to the workspace-relative form the patterns are written
against, because node_modules/** is how a user thinks about it and
an absolute path would never match.
An unparseable pattern excludes nothing. Refusing to check a file because a glob had a typo is the worse of the two failures.
Sourcepub fn includes(&self, path: &Path, workspace_root: &Path) -> bool
pub fn includes(&self, path: &Path, workspace_root: &Path) -> bool
Whether include selects this path.
An empty include selects everything, so a config that never mentions
the key behaves as it always did.
Sourcepub fn admits_type(&self, path: &Path) -> bool
pub fn admits_type(&self, path: &Path) -> bool
Whether file_types admits this path’s extension.
An empty list admits everything, so a config that never mentions the key behaves as it always did. A path with no extension is admitted too: the list is a restriction on types, and a file that has no type was never selected by one.
Sourcepub fn checks(&self, path: &Path, workspace_root: &Path) -> bool
pub fn checks(&self, path: &Path, workspace_root: &Path) -> bool
Whether this project checks this file at all.
The one question the indexer, the CLI and the editor all have to
answer the same way: a file the editor still checks after the indexer
skipped it is the inconsistency this exists to avoid. include
selects and exclude subtracts, so an excluded path stays excluded
however explicitly include names it.
Source§impl Config
impl Config
Sourcepub fn parse_text(
text: &str,
workspace_root: &Path,
format: &str,
) -> Result<Self>
pub fn parse_text( text: &str, workspace_root: &Path, format: &str, ) -> Result<Self>
Parse a config from text that is not on disk yet.
The editor asks about the buffer it is showing, which is not the file
the engines are running under: a half-typed URL has to be answerable
before it is saved, or the feedback arrives after the mistake has
already been committed. Relative paths still resolve against
workspace_root, because that is what they will mean once the file is
written.
format is the file’s extension when the caller knows it. YAML 1.2 is
a superset of JSON, so the YAML parser reads both and “json” only
picks the stricter reader for a better error message.
Sourcepub fn unknown_key_paths(text: &str) -> Vec<String>
pub fn unknown_key_paths(text: &str) -> Vec<String>
Every unknown key in text, as dotted paths, for a caller that wants
to report them against a position instead of a log line.
[warn_unknown_keys] writes the same finding to the log, which is
where it went before anything could draw it.
pub fn load(workspace_root: &Path) -> Result<Self>
Sourcepub fn apply_auto_fixes(&self, text: &str) -> (String, usize)
pub fn apply_auto_fixes(&self, text: &str) -> (String, usize)
Apply user-defined auto-fix rules to the given text, returning the modified text and the number of replacements made.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: Sized + AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: Sized + AsFilelike,
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more