Skip to main content

blank_non_code

Function blank_non_code 

Source
pub fn blank_non_code(src: &str) -> String
Expand description

Blank comments and the insides of string/template/REGEX literals, preserving length and line count so offsets still line up — blanked, not deleted, for that reason.

Now handles regex literals. It previously did not, and /a\\/b/ read as a line comment: everything after it on that line was blanked, so a real debugger; sharing the line went unreported. Missed warnings rather than false alarms, but missed all the same.

Telling a regex from division needs the preceding token, which is why this is a tokenizer and not a set of rules over characters. The two ways to be wrong are NOT symmetric:

  • division mistaken for a regex → blanks to the next /, so a violation there is MISSED. Safe direction.
  • a regex mistaken for division → its contents are scanned as code, so /it\\.only/ would be reported as a violation that does not exist. A false alarm blocking a commit — the direction to avoid, and why the “regex allowed” set below is generous.