Skip to content

feat(forge-lint): new LateLintPass + support code snippets #10846

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

Merged
merged 56 commits into from
Jul 16, 2025

Conversation

0xrusowsky
Copy link
Contributor

@0xrusowsky 0xrusowsky commented Jun 25, 2025

TODO:

  • release solar + foundry compilers --> remove patches

Motivation

Boost forge-lint capabilities by adding 2 new features:

Implementation

Linter Architecture

Updated the architecture to a dual-pass system:

  • Early lint passes (AST-based) for syntax-level checks
  • Late lint passes (HIR-based) for semantic analysis after type resolution

Relevant changes:

  • Added trait LateLintPass and implemented a LateLintVisitor that traverses the HIR + runs late lint passes.
  • Updated the trait Linter to support both early (AST) and late (HIR) linting phases.
  • Added a new input to the lint helper macros which can be either early or late.

Code Snippet Support

  • Introduced enum Snippet to represent code suggestions:
pub enum Snippet {
    /// Represents a code block. Can have an optional description.
    Block { desc: Option<&'static str>, code: String },
    /// Represents a code diff.
    /// Includes an optional description, the code to remove, and a replacement proposal.
    Diff { desc: Option<&'static str>, rmv: String, add: String },
}
  • Added fn emit_with_fix() method to LintContext to emit diagnostics with (formatted) snippets

@0xrusowsky 0xrusowsky self-assigned this Jun 25, 2025
@0xrusowsky 0xrusowsky linked an issue Jun 25, 2025 that may be closed by this pull request
@0xrusowsky 0xrusowsky added T-feature Type: feature Cmd-forge-lint Command: forge lint labels Jun 25, 2025
DaniPopes pushed a commit to paradigmxyz/solar that referenced this pull request Jun 25, 2025
i was working on improved lints that would show code diffs, and i
realized that despite using `fn highlighted_note`, the `fn
flatten_messages` would remove the style.

so this PR aims to enhance `fn flatten_messages` to optionally preserve
styles while flattening (depending on whether the emitter supports
styles or not).

i added a new `fn label_with_style()` to try to avoid breaking API
changes for solar users, but not sure if may have missed something.
@DaniPopes please lmk if the approach looks good or if we should do it
differently.

PS: `forge-lint` PR in case it is useful
foundry-rs/foundry#10846
@0xrusowsky 0xrusowsky moved this to In Progress in Foundry Jul 1, 2025
@0xrusowsky 0xrusowsky changed the title feat(forge-lint): add support for code (snippets) examples feat(forge-lint): new LateLintPass + support code snippets Jul 9, 2025
@0xrusowsky 0xrusowsky requested a review from DaniPopes July 15, 2025 13:28
@0xrusowsky 0xrusowsky requested a review from zerosnacks July 15, 2025 15:13
@zerosnacks
Copy link
Member

lgtm! Pending review from @DaniPopes / @grandizzy

grandizzy
grandizzy previously approved these changes Jul 16, 2025
Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! pending @DaniPopes review, this should also unblock #10980

Self::Diff { desc, .. } => *desc,
Self::Block { desc, .. } => *desc,
}
}
}

/// Trait for lints that operate directly on the AST.
/// Its methods mirror `ast::visit::Visit`, with the addition of `LintCotext`.
pub trait EarlyLintPass<'ast>: Send + Sync {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move these to early.rs and late.rs

&sess,
&self.build,
None,
Some(vec![self.target_path].as_ref()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no vec! needed

DaniPopes
DaniPopes previously approved these changes Jul 16, 2025
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@0xrusowsky 0xrusowsky merged commit 03e3dbc into master Jul 16, 2025
22 checks passed
@0xrusowsky 0xrusowsky deleted the rusowsky/lints-with-examples branch July 16, 2025 18:15
@github-project-automation github-project-automation bot moved this from Ready For Review to Done in Foundry Jul 16, 2025
@grandizzy grandizzy moved this from Done to Completed in Foundry Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cmd-forge-lint Command: forge lint T-feature Type: feature
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

feat(forge-lint): support code examples
5 participants