Skip to main content

Config

Struct Config 

Source
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: MorphologyConfig

Implementations§

Source§

impl Config

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

pub fn load(workspace_root: &Path) -> Result<Self>

Source

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 Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> GetSetFdFlags for T

Source§

fn get_fd_flags(&self) -> Result<FdFlags, Error>
where T: AsFilelike,

Query the “status” flags for the self file descriptor.
Source§

fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>
where T: AsFilelike,

Create a new SetFdFlags value for use with set_fd_flags. Read more
Source§

fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>
where T: Sized + AsFilelike,

Set the “status” flags for the self file descriptor. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> LSend for T
where T: Send + Sync + ?Sized,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Pointer = u32

Source§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more