Skip to content

Conversation

grandizzy
Copy link
Collaborator

@grandizzy grandizzy commented Aug 8, 2025

Motivation

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@grandizzy grandizzy marked this pull request as ready for review August 8, 2025 13:20
@grandizzy grandizzy requested a review from 0xrusowsky August 8, 2025 13:20
Copy link
Contributor

@0xrusowsky 0xrusowsky left a comment

Choose a reason for hiding this comment

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

the changes look good, but i am wondering if it is desirable to have this behavior? we already exclude gas and codesize lints from tests and scripts.

if we think its desirable (i am not against it), imo it would be better to configure it via a flag in foundry.toml, rather than users having to explicitly include tests and scripts.

this way users would easily know the behavior that they have configured.. having to pass the script/ and test/ paths every time, is more tedious than simply changing a config flag.

@grandizzy
Copy link
Collaborator Author

grandizzy commented Aug 8, 2025

the changes look good, but i am wondering if it is desirable to have this behavior? we already

this way users would easily know the behavior that they have configured.. having to pass the script/ and test/ paths every time, is more tedious than simply changing a config flag.

yep, agree, this makes sense, so we will lint src, test and scripts by default but not libs. Also lint only files we build if they're specified Cc @aviggiano

@aviggiano
Copy link

Makes sense! Good feature

@grandizzy grandizzy marked this pull request as draft August 8, 2025 14:12
@grandizzy grandizzy changed the title fix(lint): lint src only by default and files that we build fix(lint): lint src/script/test only by default and files that we build Aug 8, 2025
@grandizzy grandizzy changed the title fix(lint): lint src/script/test only by default and files that we build fix(lint): lint only files that we build Aug 15, 2025
@grandizzy grandizzy requested a review from 0xrusowsky August 15, 2025 09:22
@grandizzy grandizzy marked this pull request as ready for review August 15, 2025 09:22
@@ -118,13 +118,13 @@ impl BuildArgs {

// Only run the `SolidityLinter` if there are no compilation errors
if !output.output().errors.iter().any(|e| e.is_error()) {
self.lint(&project, &config).map_err(|err| eyre!("Lint failed: {err}"))?;
self.lint(&project, &config, &self.paths).map_err(|err| eyre!("Lint failed: {err}"))?;
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 not get the paths from the compiler output instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure we want this as will mean that we won't lint contracts that are already built, e.g. we will show lint errors only first time for forge build src/utils/BaseVault.sol but not on subsequent forge build src/utils/BaseVault.sol (same with forge build entire project). I think we want to always lint the files, wdyt?

Copy link
Member

@DaniPopes DaniPopes Aug 18, 2025

Choose a reason for hiding this comment

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

that's true for output, however we can check the paths from artifacts_with_files().

Copy link
Member

Choose a reason for hiding this comment

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

with that we can simply pass the paths from artifacts_with_files() to lint and avoid having to input_files_iter

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hm, isn't this the same, artifacts_with_files() returns cached and compiled artifacts, so if we call forge build src/utils/BaseVault.sol again (and BaseVault.sol is not recompiled) then we won't know to lint BaseVault.sol only, maybe I am missing something?

Copy link
Member

Choose a reason for hiding this comment

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

we can do both

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@DaniPopes artifacts_with_files returns all artifacts including artifacts from deps while input_files_iter returns only src, test and scripts that we want to lint. Could use artifacts_with_files but then have to filter out deps artifacts - IMO is cleaner by input_files_iter but happy to change if you strongly think we should use artifacts_with_files. thank you!

Copy link
Member

Choose a reason for hiding this comment

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

I see, that is fine then

0xrusowsky
0xrusowsky previously approved these changes Aug 15, 2025
Copy link
Contributor

@0xrusowsky 0xrusowsky left a comment

Choose a reason for hiding this comment

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

lgtm

0xrusowsky
0xrusowsky previously approved these changes Aug 18, 2025
zerosnacks
zerosnacks previously approved these changes Aug 18, 2025
Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

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

lgtm, makes sense 👍

@@ -118,13 +118,14 @@ impl BuildArgs {

// Only run the `SolidityLinter` if there are no compilation errors
if !output.output().errors.iter().any(|e| e.is_error()) {
Copy link
Member

Choose a reason for hiding this comment

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

the condition above can be merged with this one: config.lint.lint_on_build &&

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep, simplified in 7722419

@grandizzy grandizzy dismissed stale reviews from zerosnacks and 0xrusowsky via 7722419 August 18, 2025 08:09
@grandizzy grandizzy self-assigned this Aug 18, 2025
@grandizzy grandizzy moved this to Ready For Review in Foundry Aug 18, 2025
@0xrusowsky 0xrusowsky merged commit ead9577 into foundry-rs:master Aug 19, 2025
22 checks passed
@github-project-automation github-project-automation bot moved this from Ready For Review to Done in Foundry Aug 19, 2025
grandizzy added a commit to grandizzy/foundry that referenced this pull request Aug 20, 2025
@grandizzy grandizzy mentioned this pull request Aug 20, 2025
3 tasks
grandizzy added a commit that referenced this pull request Aug 20, 2025
* fix(lint): explicit message when lint on build failures (#11224)

* fix(lint): lint only files that we build (#11247)

* fix: force 4844 txtype in blobhashes setter (#11355)

* test: add blobhashes repro

* fix: force 4844 tx type

* fix(forge): handle error if etherscan identifier cannot resolve config (#11356)

* fix(forge): handle error if etherscan identifier cannot resolve config

* warn on config failures

* fix: disable tx gas limit cap (#11347)

* fix(forge): write ordered deps in foundry.lock (#11360)

* chore: fix clippy (#11361)

* chore: bump version 1.3.2 (#11363)

* chore: fix cargo deny - update slab to 0.4.11

---------

Co-authored-by: Matthias Seitz <[email protected]>
@grandizzy grandizzy moved this from Done to Completed in Foundry Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

bug(forge lint): lint only files that we build
5 participants