Skip to content

Conversation

@alexdewar
Copy link
Collaborator

Description

By default, it seems that clippy does 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-targets flag). (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's restriction group. (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 clippy warnings can be autofixed. Unfortunately, the pre-commit hook we're using doesn't support this, but if you run cargo 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 like HashMaps, 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 gotcha
  • clone_on_ref_ptr - apparently it's more conventional to write Rc::clone(&thing) than thing.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 churn

Type of change

  • Bug fix (non-breaking change to fix an issue)
  • New feature (non-breaking change to add functionality)
  • Refactoring (non-breaking, non-functional change to improve maintainability)
  • Optimization (non-breaking change to speed up the code)
  • Breaking change (whatever its nature)
  • Documentation (improve or add documentation)

Key checklist

  • All tests pass: $ cargo test
  • The documentation builds and looks OK: $ cargo doc

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

❌ Patch coverage is 96.96970% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.78%. Comparing base (09cb2cd) to head (c5dc784).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/input/process/investment_constraints.rs 71.42% 2 Missing ⚠️
src/graph.rs 0.00% 1 Missing ⚠️
src/time_slice.rs 80.00% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a 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-targets flag 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.

@alexdewar alexdewar added this to MUSE Dec 22, 2025
@alexdewar alexdewar moved this to 👀 In review in MUSE Dec 22, 2025
@alexdewar
Copy link
Collaborator Author

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! 🎄

@alexdewar alexdewar marked this pull request as draft December 22, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

2 participants