Skip to content

Commit 8644e30

Browse files
committed
Fix NFKC normalization bug when removing unused imports
1 parent 381bd1f commit 8644e30

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ruff_linter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ toml = { workspace = true }
6969
typed-arena = { workspace = true }
7070
unicode-width = { workspace = true }
7171
unicode_names2 = { workspace = true }
72+
unicode-normalization = { workspace = true }
7273
url = { workspace = true }
7374

7475
[dev-dependencies]

crates/ruff_linter/src/fix/codemods.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use libcst_native::{
55
Codegen, CodegenState, Expression, ImportNames, NameOrAttribute, ParenthesizableWhitespace,
66
SmallStatement, Statement,
77
};
8+
use unicode_normalization::UnicodeNormalization;
89
use ruff_python_ast::name::UnqualifiedName;
910
use smallvec::{smallvec, SmallVec};
1011

@@ -194,12 +195,13 @@ fn unqualified_name_from_expression<'a>(expr: &'a Expression<'a>) -> Option<Unqu
194195
}
195196

196197
fn qualified_name_from_name_or_attribute(module: &NameOrAttribute) -> String {
197-
match module {
198+
let unnormalized = match module {
198199
NameOrAttribute::N(name) => name.value.to_string(),
199200
NameOrAttribute::A(attr) => {
200201
let name = attr.attr.value;
201202
let prefix = unqualified_name_from_expression(&attr.value);
202203
prefix.map_or_else(|| name.to_string(), |prefix| format!("{prefix}.{name}"))
203204
}
204-
}
205+
};
206+
unnormalized.nfkc().collect()
205207
}

0 commit comments

Comments
 (0)