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:
Charlie Marsh 2023-10-04 15:24:07 -04:00 committed by GitHub
parent 59c00b5298
commit ad265fa6bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 162 additions and 86 deletions

View file

@ -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 {