Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forge-lint): Refactor linting to enable support for multiple languages #5

Merged
merged 21 commits into from
Dec 29, 2024

Conversation

0xKitsune
Copy link
Owner

@0xKitsune 0xKitsune commented Dec 29, 2024

This PR introduces a new ProjectLinter type that enables support for any linter that implements the Linter trait. This will allow other languages like Vyper to implement linting without changes to forge lint.

pub struct ProjectLinter<L>
where
    L: Linter,
{
    pub linter: L,
}

// --snip--

pub trait Linter: Send + Sync + Clone {
    type Language: Language;
    type Lint: Lint + Ord;
    type LinterError: Error;

    fn lint(&self, input: &[PathBuf]) -> Result<LinterOutput<Self>, Self::LinterError>;
}

Currently, forge lint infers the linter via the Project struct. The only linter supported at the moment is the SolidityLinter.

impl LintArgs {
    pub fn run(self) -> Result<()> {
        let config = self.try_load_config_emit_warnings()?;
        let project = config.project()?;
     
        // --snip--
     
        let linter = if project.compiler.solc.is_some() {
            SolidityLinter::new()
                .with_severity(self.severity)
                .with_description(self.with_description)
        } else {
            todo!("Linting not supported for this language");
        };

      // --snip--

      let output = ProjectLinter::new(linter).lint(&sources)?;
    }
}

@0xKitsune 0xKitsune merged commit 8551634 into master Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant