Trait EarlyLintPass

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

Source

fn check_expr(&mut self, _ctx: &LintContext<'_>, _expr: &'ast Expr<'ast>)

Source

fn check_item_struct( &mut self, _ctx: &LintContext<'_>, _struct: &'ast ItemStruct<'ast>, )

Source

fn check_item_function( &mut self, _ctx: &LintContext<'_>, _func: &'ast ItemFunction<'ast>, )

Source

fn check_variable_definition( &mut self, _ctx: &LintContext<'_>, _var: &'ast VariableDefinition<'ast>, )

Source

fn check_import_directive( &mut self, _ctx: &LintContext<'_>, _import: &'ast ImportDirective<'ast>, )

Source

fn check_using_directive( &mut self, _ctx: &LintContext<'_>, _using: &'ast UsingDirective<'ast>, )

Source

fn check_item_contract( &mut self, _ctx: &LintContext<'_>, _contract: &'ast ItemContract<'ast>, )

Source

fn check_doc_comment(&mut self, _ctx: &LintContext<'_>, _cmnt: &'ast DocComment)

Source

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§

Source§

impl<'ast> EarlyLintPass<'ast> for IncorrectShift

Source§

impl<'ast> EarlyLintPass<'ast> for UncheckedCall

Source§

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.

Source§

impl<'ast> EarlyLintPass<'ast> for Imports

Source§

impl<'ast> EarlyLintPass<'ast> for MixedCaseFunction

Source§

impl<'ast> EarlyLintPass<'ast> for MixedCaseVariable

Source§

impl<'ast> EarlyLintPass<'ast> for PascalCaseStruct

Source§

impl<'ast> EarlyLintPass<'ast> for ScreamingSnakeCase

Source§

impl<'ast> EarlyLintPass<'ast> for DivideBeforeMultiply