Skip to content

Commit

Permalink
review: add comments explaining helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Jan 9, 2025
1 parent 572632e commit a6f4ba0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/ruff_linter/src/message/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ fn replace_whitespace_and_unprintable(source: &str, annotation_range: TextRange)
let mut range = annotation_range;
let mut line_width = LineWidthBuilder::new(IndentWidth::default());

// Updates the range given by the caller whenever a single byte (at
// `index` in `source`) is replaced with `len` bytes.
//
// When the index occurs before the start of the range, the range is
// offset by `len`. When the range occurs after or at the start but before
// the end, then the end of the range only is offset by `len`.
let mut update_range = |index, len| {
if index < usize::from(annotation_range.start()) {
range += TextSize::new(len - 1);
Expand All @@ -303,7 +309,8 @@ fn replace_whitespace_and_unprintable(source: &str, annotation_range: TextRange)
}
};

// impl_show_nonprinting!(('\x07', "␇"), ('\x08', "␈"), ('\x1b', "␛"), ('\x7f', "␡"));
// If `c` is an unprintable character, then this returns a printable
// representation of it (using a fancier Unicode codepoint).
let unprintable_replacement = |c: char| -> Option<char> {
match c {
'\x07' => Some('␇'),
Expand Down

0 comments on commit a6f4ba0

Please sign in to comment.