Skip to content

Commit 93f87a4

Browse files
committed
chore: minified function
1 parent b758195 commit 93f87a4

5 files changed

Lines changed: 14 additions & 6 deletions

File tree

docs/capabilities.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Default scanned file types: .ts, .js, jsx, tsx, vue, .mjs, .mts, .cjs, .cts, .sv
3838

3939
## What It Checks For
4040

41+
> **Note:** The scanner skips files containing any line over 500 characters, as these are likely minified or bundled — this avoids false positives across all checks below.
42+
4143
### 1 Missing Variables
4244

4345
Variables that are **used in code** but **not defined** in the selected env comparison file.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Returns true if a line looks like minified/bundled code.
3+
* Used to skip entire files early in the pipeline.
4+
*/
5+
export function isLikelyMinified(content: string): boolean {
6+
return content.split(/\r?\n/).some((line) => line.length > 500);
7+
}

packages/cli/src/core/scan/scanFile.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { EnvUsage, ScanOptions } from '../../config/types.js';
33
import { ENV_PATTERNS } from './patterns.js';
44
import { hasIgnoreComment } from '../security/secretDetectors.js';
55
import { normalizePath } from '../helpers/normalizePath.js';
6+
import { isLikelyMinified } from '../helpers/isLikelyMinified.js';
67

78
/**
89
* Scans a file for environment variable usage.
@@ -63,7 +64,7 @@ export function scanFile(
6364
const contextLine = lines[lineNumber - 1]!;
6465

6566
// Ignore likely minified / bundled lines to avoid scan false positives
66-
if (contextLine.length > 500) continue;
67+
if (isLikelyMinified(contextLine)) continue;
6768

6869
// Determine previous line for ignore detection
6970
const prevLine = lines[lineNumber - 2] ?? '';

packages/cli/src/core/security/secretDetectors.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { shannonEntropyNormalized } from './entropy.js';
2+
import { isLikelyMinified } from '../helpers/isLikelyMinified.js';
23

34
/**
45
* Severity levels for detected secrets
@@ -55,11 +56,6 @@ const HARMLESS_URLS = [
5556
const HARMLESS_ATTRIBUTE_KEYS =
5657
/\b(trackingId|trackingContext|data-testid|data-test|aria-label)\b/i;
5758

58-
// Ignore minified files
59-
function isLikelyMinified(line: string): boolean {
60-
return line.length > 500; // Extremely long line, likely minified
61-
}
62-
6359
// Checks if a line is an HTML text node or tag
6460
function isHtmlTextNode(line: string): boolean {
6561
const trimmed = line.trim();

packages/cli/src/services/scanCodebase.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { DEFAULT_EXCLUDE_PATTERNS } from '../core/scan/patterns.js';
99
import { scanFile } from '../core/scan/scanFile.js';
1010
import { findFiles } from './fileWalker.js';
1111
import { normalizePath } from '../core/helpers/normalizePath.js';
12+
import { isLikelyMinified } from '../core/helpers/isLikelyMinified.js';
1213

1314
/**
1415
* Scans the codebase for environment variable usage based on the provided options.
@@ -30,6 +31,7 @@ export async function scanCodebase(opts: ScanOptions): Promise<ScanResult> {
3031
for (const filePath of files) {
3132
const content = await safeReadFile(filePath);
3233
if (!content) continue;
34+
if (isLikelyMinified(content)) continue; // Skip likely minified files
3335

3436
// Scan the file for environment variable usages
3537
const fileUsages = scanFile(filePath, content, opts);

0 commit comments

Comments
 (0)