Skip to content

Commit a6f4ba0

Browse files
committed
review: add comments explaining helper functions
1 parent 572632e commit a6f4ba0

File tree

1 file changed

+8
-1
lines changed
  • crates/ruff_linter/src/message

1 file changed

+8
-1
lines changed

crates/ruff_linter/src/message/text.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ fn replace_whitespace_and_unprintable(source: &str, annotation_range: TextRange)
295295
let mut range = annotation_range;
296296
let mut line_width = LineWidthBuilder::new(IndentWidth::default());
297297

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

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

0 commit comments

Comments
 (0)