pub trait EarlyLintPass<'ast>: Send + Sync {
// Provided methods
fn check_expr(&mut self, _ctx: &LintContext<'_>, _expr: &'ast Expr<'ast>) { ... }
fn check_item_struct(
&mut self,
_ctx: &LintContext<'_>,
_struct: &'ast ItemStruct<'ast>,
) { ... }
fn check_item_function(
&mut self,
_ctx: &LintContext<'_>,
_func: &'ast ItemFunction<'ast>,
) { ... }
fn check_variable_definition(
&mut self,
_ctx: &LintContext<'_>,
_var: &'ast VariableDefinition<'ast>,
) { ... }
fn check_import_directive(
&mut self,
_ctx: &LintContext<'_>,
_import: &'ast ImportDirective<'ast>,
) { ... }
fn check_using_directive(
&mut self,
_ctx: &LintContext<'_>,
_using: &'ast UsingDirective<'ast>,
) { ... }
fn check_item_contract(
&mut self,
_ctx: &LintContext<'_>,
_contract: &'ast ItemContract<'ast>,
) { ... }
fn check_doc_comment(
&mut self,
_ctx: &LintContext<'_>,
_cmnt: &'ast DocComment,
) { ... }
fn check_full_source_unit(
&mut self,
_ctx: &LintContext<'ast>,
_ast: &'ast SourceUnit<'ast>,
) { ... }
}
Expand description
Trait for lints that operate directly on the AST.
Its methods mirror ast::visit::Visit
, with the addition of LintCotext
.
Provided Methods§
fn check_expr(&mut self, _ctx: &LintContext<'_>, _expr: &'ast Expr<'ast>)
fn check_item_struct( &mut self, _ctx: &LintContext<'_>, _struct: &'ast ItemStruct<'ast>, )
fn check_item_function( &mut self, _ctx: &LintContext<'_>, _func: &'ast ItemFunction<'ast>, )
fn check_variable_definition( &mut self, _ctx: &LintContext<'_>, _var: &'ast VariableDefinition<'ast>, )
fn check_import_directive( &mut self, _ctx: &LintContext<'_>, _import: &'ast ImportDirective<'ast>, )
fn check_using_directive( &mut self, _ctx: &LintContext<'_>, _using: &'ast UsingDirective<'ast>, )
fn check_item_contract( &mut self, _ctx: &LintContext<'_>, _contract: &'ast ItemContract<'ast>, )
fn check_doc_comment(&mut self, _ctx: &LintContext<'_>, _cmnt: &'ast DocComment)
Sourcefn check_full_source_unit(
&mut self,
_ctx: &LintContext<'ast>,
_ast: &'ast SourceUnit<'ast>,
)
fn check_full_source_unit( &mut self, _ctx: &LintContext<'ast>, _ast: &'ast SourceUnit<'ast>, )
Should be called after the source unit has been visited. Enables lints that require knowledge of the entire AST to perform their analysis.
§Performance
Since a full-AST analysis can be computationally expensive, implementations
should guard their logic by first checking if the relevant lint is enabled
using LintContext::is_lint_enabled
. This avoids performing costly work
if the user has disabled the lint.
§Example
ⓘ
fn check_full_source_unit(&mut self, ctx: &LintContext<'ast>, ast: &'ast ast::SourceUnit<'ast>) {
// Check if the lint is enabled before performing expensive work.
if ctx.is_lint_enabled(MY_EXPENSIVE_LINT.id) {
// ... perform computation and emit diagnostics ...
}
}
Implementors§
impl<'ast> EarlyLintPass<'ast> for IncorrectShift
impl<'ast> EarlyLintPass<'ast> for UncheckedCall
impl<'ast> EarlyLintPass<'ast> for UncheckedTransferERC20
WARN: can issue false positives. It does not check that the contract being called is an ERC20.
TODO: re-implement using LateLintPass
so that it can’t issue false positives.