Skip byte-order-mark at start of file (#3343)
This commit is contained in:
1
crates/ruff/resources/test/fixtures/pydocstyle/bom.py
vendored
Normal file
1
crates/ruff/resources/test/fixtures/pydocstyle/bom.py
vendored
Normal file
@@ -0,0 +1 @@
|
||||
''' SAM macro definitions '''
|
||||
@@ -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(
|
||||
|
||||
@@ -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: ~
|
||||
|
||||
@@ -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' {
|
||||
|
||||
Reference in New Issue
Block a user