mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:35:58 +00:00
Allow f-string modifications in line-shrinking cases (#7818)
## Summary This PR resolves an issue raised in https://github.com/astral-sh/ruff/discussions/7810, whereby we don't fix an f-string that exceeds the line length _even if_ the resultant code is _shorter_ than the current code. As part of this change, I've also refactored and extracted some common logic we use around "ensuring a fix isn't breaking the line length rules". ## Test Plan `cargo test`
This commit is contained in:
parent
59c00b5298
commit
ad265fa6bc
9 changed files with 162 additions and 86 deletions
|
@ -1,12 +1,14 @@
|
|||
use ruff_cache::{CacheKey, CacheKeyHasher};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::error::Error;
|
||||
use std::hash::Hasher;
|
||||
use std::num::{NonZeroU16, NonZeroU8, ParseIntError};
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use unicode_width::UnicodeWidthChar;
|
||||
|
||||
use ruff_cache::{CacheKey, CacheKeyHasher};
|
||||
use ruff_macros::CacheKey;
|
||||
use ruff_text_size::TextSize;
|
||||
|
||||
/// The length of a line of text that is considered too long.
|
||||
///
|
||||
|
@ -23,6 +25,10 @@ impl LineLength {
|
|||
pub fn value(&self) -> u16 {
|
||||
self.0.get()
|
||||
}
|
||||
|
||||
pub fn text_len(&self) -> TextSize {
|
||||
TextSize::from(u32::from(self.value()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for LineLength {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue