(code: string)
| 111 | /** Replaces comments and quoted/template literals with same-length blanks, so |
| 112 | * offsets stay valid and their contents can't be mistaken for code. */ |
| 113 | const withLiteralsBlanked = (code: string): string => { |
| 114 | const blank = (text: string): string => text.replace(/[^\n]/g, " "); |
| 115 | return code.replace( |
| 116 | // Order matters: line comment, block comment, then each quote flavour. |
| 117 | /\/\/[^\n]*|\/\*[\s\S]*?\*\/|'(?:\\.|[^'\\\n])*'|"(?:\\.|[^"\\\n])*"|`(?:\\.|[^`\\])*`/g, |
| 118 | blank, |
| 119 | ); |
| 120 | }; |
| 121 | |
| 122 | /** A React hook call: `useFoo(`, not `x.useFoo(` and not `abusefoo(`. */ |
| 123 | const HOOK_CALL = /(?<![.\w$])(use[A-Z][\w$]*)\s*\(/; |
no test coverage detected