mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00
Respect tab width in line-length heuristic (#6491)
## Summary In https://github.com/astral-sh/ruff/pull/5811, I suggested that we add a heuristic to the overlong-lines check such that if the line had fewer bytes than the character limit, we return early -- the idea being that a single byte per character was the "worst case". I overlooked that this isn't true for tabs -- with tabs, the "worst case" scenario is that every byte is a tab, which can have a width greater than 1. Closes https://github.com/astral-sh/ruff/issues/6425. ## Test Plan `cargo test` with a new fixture borrowed from the issue, plus manual testing.
This commit is contained in:
parent
eb68addf97
commit
95dea5c868
8 changed files with 296 additions and 175 deletions
|
@ -145,10 +145,10 @@ impl PartialOrd<LineLength> for LineWidth {
|
|||
/// The size of a tab.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, CacheKey)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
pub struct TabSize(pub NonZeroU8);
|
||||
pub struct TabSize(NonZeroU8);
|
||||
|
||||
impl TabSize {
|
||||
fn as_usize(self) -> usize {
|
||||
pub(crate) fn as_usize(self) -> usize {
|
||||
self.0.get() as usize
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue