Skip to content

Commit

Permalink
Fix NFKC normalization bug when removing unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jul 29, 2024
1 parent 381bd1f commit 8644e30
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/ruff_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ toml = { workspace = true }
typed-arena = { workspace = true }
unicode-width = { workspace = true }
unicode_names2 = { workspace = true }
unicode-normalization = { workspace = true }
url = { workspace = true }

[dev-dependencies]
Expand Down
6 changes: 4 additions & 2 deletions crates/ruff_linter/src/fix/codemods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use libcst_native::{
Codegen, CodegenState, Expression, ImportNames, NameOrAttribute, ParenthesizableWhitespace,
SmallStatement, Statement,
};
use unicode_normalization::UnicodeNormalization;
use ruff_python_ast::name::UnqualifiedName;
use smallvec::{smallvec, SmallVec};

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

fn qualified_name_from_name_or_attribute(module: &NameOrAttribute) -> String {
match module {
let unnormalized = match module {
NameOrAttribute::N(name) => name.value.to_string(),
NameOrAttribute::A(attr) => {
let name = attr.attr.value;
let prefix = unqualified_name_from_expression(&attr.value);
prefix.map_or_else(|| name.to_string(), |prefix| format!("{prefix}.{name}"))
}
}
};
unnormalized.nfkc().collect()
}

0 comments on commit 8644e30

Please sign in to comment.