Skip to content

fix(lint): warn when a named path is a test or script - #18538

Merged
mattsse merged 4 commits into
foundry-rs:masterfrom
pjdurden:fix/17992
Nov 28, 2026
Merged

mattsse merged 4 commits into
foundry-rs:masterfrom
pjdurden:fix/17992

Conversation

@pjdurden

Copy link
Copy Markdown
Contributor

Notes for #17992

1. Root cause

Since 1.8.2 (#16663) ForgeLintSuite::active_lints in crates/lint/src/sol/mod.rs
drops every lint except unsafe-cheatcode and environment-read-across-mutation
for files under the configured test and script directories. That filter is
intended, 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 warnings exits 0 with empty output even
though almost no lint ran. The PATH help text ("Overrides the ignore project
config") 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 lint now prints a Warning: on stderr when explicitly named paths
    resolve to at least one file under the configured test/script directories
    and 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-lint selects only lints that do run on tests and scripts (so
    forge geiger, an alias for --only-lint unsafe-cheatcode, is unaffected).
  • The exempt lint IDs moved from an inline matches! to a public
    TEST_AND_SCRIPT_LINTS constant in the lint crate, which owns the policy, so
    the CLI message and the filter cannot drift apart.
  • The PATH help text now says test and script files are only checked by the
    applicable lints even when named.

The exit code is unchanged (the warning is a shell warning, not a lint
diagnostic, so --deny warnings does not turn it into a failure).

3. Files changed

  • crates/lint/src/sol/mod.rs: add TEST_AND_SCRIPT_LINTS, use it in active_lints.
  • crates/forge/src/cmd/lint.rs: emit the warning, extend PATH help.
  • crates/forge/tests/cli/lint.rs: new warns_when_named_path_is_test_or_script.

4. Risk / uncertainty

  • Not compiled or run: this machine has no Rust toolchain (cargo is not
    installed), so the code, formatting (cargo +nightly fmt), clippy and the new
    test are unverified. The snapshot in the new test was written by hand; the
    incorrect-shift block is copied from the existing can_override_config_lint
    snapshot for the same fixture.
  • The issue is labelled T-to-discuss with no maintainer response. Maintainers
    may prefer a different behavior (lint named test/script paths fully, a
    [lint] option, or a note also for project-wide runs). This change takes only
    the reporter's smallest proposal (item 1 plus the help-text half of item 2).
  • The book fixes mentioned in the issue (forge/linting.mdx) live in
    foundry-rs/book and are not part of this change.
  • If the generated CLI reference or a help snapshot embeds the forge lint
    PATH help, it will need regenerating; none was found in this repo.
  • The warning fires once per run for directories too (e.g. forge lint . in a
    project 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 same
canonicalize + is_test_or_script check for the warning. No build, test, fmt or
clippy run was possible here. To verify:

cargo nextest run -p forge --test cli lint::
cargo +nightly fmt --all -- --check
cargo +nightly clippy -p forge -p forge-lint --all-targets

Copilot AI balanced review requested due to automatic review settings November 17, 2026 15:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread crates/forge/tests/cli/lint.rs Resolved
figtracer
figtracer previously approved these changes Nov 24, 2026
mattsse
mattsse previously approved these changes Nov 27, 2026
@mattsse
mattsse enabled auto-merge (squash) November 27, 2026 20:56
auto-merge was automatically disabled November 27, 2026 21:02

Head branch was pushed to by a user without write access

@mattsse
mattsse enabled auto-merge (squash) November 27, 2026 21:04
@mattsse
mattsse dismissed stale reviews from figtracer and themself via 666d2a4 November 27, 2026 21:23

@stevencartavia stevencartavia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@mattsse
mattsse merged commit 3d33562 into foundry-rs:master Nov 28, 2026
29 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants