oparlint-linting 0.0.2

Linting infrastructure for oparlint
Documentation
// SPDX-FileCopyrightText: Politik im Blick developers
// SPDX-FileCopyrightText: Wolfgang Silbermayr <wolfgang@silbermayr.at>
//
// SPDX-License-Identifier: AGPL-3.0-or-later OR EUPL-1.2

use crate::{Lint, LintSuite, LintingResult};

/// A trait to be implemented by linters which run the checks and record their results.
#[async_trait::async_trait]
pub trait Linter {
    /// Execute a lint check, and record the results.
    fn execute_lint<L: Lint<Output = O>, O>(&mut self, lint: L) -> LintingResult<O>;

    /// Execute a lint suite, end record the results.
    ///
    /// Do not override the default implementation when implementing the trait, but
    /// instead implement [`Self::execute_suite_checks`].
    async fn execute_suite<S: LintSuite<Output = O> + Send, O>(
        &mut self,
        suite: S,
    ) -> LintingResult<O> {
        self.begin_suite(&suite.identifier(), &suite.title());
        let outcome = self.execute_suite_checks(suite).await;
        self.end_suite();
        outcome
    }

    /// Execute the checks inside of a suite.
    ///
    /// This is what should be implemented by a lint suite, but never called
    /// directly from the outside. Call [`Self::execute_suite`] instead, which
    /// will set up and tear down the stage for the lint suite.
    async fn execute_suite_checks<S: LintSuite<Output = O> + Send, O>(
        &mut self,
        suite: S,
    ) -> LintingResult<O>;

    /// This function is called once before running a lint suite.
    ///
    /// Can be used for setting the stage of the lints, e.g. printing a header.
    fn begin_suite(&mut self, identifier: &str, title: &str);

    /// This function must be called once after running a set of lints.
    ///
    /// Can be used for cleaning the stage of the lints, e.g. printing a footer.
    fn end_suite(&mut self);
}