Skip to main content

Linter

Struct Linter 

Source
pub struct Linter { /* private fields */ }
Expand description

A compiled, ready-to-run rule set.

Implementations§

Source§

impl Linter

Source

pub fn new(config: Config, callbacks: &Callbacks) -> Result<Self, ConfigError>

Compiles a config into a linter, resolving every rule’s callback and parser against callbacks. Errors when a rule references a callback or parser that is not registered — patterns themselves were validated at config-load time.

Source

pub fn rules(&self) -> &[Rule]

The global rules, in config order.

Source

pub fn scopes(&self) -> &[Scope]

The scopes, in config order.

Source

pub fn lint(&self, source: &str) -> Vec<Violation>

Lints one snapshot of a source file with the global rules only — scoped rules are ignored. Hits are sorted by position (then span end, then rule id) so output is deterministic regardless of rule order. Zero-width matches are skipped.

Source

pub fn lint_in(&self, info: DocInfo<'_>, source: &str) -> Vec<Violation>

Like Linter::lint, with file path and language exposed to callbacks.

Source

pub fn lint_segments( &self, source: &str, segments: &[(usize, Span)], ) -> Vec<Violation>

Lints pre-computed scope regions — the subpasses. segments are (scope index, region) pairs, typically from scopes::segment_all or a parse tree’s scoped nodes.

Source

pub fn lint_segments_in( &self, info: DocInfo<'_>, source: &str, segments: &[(usize, Span)], ) -> Vec<Violation>

Like Linter::lint_segments, with file path and language exposed to callbacks.

Source

pub fn lint_merged( &self, source: &str, segments: &[(usize, Span)], ) -> Vec<Violation>

Global rules plus scoped rules over segments, merged and sorted — one call for consumers that already have regions (e.g. a parse tree).

Source

pub fn lint_merged_in( &self, info: DocInfo<'_>, source: &str, segments: &[(usize, Span)], ) -> Vec<Violation>

Like Linter::lint_merged, with file path and language exposed to callbacks.

Source

pub fn lint_all(&self, source: &str) -> Vec<Violation>

Segments the source itself, then lints everything — the one-liner for CLI use.

Source

pub fn lint_all_in(&self, info: DocInfo<'_>, source: &str) -> Vec<Violation>

Like Linter::lint_all, with file path and language exposed to callbacks.

Source

pub fn lint_rule( &self, rule_id: &str, info: DocInfo<'_>, source: &str, ) -> Result<Vec<Violation>, String>

Runs a single rule over a source snapshot — global or scoped automatically, by where the rule lives. Unknown ids are an error. Used by declint test to exercise one rule’s fixtures.

Trait Implementations§

Source§

impl Debug for Linter

Source§

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

Formats the value using the given formatter. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.