Use u8 to represent ambiguous representants (#3345)

This commit is contained in:
Charlie Marsh 2023-03-04 16:01:05 -05:00 committed by GitHub
parent 40d3b40c14
commit d7767b2bad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -96,7 +96,7 @@ impl AlwaysAutofixableViolation for AmbiguousUnicodeCharacterComment {
}
/// See: <https://github.com/microsoft/vscode/blob/095ddabc52b82498ee7f718a34f9dd11d59099a8/src/vs/base/common/strings.ts#L1094>
static CONFUSABLES: Lazy<FxHashMap<u32, u32>> = Lazy::new(|| {
static CONFUSABLES: Lazy<FxHashMap<u32, u8>> = Lazy::new(|| {
#[allow(clippy::unreadable_literal)]
FxHashMap::from_iter([
(8232, 32),
@ -1701,7 +1701,6 @@ pub fn ambiguous_unicode_character(
// Search for confusing characters.
if let Some(representant) = CONFUSABLES.get(&(current_char as u32)) {
if !settings.allowed_confusables.contains(&current_char) {
if let Some(representant) = char::from_u32(*representant) {
let col = if row_offset == 0 {
start.column() + col_offset
} else {
@ -1713,17 +1712,17 @@ pub fn ambiguous_unicode_character(
match context {
Context::String => AmbiguousUnicodeCharacterString {
confusable: current_char,
representant,
representant: *representant as char,
}
.into(),
Context::Docstring => AmbiguousUnicodeCharacterDocstring {
confusable: current_char,
representant,
representant: *representant as char,
}
.into(),
Context::Comment => AmbiguousUnicodeCharacterComment {
confusable: current_char,
representant,
representant: *representant as char,
}
.into(),
},
@ -1732,7 +1731,7 @@ pub fn ambiguous_unicode_character(
if settings.rules.enabled(diagnostic.kind.rule()) {
if autofix.into() && settings.rules.should_fix(diagnostic.kind.rule()) {
diagnostic.amend(Fix::replacement(
representant.to_string(),
(*representant as char).to_string(),
location,
end_location,
));
@ -1741,7 +1740,6 @@ pub fn ambiguous_unicode_character(
}
}
}
}
// Track the offset from the start position as we iterate over the body.
if current_char == '\n' {