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,45 +1698,47 @@ 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() {
|
||||||
// Search for confusing characters.
|
if !current_char.is_ascii() {
|
||||||
if let Some(representant) = CONFUSABLES.get(&(current_char as u32)) {
|
// Search for confusing characters.
|
||||||
if !settings.allowed_confusables.contains(¤t_char) {
|
if let Some(representant) = CONFUSABLES.get(&(current_char as u32)).copied() {
|
||||||
let col = if row_offset == 0 {
|
if !settings.allowed_confusables.contains(¤t_char) {
|
||||||
start.column() + col_offset
|
let col = if row_offset == 0 {
|
||||||
} else {
|
start.column() + col_offset
|
||||||
col_offset
|
} else {
|
||||||
};
|
col_offset
|
||||||
let location = Location::new(start.row() + row_offset, col);
|
};
|
||||||
let end_location = Location::new(location.row(), location.column() + 1);
|
let location = Location::new(start.row() + row_offset, col);
|
||||||
let mut diagnostic = Diagnostic::new::<DiagnosticKind>(
|
let end_location = Location::new(location.row(), location.column() + 1);
|
||||||
match context {
|
let mut diagnostic = Diagnostic::new::<DiagnosticKind>(
|
||||||
Context::String => AmbiguousUnicodeCharacterString {
|
match context {
|
||||||
confusable: current_char,
|
Context::String => AmbiguousUnicodeCharacterString {
|
||||||
representant: *representant as char,
|
confusable: current_char,
|
||||||
|
representant: representant as char,
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
Context::Docstring => AmbiguousUnicodeCharacterDocstring {
|
||||||
|
confusable: current_char,
|
||||||
|
representant: representant as char,
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
Context::Comment => AmbiguousUnicodeCharacterComment {
|
||||||
|
confusable: current_char,
|
||||||
|
representant: representant as char,
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
},
|
||||||
|
Range::new(location, end_location),
|
||||||
|
);
|
||||||
|
if settings.rules.enabled(diagnostic.kind.rule()) {
|
||||||
|
if autofix.into() && settings.rules.should_fix(diagnostic.kind.rule()) {
|
||||||
|
diagnostic.set_fix(Edit::replacement(
|
||||||
|
(representant as char).to_string(),
|
||||||
|
location,
|
||||||
|
end_location,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
.into(),
|
diagnostics.push(diagnostic);
|
||||||
Context::Docstring => AmbiguousUnicodeCharacterDocstring {
|
|
||||||
confusable: current_char,
|
|
||||||
representant: *representant as char,
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
Context::Comment => AmbiguousUnicodeCharacterComment {
|
|
||||||
confusable: current_char,
|
|
||||||
representant: *representant as char,
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
},
|
|
||||||
Range::new(location, end_location),
|
|
||||||
);
|
|
||||||
if settings.rules.enabled(diagnostic.kind.rule()) {
|
|
||||||
if autofix.into() && settings.rules.should_fix(diagnostic.kind.rule()) {
|
|
||||||
diagnostic.set_fix(Edit::replacement(
|
|
||||||
(*representant as char).to_string(),
|
|
||||||
location,
|
|
||||||
end_location,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
diagnostics.push(diagnostic);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue