Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ rust-version = "1.90.0"
members = [
"compiler/ast",
"compiler/compiler",
"compiler/linter",
"compiler/parser-lossless",
"compiler/parser",
"compiler/passes",
Expand Down Expand Up @@ -65,6 +66,10 @@ version = "=3.3.1"
path = "./interpreter"
version = "=3.3.1"

[workspace.dependencies.leo-linter]
path = "./compiler/linter"
version = "=3.3.1"

[workspace.dependencies.leo-package]
path = "./leo/package"
version = "=3.3.1"
Expand Down Expand Up @@ -195,6 +200,9 @@ workspace = true
[dependencies.leo-interpreter]
workspace = true

[dependencies.leo-linter]
workspace = true

[dependencies.leo-package]
workspace = true

Expand Down
55 changes: 55 additions & 0 deletions compiler/linter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[package]
name = "leo-linter"
version = "3.3.1"
authors = [ "The Leo Team <[email protected]>" ]
description = "Linter for Leo programming language"
homepage = "https://leo-lang.org"
repository = "https://github.com/ProvableHQ/leo"
keywords = [
"aleo",
"cryptography",
"leo",
"programming-language",
"zero-knowledge"
]
categories = [ "compilers", "cryptography", "web-programming" ]
include = [ "Cargo.toml", "src", "LICENSE.md" ]
license = "GPL-3.0"
edition = "2024"
rust-version = "1.88.0"

[dependencies.leo-ast]
workspace = true

[dependencies.leo-errors]
workspace = true

[dependencies.leo-compiler]
workspace = true

[dependencies.leo-parser]
workspace = true

[dependencies.leo-parser-lossless]
workspace = true

[dependencies.leo-passes]
workspace = true

[dependencies.leo-span]
workspace = true

[dependencies.indexmap]
workspace = true

[dependencies.walkdir]
workspace = true

[dev-dependencies.snarkvm]
workspace = true

[dev-dependencies.serial_test]
workspace = true

[dev-dependencies.leo-test-framework]
workspace = true
596 changes: 596 additions & 0 deletions compiler/linter/LICENSE.md

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions compiler/linter/src/context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (C) 2019-2025 Provable Inc.
// This file is part of the Leo library.

// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.

use leo_errors::Lint;
use leo_passes::CompilerState;

use crate::diagnostics::DiagnosticReport;

/// Context for the Late lint pass.
#[derive(Clone, Copy)]
pub struct LateContext<'ctx> {
#[expect(dead_code)]
state: &'ctx CompilerState,
report: &'ctx DiagnosticReport,
}

impl<'ctx> LateContext<'ctx> {
pub fn new(report: &'ctx DiagnosticReport, state: &'ctx CompilerState) -> LateContext<'ctx> {
Self { state, report }
}

pub fn emit_lint(&self, lint: Lint) {
self.report.emit_lint(lint);
}
}

/// Context for the early lint pass.
#[derive(Clone, Copy)]
pub struct EarlyContext<'ctx> {
report: &'ctx DiagnosticReport,
}

impl<'ctx> EarlyContext<'ctx> {
pub fn new(report: &'ctx DiagnosticReport) -> EarlyContext<'ctx> {
Self { report }
}

pub fn emit_lint(&self, lint: Lint) {
self.report.emit_lint(lint);
}
}
47 changes: 47 additions & 0 deletions compiler/linter/src/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (C) 2019-2025 Provable Inc.
// This file is part of the Leo library.

// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.

use leo_errors::Lint;

use std::cell::RefCell;

/// All the triggered lints are collected here, as we traverse
/// the syntax trees and perform various lints.
#[derive(Default)]
pub struct DiagnosticReport {
inner: RefCell<DiagnosticReportInner>,
}

impl DiagnosticReport {
pub fn emit_lint(&self, lint: Lint) {
self.inner.borrow_mut().emit_lint(lint);
}

pub fn consume(self) -> Vec<Lint> {
self.inner.into_inner().collected
}
}

#[derive(Default)]
struct DiagnosticReportInner {
collected: Vec<Lint>,
}

impl DiagnosticReportInner {
fn emit_lint(&mut self, lint: Lint) {
self.collected.push(lint);
}
}
26 changes: 26 additions & 0 deletions compiler/linter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2019-2025 Provable Inc.
// This file is part of the Leo library.

// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.

mod context;
mod diagnostics;
mod linter;
mod lints;
mod passes;
#[cfg(test)]
mod test;

pub use linter::Linter;
pub use passes::*;
Loading