Skip to content

chore(lint): allow restriction/pedantic lints in test cfg only#292

Merged
sachiniyer merged 2 commits intomainfrom
siyer/clippy-allow-unwrap-in-tests
May 9, 2026
Merged

chore(lint): allow restriction/pedantic lints in test cfg only#292
sachiniyer merged 2 commits intomainfrom
siyer/clippy-allow-unwrap-in-tests

Conversation

@sachiniyer
Copy link
Copy Markdown
Contributor

Summary

  • cargo clippy --all-targets was failing with 238 errors, all in test code
  • Scope the restriction lints (unwrap_used, expect_used, panic, as_conversions, cast_sign_loss, cast_possible_wrap) and a handful of pedantic lints that only fire on test code to cfg(test) via #![cfg_attr(test, allow(...))] in src/lib.rs, src/main.rs, and tests/integration.rs
  • Production code is unaffected — the same lints still deny outside test cfg

Why

unwrap/expect/panic and similar lints are idiomatic in tests, where panicking on bad assumptions is the desired failure mode. Tests are also a common place for one-off casts (as), pedantic style nits (needless_collect, redundant_closure_for_method_calls), and integration-test layout (tests_outside_test_module). Holding tests to the same bar as production created 200+ false-positive errors with no production benefit.

The reason string on each allow block satisfies clippy::allow_attributes_without_reason, which is denied repo-wide.

Test plan

  • cargo clippy --all-targets — 0 errors, 0 warnings
  • cargo check
  • cargo test --lib — 290 tests pass

🤖 Generated with Claude Code

All clippy violations from these lints lived inside `#[cfg(test)]`
modules (and the `tests/` integration crate); none were in production
code. Scope the restriction lints (`unwrap_used`, `expect_used`,
`panic`, `as_conversions`, `cast_sign_loss`, `cast_possible_wrap`) and
a few pedantic ones that only fired on test code (`needless_collect`,
`absolute_paths`, `if_then_some_else_none`, `doc_markdown`,
`semicolon_outside_block`, plus the integration-test-only
`redundant_closure_for_method_calls` and `tests_outside_test_module`)
to test cfg via `#![cfg_attr(test, allow(...))]`. Production code is
still held to the same bar.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sachiniyer sachiniyer temporarily deployed to integration-tests May 9, 2026 04:18 — with GitHub Actions Inactive
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

The binary crate has no tests, so the test-cfg allow block had no
effect. lib.rs already covers all `#[cfg(test)] mod tests` in src/
since they compile as part of the lib crate; tests/integration.rs
keeps its own block because it's a separate crate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sachiniyer sachiniyer temporarily deployed to integration-tests May 9, 2026 04:49 — with GitHub Actions Inactive
@sachiniyer sachiniyer enabled auto-merge (squash) May 9, 2026 04:49
@sachiniyer sachiniyer merged commit aad53d3 into main May 9, 2026
13 checks passed
@sachiniyer sachiniyer deleted the siyer/clippy-allow-unwrap-in-tests branch May 9, 2026 04:52
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.

1 participant