pub trait ExprLinter: LSend {
type Unit: DocumentIterator;
// Required methods
fn expr(&self) -> &dyn Expr;
fn description(&self) -> &str;
// Provided methods
fn match_to_lint(
&self,
matched_tokens: &[Token],
source: &[char],
) -> Option<Lint> { ... }
fn match_to_lint_with_context(
&self,
matched_tokens: &[Token],
source: &[char],
_context: Option<(&[Token], &[Token])>,
) -> Option<Lint> { ... }
}Expand description
A trait that searches for tokens that fulfil Exprs in a Document.
Makes use of TokenStringExt::iter_chunks by default, or TokenStringExt::iter_sentences to process either
a chunk (clause) or a sentence at a time.
Required Associated Types§
Required Methods§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
A user-facing description of what kinds of grammatical errors this rule looks for. It is usually shown in settings menus.
Provided Methods§
Sourcefn match_to_lint(
&self,
matched_tokens: &[Token],
source: &[char],
) -> Option<Lint>
fn match_to_lint( &self, matched_tokens: &[Token], source: &[char], ) -> Option<Lint>
If any portions of a Document match Self::expr, they are passed through ExprLinter::match_to_lint
or ExprLinter::match_to_lint_with_context to be transformed into a Lint for editor consumption.
Transform matched tokens into a Lint for editor consumption.
This is the simple version that only sees the matched tokens. For context-aware linting,
implement match_to_lint_with_context instead.
Return None to skip producing a lint for this match.
Sourcefn match_to_lint_with_context(
&self,
matched_tokens: &[Token],
source: &[char],
_context: Option<(&[Token], &[Token])>,
) -> Option<Lint>
fn match_to_lint_with_context( &self, matched_tokens: &[Token], source: &[char], _context: Option<(&[Token], &[Token])>, ) -> Option<Lint>
Transform matched tokens into a Lint with access to surrounding context.
The context provides access to tokens before and after the match. When implementing
this method, you can call self.match_to_lint() as a fallback if the context isn’t needed.
Return None to skip producing a lint for this match.