-
Notifications
You must be signed in to change notification settings - Fork 0
Lower bumpy_road_function detection threshold to 2.5 #192
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4e6fce0
feat(bumpy_road_function): lower default threshold from 3.0 to 2.5 fo…
leynos 7fd238b
style(ui): make Mode enum public for external use
leynos de7d90b
fix(bumpy_road_function): correct path for key file in key_from_file …
leynos fcd7d48
refactor(ui): extract is_small_eligible to improve match readability
leynos a9dfaa6
fix(nextest): fix test filter to include integration binary test cases
leynos 4e36490
feat(bumpy_road_function): add DEFAULT_THRESHOLD constant and sync co…
leynos 56f4d34
test(nextest_ui_filter): correct assertion to match combined filter p…
leynos ab8dd57
docs(developers-guide): add patterns for config constants and nextest…
leynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| [bumpy_road_function] | ||
| threshold = 3.0 | ||
| threshold = 2.5 | ||
| window = 3 | ||
| min_bump_lines = 2 | ||
| include_closures = false | ||
|
|
||
71 changes: 71 additions & 0 deletions
71
crates/bumpy_road_function/ui/fail_match_with_nested_if.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| //! UI fixture that should trigger the bumpy road lint. | ||
| //! | ||
| //! This variant uses a match expression with two arms, each containing a nested | ||
| //! conditional block. The two conditional clusters form separated bumps. | ||
|
|
||
| pub mod fixture { | ||
| //! Test fixture providing types and functions that exercise the bumpy road | ||
| //! lint for the fail_match_with_nested_if UI test. | ||
|
|
||
| use std::path::PathBuf; | ||
|
|
||
| /// Build configuration mode controlling validation strictness. | ||
| #[derive(Clone, Copy, PartialEq, Eq)] | ||
| pub enum Mode { | ||
| /// Run with debug assertions and relaxed key-length checks. | ||
| Debug, | ||
| /// Optimized production build with strict validation. | ||
| Release, | ||
| } | ||
|
|
||
| impl Mode { | ||
| pub(crate) fn is_debug(self) -> bool { | ||
| matches!(self, Self::Debug) | ||
| } | ||
| } | ||
|
|
||
| const MIN_LEN: usize = 64; | ||
|
|
||
| /// Reads key material from disk and applies mode-dependent validation. | ||
| /// | ||
| /// The match arms each contain nested conditional blocks, producing two | ||
| /// separated complexity bumps. | ||
| /// | ||
| /// ```ignore | ||
| /// key_from_file(Mode::Debug, true); | ||
| /// ``` | ||
| pub fn key_from_file(mode: Mode, allow_fallback: bool) -> Result<Vec<u8>, String> { | ||
| let path = PathBuf::from("key"); | ||
|
|
||
| match std::fs::read(&path) { | ||
| Ok(mut bytes) => { | ||
| let length = bytes.len(); | ||
| if mode == Mode::Release && length < MIN_LEN { | ||
| bytes.fill(0); | ||
| return Err(format!( | ||
| "key at {} is too short ({length} < {MIN_LEN})", | ||
| path.display() | ||
| )); | ||
| } | ||
| let result = bytes.clone(); | ||
| bytes.fill(0); | ||
| Ok(result) | ||
| } | ||
| Err(error) => { | ||
| if mode.is_debug() || allow_fallback { | ||
| Ok(vec![0; MIN_LEN]) | ||
| } else { | ||
| Err(format!( | ||
| "cannot read key from {}: {error}", | ||
| path.display() | ||
| )) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(any())] | ||
| fn dead_code_fixture_marker() {} | ||
| } | ||
|
|
||
| fn main() {} |
29 changes: 29 additions & 0 deletions
29
crates/bumpy_road_function/ui/fail_match_with_nested_if.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| warning: Multiple clusters of nested conditional logic in `key_from_file`. | ||
| --> $DIR/fail_match_with_nested_if.rs:37:12 | ||
| | | ||
| LL | pub fn key_from_file(mode: Mode, allow_fallback: bool) -> Result<Vec<u8>, String> { | ||
| | _____________^^^^^^^^^^^^^______________________________________________________________- | ||
| | | _______________________________________________________________________________________| | ||
| | || | ||
| LL | || let path = PathBuf::from("key"); | ||
| LL | || | ||
| LL | || match std::fs::read(&path) { | ||
| ... || | ||
| LL | || )); | ||
| LL | || } | ||
| | ||_- Complexity bump 2 spans 6 lines. | ||
| ... | | ||
| LL | | )) | ||
| LL | | } | ||
| | |__- Complexity bump 1 spans 7 lines. | ||
| | | ||
| note: Detected 2 complexity bumps above the threshold 2.5. | ||
| --> $DIR/fail_match_with_nested_if.rs:37:12 | ||
| | | ||
| LL | pub fn key_from_file(mode: Mode, allow_fallback: bool) -> Result<Vec<u8>, String> { | ||
| | ^^^^^^^^^^^^^ | ||
| = help: Extract helper functions from the highlighted regions to reduce clustered complexity. | ||
| = note: `#[warn(bumpy_road_function)]` on by default | ||
|
|
||
| warning: 1 warning emitted | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
crates/bumpy_road_function/ui/pass_single_match_cluster.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| //! UI fixture that should *not* trigger the bumpy road lint. | ||
| //! | ||
| //! This example uses a match expression where all conditional complexity is | ||
| //! concentrated in a single arm, forming only one contiguous cluster. | ||
|
|
||
| mod fixture { | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| //! Test fixture providing conditional logic helpers for the | ||
| //! pass_single_match_cluster UI test. | ||
|
|
||
| /// Returns `true` when `n` falls in the small eligible range, | ||
| /// i.e. positive, below ten, and neither five nor seven. | ||
| fn is_small_eligible(n: i32) -> bool { | ||
| n > 0 && n < 10 && n != 5 && n != 7 | ||
| } | ||
|
|
||
| /// Categorises the input with a single cluster of conditional logic. | ||
| /// | ||
| /// ```ignore | ||
| /// assert_eq!(categorise(42), "other"); | ||
| /// ``` | ||
| pub fn categorise(input: i32) -> &'static str { | ||
| match input { | ||
| 0 => "zero", | ||
| n if is_small_eligible(n) => { | ||
| if n % 2 == 0 { | ||
| "small even" | ||
| } else { | ||
| "small odd" | ||
| } | ||
| } | ||
| _ => "other", | ||
| } | ||
| } | ||
|
|
||
| pub fn dead_code_fixture_marker() {} | ||
| } | ||
|
|
||
| fn main() { | ||
| let _ = fixture::categorise(0); | ||
| let _ = fixture::categorise(4); | ||
| let _ = fixture::categorise(99); | ||
| fixture::dead_code_fixture_marker(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.