-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(lint): lint only files that we build #11247
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
Conversation
There was a problem hiding this 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.
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 |
Makes sense! Good feature |
crates/forge/src/cmd/build.rs
Outdated
@@ -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}"))?; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can do both
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
Co-authored-by: DaniPopes <[email protected]>
Co-authored-by: DaniPopes <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, makes sense 👍
crates/forge/src/cmd/build.rs
Outdated
@@ -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()) { |
There was a problem hiding this comment.
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 &&
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, simplified in 7722419
* 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]>
Motivation
forge lint
): lint only files that we build #11234forge build path
then lint only path that we buildSolution
PR Checklist