-
-
Notifications
You must be signed in to change notification settings - Fork 930
fix: detect inifinite loops caused by conflicting rule fixes #7732
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
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
Some comments aren't visible on the classic Files Changed page.
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
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 |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ pub mod workspace; | |
| pub mod workspace_types; | ||
|
|
||
| mod scanner; | ||
| mod utils; | ||
|
|
||
| #[cfg(test)] | ||
| mod test_utils; | ||
|
|
||
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,70 @@ | ||
| const RATIO_Q: u32 = 100; // fixed-point 2 decimals | ||
| const RATIO_GROWTH: u32 = 150; // 1.5x growth increase | ||
| const RATIO_ACCEL: u32 = 180; // 1.8x delta increase | ||
| const STREAK_LIMIT: u8 = 10; | ||
|
|
||
| /// A guard that ensures a value does not grow too quickly. | ||
| /// | ||
| /// Used to prevent runaway growth of files when applying fixes. | ||
| pub(crate) struct GrowthGuard { | ||
| previous: u32, | ||
| previous_diff: u32, | ||
| /// multiplicative growth streak | ||
| growth_streak: u8, | ||
| /// delta acceleration streak | ||
| accel_streak: u8, | ||
| } | ||
|
|
||
| impl GrowthGuard { | ||
| pub fn new(initial: u32) -> Self { | ||
| Self { | ||
| previous: initial, | ||
| previous_diff: 0, | ||
| growth_streak: 0, | ||
| accel_streak: 0, | ||
| } | ||
| } | ||
|
|
||
| /// Check if the new value is allowed based on growth constraints. | ||
| /// | ||
| /// Returns `true` if the new value is allowed, `false` otherwise. | ||
| pub fn check(&mut self, new: u32) -> bool { | ||
| if new < self.previous { | ||
| // Allow decreases | ||
| self.previous = new; | ||
| self.previous_diff = 0; | ||
| self.growth_streak = 0; | ||
| self.accel_streak = 0; | ||
| return true; | ||
| } | ||
|
|
||
| let diff = new.saturating_sub(self.previous); | ||
|
|
||
| // Check for multiplicative growth | ||
| if new.saturating_mul(RATIO_Q) >= self.previous.saturating_mul(RATIO_GROWTH) { | ||
| self.growth_streak = self.growth_streak.saturating_add(1); | ||
| } else { | ||
| self.growth_streak = 0; | ||
| } | ||
|
|
||
| // Check for delta acceleration | ||
| if diff.saturating_mul(RATIO_Q) >= self.previous_diff.saturating_mul(RATIO_ACCEL) | ||
| && self.previous_diff > 0 | ||
| { | ||
| self.accel_streak = self.accel_streak.saturating_add(1); | ||
| } else { | ||
| self.accel_streak = 0; | ||
| } | ||
|
|
||
| // Update state | ||
| self.previous = new; | ||
| self.previous_diff = diff; | ||
|
|
||
| // Enforce limits | ||
| if self.growth_streak >= STREAK_LIMIT || self.accel_streak >= STREAK_LIMIT { | ||
| return false; | ||
| } | ||
|
|
||
| true | ||
| } | ||
| } |
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 @@ | ||
| pub mod growth_guard; |
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.
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.
Add paragraph breaks to the diagnostic message
Right now each
write_markupcall runs back-to-back, so the rendered text comes out as one long sentence (…file.The…This…). A couple of explicit separators will fix the readability.fmt.write_markup(markup! { "An internal error occurred when analyzing this file." })?; + fmt.write_markup(markup! { + "\n\n" + })?; fmt.write_markup(markup! { {self} })?; + fmt.write_markup(markup! { + "\n\n" + })?; fmt.write_markup(markup! { "This is likely a bug in Biome, not an error in your code. Please consider filing an issue on "<Hyperlink href="https://github.com/biomejs/biome/issues/new/choose">"GitHub"</Hyperlink>" with a reproduction of this error." })?;📝 Committable suggestion
🤖 Prompt for AI Agents