scanner: do not count commented-out code
Header.tsx has a disabled dev-console button inside a JSX comment and IntegrationsSettings has a commented-out section literal. Four hits in officer-web, all of them code nobody ships — and an area cannot reach zero while a comment counts against it. Only two shapes stripped, both unambiguous: block comments, and lines whose first non-space characters are //. Stripping every // would eat the tail of any string holding a URL. Verified the delta is exactly those four.
This commit is contained in:
@@ -94,6 +94,16 @@ function isHuman(value: string | undefined): value is string {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commented-out code is not user-facing text. `Header.tsx` carries a disabled dev-console button inside
|
||||
* a `{/* … *\/}` block, and counting it means the area can never reach zero without editing a comment.
|
||||
*
|
||||
* Deliberately only two shapes, both unambiguous: a block comment, and a line whose first non-space
|
||||
* characters are `//`. Stripping every `//` would eat the tail of any string holding a URL.
|
||||
*/
|
||||
const stripComments = (source: string): string =>
|
||||
source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^[ \t]*\/\/.*$/gm, '');
|
||||
|
||||
function* walk(dir: string): Generator<string> {
|
||||
let entries: string[];
|
||||
try {
|
||||
@@ -125,7 +135,7 @@ function scan(root: string): { files: number; hits: Hit[] } {
|
||||
files++;
|
||||
let source: string;
|
||||
try {
|
||||
source = readFileSync(file, 'utf8');
|
||||
source = stripComments(readFileSync(file, 'utf8'));
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user