mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
Skip BOM when determining Locator's line starts (#6159)
## Summary If a file has a BOM, the import sorter _always_ reports the imports as unsorted. The acute issue is that we detect that the line has leading content (before the imports), which we always consider a violation. Rather than fixing that one site, this PR instead makes `.line_start` BOM-aware. Fixes https://github.com/astral-sh/ruff/issues/6155.
This commit is contained in:
parent
44bdf20221
commit
badbfb2d3e
6 changed files with 32 additions and 0 deletions
|
@ -76,7 +76,11 @@ impl<'a> Locator<'a> {
|
|||
if let Some(index) = memrchr2(b'\n', b'\r', bytes) {
|
||||
// SAFETY: Safe because `index < offset`
|
||||
TextSize::try_from(index).unwrap().add(TextSize::from(1))
|
||||
} else if self.contents.starts_with('\u{feff}') {
|
||||
// Skip the BOM.
|
||||
'\u{feff}'.text_len()
|
||||
} else {
|
||||
// Start of file.
|
||||
TextSize::default()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue