Skip to content

chore: Lint all cargo targets in CI - #203

Draft
jsonbailey wants to merge 1 commit into
mainfrom
jb/chore/clippy-deny-warnings
Draft

jsonbailey wants to merge 1 commit into
mainfrom
jb/chore/clippy-deny-warnings

Conversation

@jsonbailey

Copy link
Copy Markdown

Summary

CI already runs clippy with -D warnings, so lint findings do fail the build. What it does not do is pass --all-targets, so only the library target is linted — test modules and examples are never checked, and findings there accumulate invisibly.

Adding --all-targets surfaced four, fixed here:

Finding Location
useless_borrows_in_formatting src/events/sender.rs:356
unused import MultiContextBuilder src/client.rs:924
unused imports ContextBuilder, mockito::Matcher, test_case::test_case, ServiceEndpointsBuilder, EventFactory src/events/processor_builders.rs:342-347
example fails to compile, HyperTransport::new_https not found (E0599) examples/custom_transport.rs:67

The unused imports are not dead code. They serve tests behind #[cfg(any(feature = ...))] gates, and the SDK's default feature set satisfies those gates, so the imports only go unused under --no-default-features variants. Each import is now gated with the same expression as the test that consumes it rather than deleted. maplit::hashset is deliberately left ungated — the test using it has no gate.

The example was an oversight rather than a lint problem. print_flags and progress each declare required-features = ["hyper-rustls-native-roots"], but custom_transport had no [[example]] entry at all, so cargo built it unconditionally even though new_https() needs rustls. It now declares the same requirement as its siblings; the example's code is unchanged. This was latent because the two matrix entries that would have broken it also pass cargo-test-flags: --lib, so nothing compiled the example there.

Testing

cargo clippy --all-targets -p launchdarkly-server-sdk -- -D warnings is clean for all seven CI matrix feature combinations, asserted on exit code rather than on output:

Flags Result
(default) clean
--no-default-features clean
--no-default-features --features hyper clean
--no-default-features --features hyper-rustls-native-roots clean
--no-default-features --features hyper-rustls-webpki-roots clean
--no-default-features --features native-tls clean
--no-default-features --features hyper-rustls-native-roots,crypto-openssl clean

cargo test: 413 unit passed, 19 doc-tests passed, 0 failed — unchanged from main. The diff touches no #[test], #[tokio::test], or #[test_case] line, so no test is newly gated out. Unit tests also pass under three --no-default-features variants (397 / 408 / 408), and those counts tracking the feature gates is the cross-check that each gate matches its tests. cargo fmt --check clean. contract-tests was already clean under --all-targets and still is.

A consequence worth knowing

CI pins the toolchain from .github/variables/rust-versions.env (currently target=1.96), and check-rust-versions.yml opens an MSRV bump PR nightly. New toolchains add new lints, so widening clippy's scope means a future bump PR can go red on code nobody touched. That is the point — drift surfaces on the bump PR instead of hiding — but whoever handles those bot PRs should expect it. The sender.rs finding is an example: it does not fire on 1.96 and would have appeared at the next bump regardless.

Note this PR's own CI runs clippy on 1.96, so it verifies the --all-targets change but cannot confirm the 1.98-only finding is gone. That was verified locally.

Not in scope

--all-features does not compile, on an unrelated dependency conflict in hyper-http-proxy. Left alone.

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.

2 participants