mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:24 +00:00
Ambiguous unicode, only test unicode characters (#3814)
This commit is contained in:
parent
82584ad101
commit
48d8680e71
1 changed files with 39 additions and 37 deletions
|
@ -1698,8 +1698,9 @@ pub fn ambiguous_unicode_character(
|
||||||
let mut col_offset = 0;
|
let mut col_offset = 0;
|
||||||
let mut row_offset = 0;
|
let mut row_offset = 0;
|
||||||
for current_char in text.chars() {
|
for current_char in text.chars() {
|
||||||
|
if !current_char.is_ascii() {
|
||||||
// Search for confusing characters.
|
// Search for confusing characters.
|
||||||
if let Some(representant) = CONFUSABLES.get(&(current_char as u32)) {
|
if let Some(representant) = CONFUSABLES.get(&(current_char as u32)).copied() {
|
||||||
if !settings.allowed_confusables.contains(¤t_char) {
|
if !settings.allowed_confusables.contains(¤t_char) {
|
||||||
let col = if row_offset == 0 {
|
let col = if row_offset == 0 {
|
||||||
start.column() + col_offset
|
start.column() + col_offset
|
||||||
|
@ -1712,17 +1713,17 @@ pub fn ambiguous_unicode_character(
|
||||||
match context {
|
match context {
|
||||||
Context::String => AmbiguousUnicodeCharacterString {
|
Context::String => AmbiguousUnicodeCharacterString {
|
||||||
confusable: current_char,
|
confusable: current_char,
|
||||||
representant: *representant as char,
|
representant: representant as char,
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
Context::Docstring => AmbiguousUnicodeCharacterDocstring {
|
Context::Docstring => AmbiguousUnicodeCharacterDocstring {
|
||||||
confusable: current_char,
|
confusable: current_char,
|
||||||
representant: *representant as char,
|
representant: representant as char,
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
Context::Comment => AmbiguousUnicodeCharacterComment {
|
Context::Comment => AmbiguousUnicodeCharacterComment {
|
||||||
confusable: current_char,
|
confusable: current_char,
|
||||||
representant: *representant as char,
|
representant: representant as char,
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
},
|
},
|
||||||
|
@ -1731,7 +1732,7 @@ pub fn ambiguous_unicode_character(
|
||||||
if settings.rules.enabled(diagnostic.kind.rule()) {
|
if settings.rules.enabled(diagnostic.kind.rule()) {
|
||||||
if autofix.into() && settings.rules.should_fix(diagnostic.kind.rule()) {
|
if autofix.into() && settings.rules.should_fix(diagnostic.kind.rule()) {
|
||||||
diagnostic.set_fix(Edit::replacement(
|
diagnostic.set_fix(Edit::replacement(
|
||||||
(*representant as char).to_string(),
|
(representant as char).to_string(),
|
||||||
location,
|
location,
|
||||||
end_location,
|
end_location,
|
||||||
));
|
));
|
||||||
|
@ -1740,6 +1741,7 @@ pub fn ambiguous_unicode_character(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Track the offset from the start position as we iterate over the body.
|
// Track the offset from the start position as we iterate over the body.
|
||||||
if current_char == '\n' {
|
if current_char == '\n' {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue