-
Notifications
You must be signed in to change notification settings - Fork 1
Also lint test code with clippy and enable additional lints
#1050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1050 +/- ##
==========================================
+ Coverage 81.75% 81.78% +0.03%
==========================================
Files 53 53
Lines 7263 7254 -9
Branches 7263 7254 -9
==========================================
- Hits 5938 5933 -5
+ Misses 1030 1026 -4
Partials 295 295 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enables clippy linting for test code and adds additional clippy lints to improve code quality. The main changes involve configuration updates to run clippy on all targets, adding new lint rules, and applying automatic fixes throughout the codebase.
Key Changes
- Added
--all-targetsflag to clippy configuration to lint test code - Enabled 12 additional clippy lints from the restriction group in
Cargo.toml - Removed
test_prefix from test function names per Rust conventions - Applied various clippy-suggested improvements (string literals, unwrap patterns, etc.)
Reviewed changes
Copilot reviewed 49 out of 49 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
.cargo/config.toml |
Updated clipfix alias to include --all-targets |
.pre-commit-config.yaml |
Added --all-targets argument to clippy hook |
Cargo.toml |
Added 12 new clippy lint rules to deny list |
tests/*.rs |
Removed test_ prefix from test function names |
src/year.rs |
Simplified conditional logic, removed test prefixes |
src/time_slice.rs |
Fixed string literals, removed test prefixes, renamed deserializer parameters |
src/simulation/prices.rs |
Removed test prefixes, added allow for too_many_arguments |
src/simulation/optimisation.rs |
Refactored filter_map to filter + map chain |
src/simulation/optimisation/constraints.rs |
Simplified map access pattern |
src/simulation/investment.rs |
Removed test prefixes |
src/settings.rs |
Used split_once instead of manual string parsing, removed test prefixes |
src/region.rs |
Changed assert patterns to unwrap_err, removed test prefixes |
src/process.rs |
Used shorthand field initialization, removed test prefixes, removed references |
src/patch.rs |
Removed test prefixes, simplified string literals |
src/output.rs |
Removed test prefixes, changed test data values, used shorthand initialization |
src/model/parameters.rs |
Changed assert patterns to unwrap, removed test prefixes |
src/input/time_slice.rs |
Fixed doc comment formatting, removed test prefixes |
src/input/region.rs |
Fixed doc comment formatting, removed test prefixes |
src/input/process/*.rs |
Changed assert patterns to unwrap, removed test prefixes, improved error messages |
src/input/commodity/*.rs |
Removed test prefixes, moved helper functions, changed assert patterns |
src/input/agent/*.rs |
Removed test prefixes, used String::new(), changed assert patterns |
src/input.rs |
Fixed doc comment formatting, changed assert patterns, removed test prefixes |
src/id.rs |
Changed assert patterns to unwrap_err, removed test prefixes |
src/graph/*.rs |
Changed assert patterns to unwrap, removed test prefixes, simplified map access |
src/fixture.rs |
Updated doc comments to use backticks, changed test data values, used String::new() |
src/finance.rs |
Removed test prefixes, added allow for unreadable_literal |
src/commodity.rs |
Removed test prefixes, removed unnecessary clone |
src/asset.rs |
Removed test prefixes, added float comparison helper, used assert_approx_eq |
tests/regression.rs |
Fixed string literals, improved file extension checking |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Ugh CI is failing because it's trying to lint a generated file. Guess I'll fix this in the new year... Merry Christmas, all! 🎄 |
Description
By default, it seems that
clippydoes not test code (i.e. unit tests and integration tests). While this isn't the end of the world, I figured we might as well enable it to have tidier test code (to do this, you pass the--all-targetsflag). (I find it's also handy for learning more idiomatic ways to write Rust code too.)While I was at it, I enabled a bunch of lints from
clippy'srestrictiongroup. (For a full list of lints, see here.)One of these lints is to remove the
test_prefix from test function names (redundant_test_prefix) and this has caused a fair amount of churn. Apparantly it's not really the convention in Rust, so I thought we might as well do it that way -- previously there was an inconsistent mix. I've also fixed up the tests with the#[rstest]attribute, which isn't covered by the lint (as an external crate), for consistency.Hopefully none of this is too controversial! I have made these changes as separate commits, so should be able to revert any that people don't like.
Remember that many
clippywarnings can be autofixed. Unfortunately, thepre-commithook we're using doesn't support this, but if you runcargo clipfix(an alias we've defined), that should fix all the fixable warnings.There were a couple more lints that I considered but decided against for now:
iter_over_hash_type- warns when you iterate over things likeHashMaps, which have a non-deterministic ordering. There are some false positives, but it might be worth enabling at some point as it is a bit of a gotchaclone_on_ref_ptr- apparently it's more conventional to writeRc::clone(&thing)thanthing.clone(), because in the latter case it's not obvious that it's only a shallow copy. Decided against because it would create a lot of churnType of change
Key checklist
$ cargo test$ cargo docFurther checks