Skip to content

Commit

Permalink
Fix non-test lints applying to tests. (#81)
Browse files Browse the repository at this point in the history
The lints in `lib.rs` are not supposed to apply to tests according to
the comment. This is a good idea, because there are a lot of false
positives with tests. However the lint is still applied to tests.

Currently all the repos have ad hoc workarounds. See e.g.
[Xilem](https://github.com/linebender/xilem/blob/363e4222c29cbddf174570af5d4a5b448d3fb73e/xilem/src/lib.rs#L14-L20),
[Kurbo](https://github.com/linebender/kurbo/blob/8f074e921e3425b97c522fd38fb9593b0aef3aa4/src/svg.rs#L629-L635),
and
[Velato](https://github.com/linebender/velato/blob/2d6cd9516f93d662c6ea4096bbf837b8151dfc76/src/lib.rs#L74).

The solution is to actually only enable this lint when `test` isn't
enabled.

Might as well do the same for `clippy::trivially_copy_pass_by_ref` as
it's probably more annoying than valuable in tests.

I also moved the comment to a single line. It is a single sentence and
under our 100 character line limit. Helps reduce the line count of the
lint set.

I swapped the order to `clippy::print_stderr` and `clippy::print_stderr`
so that they are alphabetically ordered, as is the case with our other
lints.
  • Loading branch information
xStrom authored Dec 7, 2024
1 parent 9b25ad3 commit 721dc41
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions content/wiki/canonical_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ clippy.wildcard_dependencies = "warn"
## `lib.rs`

```rust
// LINEBENDER LINT SET - lib.rs - v2
// LINEBENDER LINT SET - lib.rs - v3
// See https://linebender.org/wiki/canonical-lints/
// These lints aren't included in Cargo.toml because they
// shouldn't apply to examples and tests
#![warn(unused_crate_dependencies)]
// These lints shouldn't apply to examples or tests.
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
// These lints shouldn't apply to examples.
#![warn(clippy::print_stdout, clippy::print_stderr)]
// Targeting e.g. 32-bit means structs containing usize can give false positives for 64-bit.
#![cfg_attr(target_pointer_width = "64", warn(clippy::trivially_copy_pass_by_ref))]
Expand Down

0 comments on commit 721dc41

Please sign in to comment.