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:
Charlie Marsh 2023-08-10 22:28:25 -04:00 committed by GitHub
parent eb68addf97
commit 95dea5c868
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 296 additions and 175 deletions

View file

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