pub trait Rule:
DynClone
+ Send
+ Sync {
Show 14 methods
// Required methods
fn name(&self) -> &'static str;
fn description(&self) -> &'static str;
fn check(&self, ctx: &LintContext<'_>) -> LintResult;
fn fix(&self, ctx: &LintContext<'_>) -> Result<String, LintError>;
fn as_any(&self) -> &dyn Any;
// Provided methods
fn should_skip(&self, _ctx: &LintContext<'_>) -> bool { ... }
fn category(&self) -> RuleCategory { ... }
fn default_config_section(&self) -> Option<(String, Value)> { ... }
fn config_aliases(&self) -> Option<HashMap<String, String>> { ... }
fn fix_capability(&self) -> FixCapability { ... }
fn cross_file_scope(&self) -> CrossFileScope { ... }
fn contribute_to_index(
&self,
_ctx: &LintContext<'_>,
_file_index: &mut FileIndex,
) { ... }
fn cross_file_check(
&self,
_file_path: &Path,
_file_index: &FileIndex,
_workspace_index: &WorkspaceIndex,
) -> LintResult { ... }
fn from_config(_config: &Config) -> Box<dyn Rule>
where Self: Sized { ... }
}Expand description
Remove marker /// TRAIT_MARKER_V1
Required Methods§
fn name(&self) -> &'static str
fn description(&self) -> &'static str
fn check(&self, ctx: &LintContext<'_>) -> LintResult
fn fix(&self, ctx: &LintContext<'_>) -> Result<String, LintError>
fn as_any(&self) -> &dyn Any
Provided Methods§
Sourcefn should_skip(&self, _ctx: &LintContext<'_>) -> bool
fn should_skip(&self, _ctx: &LintContext<'_>) -> bool
Check if this rule should quickly skip processing based on content
Sourcefn category(&self) -> RuleCategory
fn category(&self) -> RuleCategory
Get the category of this rule for selective processing
Sourcefn default_config_section(&self) -> Option<(String, Value)>
fn default_config_section(&self) -> Option<(String, Value)>
Returns the rule name and default config table if the rule has config.
If a rule implements this, it MUST be defined on the impl Rule for ... block,
not just the inherent impl.
Sourcefn config_aliases(&self) -> Option<HashMap<String, String>>
fn config_aliases(&self) -> Option<HashMap<String, String>>
Returns config key aliases for this rule This allows rules to accept alternative config key names for backwards compatibility
Sourcefn fix_capability(&self) -> FixCapability
fn fix_capability(&self) -> FixCapability
Declares the fix capability of this rule
Sourcefn cross_file_scope(&self) -> CrossFileScope
fn cross_file_scope(&self) -> CrossFileScope
Declares cross-file analysis requirements for this rule
Returns CrossFileScope::None by default, meaning the rule only needs
single-file context. Rules that need workspace-wide data should override
this to return CrossFileScope::Workspace.
Sourcefn contribute_to_index(
&self,
_ctx: &LintContext<'_>,
_file_index: &mut FileIndex,
)
fn contribute_to_index( &self, _ctx: &LintContext<'_>, _file_index: &mut FileIndex, )
Contribute data to the workspace index during linting
Called during the single-file linting phase for rules that return
CrossFileScope::Workspace. Rules should extract headings, links,
and other data needed for cross-file validation.
This is called as a side effect of linting, so LintContext is already created - no duplicate parsing required.
Sourcefn cross_file_check(
&self,
_file_path: &Path,
_file_index: &FileIndex,
_workspace_index: &WorkspaceIndex,
) -> LintResult
fn cross_file_check( &self, _file_path: &Path, _file_index: &FileIndex, _workspace_index: &WorkspaceIndex, ) -> LintResult
Perform cross-file validation after all files have been linted
Called once per file after the entire workspace has been indexed. Rules receive the file_index (from contribute_to_index) and the full workspace_index for cross-file lookups.
Note: This receives the FileIndex instead of LintContext to avoid re-parsing each file. The FileIndex was already populated during contribute_to_index.
Rules can use workspace_index methods for cross-file validation:
get_file(path)- to look up headings in target files (for MD051)files()- to iterate all indexed files
Returns additional warnings for cross-file issues. These are appended to the single-file warnings.