Repository navigation
fix(lint): warn when a named path is a test or script - #18538
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Signed-off-by: pjdurden <[email protected]>
Signed-off-by: pjdurden <[email protected]>
Head branch was pushed to by a user without write access
stevencartavia
left a comment
There was a problem hiding this comment.
Reviewed against base 9610e13. The warning check mirrors the linter's own canonicalize + is_test_or_script filter, the exempt IDs now come from one constant in forge-lint, and it is correctly skipped for bare runs and for --only-lint selections limited to test/script lints (so forge geiger is unaffected). New and updated lint CLI tests pass in CI on this head; the remaining test-all failure (anvil tempo sponsor test) also fails on master.
Notes for #17992
1. Root cause
Since 1.8.2 (#16663)
ForgeLintSuite::active_lintsincrates/lint/src/sol/mod.rsdrops every lint except
unsafe-cheatcodeandenvironment-read-across-mutationfor files under the configured
testandscriptdirectories. That filter isintended, but it is applied per source file inside the linter, so it also applies
to a path the user names on the command line.
forge lint(crates/forge/src/cmd/lint.rs)had no knowledge of the filter and printed nothing, so
forge lint script/Deploy.s.sol --deny warningsexits 0 with empty output eventhough almost no lint ran. The
PATHhelp text ("Overrides theignoreprojectconfig") reinforced the impression that a named path is fully linted.
2. The fix and why
The issue reporter states the test/script filtering itself is intended and
proposes, as the smallest fix, to stop being silent. That is what this change does:
forge lintnow prints aWarning:on stderr when explicitly named pathsresolve to at least one file under the configured
test/scriptdirectoriesand at least one selected lint is not in the test/script set. It is not printed
for a bare
forge lint(project-wide runs keep their current output), nor when--only-lintselects only lints that do run on tests and scripts (soforge geiger, an alias for--only-lint unsafe-cheatcode, is unaffected).matches!to a publicTEST_AND_SCRIPT_LINTSconstant in the lint crate, which owns the policy, sothe CLI message and the filter cannot drift apart.
PATHhelp text now says test and script files are only checked by theapplicable lints even when named.
The exit code is unchanged (the warning is a shell warning, not a lint
diagnostic, so
--deny warningsdoes not turn it into a failure).3. Files changed
crates/lint/src/sol/mod.rs: addTEST_AND_SCRIPT_LINTS, use it inactive_lints.crates/forge/src/cmd/lint.rs: emit the warning, extendPATHhelp.crates/forge/tests/cli/lint.rs: newwarns_when_named_path_is_test_or_script.4. Risk / uncertainty
cargois notinstalled), so the code, formatting (
cargo +nightly fmt), clippy and the newtest are unverified. The snapshot in the new test was written by hand; the
incorrect-shiftblock is copied from the existingcan_override_config_lintsnapshot for the same fixture.
T-to-discusswith no maintainer response. Maintainersmay prefer a different behavior (lint named test/script paths fully, a
[lint]option, or a note also for project-wide runs). This change takes onlythe reporter's smallest proposal (item 1 plus the help-text half of item 2).
forge/linting.mdx) live infoundry-rs/bookand are not part of this change.forge lintPATHhelp, it will need regenerating; none was found in this repo.forge lint .in aproject with tests), which is accurate but adds a line of stderr output.
5. Verification
Static review only: traced
LintArgs::run->configure_pcx_all_sources(canonicalizes named paths) ->
ForgeLintSuite::active_lints(
path_config.is_test_or_script) to confirm the cause, and mirrored the samecanonicalize +
is_test_or_scriptcheck for the warning. No build, test, fmt orclippy run was possible here. To verify: