Skip byte-order-mark at start of file (#3343)

This commit is contained in:
Charlie Marsh 2023-03-05 21:37:14 -05:00 committed by GitHub
parent 673aa6e90f
commit 5d8591fec4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 1 deletions

View File

@ -0,0 +1 @@
''' SAM macro definitions '''

View File

@ -59,7 +59,7 @@ mod tests {
#[test_case(Rule::PublicMethod, Path::new("setter.py"); "D102_1")]
#[test_case(Rule::PublicModule, Path::new("D.py"); "D100")]
#[test_case(Rule::PublicNestedClass, Path::new("D.py"); "D106")]
#[test_case(Rule::PublicPackage, Path::new("D.py"); "D104")]
#[test_case(Rule::PublicPackage, Path::new("D.py"); "D104_0")]
#[test_case(Rule::PublicPackage, Path::new("D104/__init__.py"); "D104_1")]
#[test_case(Rule::SectionNameEndsInColon, Path::new("D.py"); "D416")]
#[test_case(Rule::SectionNotOverIndented, Path::new("sections.py"); "D214")]
@ -88,6 +88,16 @@ mod tests {
Ok(())
}
#[test]
fn bom() -> Result<()> {
let diagnostics = test_path(
Path::new("pydocstyle/bom.py"),
&settings::Settings::for_rule(Rule::TripleSingleQuotes),
)?;
assert_yaml_snapshot!(diagnostics);
Ok(())
}
#[test]
fn d417_unspecified() -> Result<()> {
let diagnostics = test_path(

View File

@ -0,0 +1,15 @@
---
source: crates/ruff/src/rules/pydocstyle/mod.rs
expression: diagnostics
---
- kind:
TripleSingleQuotes: ~
location:
row: 1
column: 0
end_location:
row: 1
column: 29
fix: ~
parent: ~

View File

@ -35,6 +35,12 @@ fn index_utf8(contents: &str) -> Vec<Vec<usize>> {
let mut current_byte_offset = 0;
let mut previous_char = '\0';
for char in contents.chars() {
// Skip BOM.
if previous_char == '\0' && char == '\u{feff}' {
current_byte_offset += char.len_utf8();
continue;
}
current_row.push(current_byte_offset);
if char == '\n' {
if previous_char == '\r' {