deno_lint icon indicating copy to clipboard operation
deno_lint copied to clipboard

fix(no-control-regex): Only warn on control char literals

Open lionel-rowe opened this issue 1 year ago • 1 comments

Fixes https://github.com/denoland/deno_lint/issues/1143.

Old and new behavior both diverge from ESLint but in different ways:

  • ESLint detects both control char escapes and control char literals
  • Old deno_lint behavior only detected control char escapes but failed to detect control char literals
  • New deno_lint behavior only detects control char literals and intentionally overlooks control char escapes (reasoning per the linked issue)

In all cases (including ESLint), the checking is done against the regex source string rather than the JS/TS source code. This gives the following behavior:

JS/TS source code ESLint deno_lint
old
deno_lint
new
// (literal 0x1f char) ⚠️ 🆗 ⚠️
/\x1f/ ⚠️ ⚠️ 🆗
new RegExp('') (literal 0x1f char) ⚠️ 🆗 ⚠️
new RegExp('\x1f') ⚠️ 🆗 ⚠️
new RegExp('\\x1f') ⚠️ ⚠️ 🆗

Also fixes the following 2 bugs noted in the linked issue:

  • Formatting of the message fixed such that code point 0x00 is rendered \x00 not \x0
  • Added \x7f DEL to the detected control chars

lionel-rowe avatar Nov 07 '24 04:11 lionel-rowe

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Nov 07 '24 04:11 CLAassistant