Skip to content

Commit c545946

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/main/dev-dependencies-36ec20a6bf
2 parents 09abdb8 + dd9040e commit c545946

17 files changed

+154
-691
lines changed

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,30 @@ This project follows [Keep a Changelog](https://keepachangelog.com/) and [Semant
1111

1212
### Changed
1313

14+
-
15+
16+
### Fixed
17+
18+
-
19+
20+
## [2.3.12] - 2025-12-18
21+
22+
### Added
23+
24+
- Added warnings count to scan usage stats.
25+
26+
### Changed
27+
1428
- Updated dependencies to latest versions.
1529
- Moved `healthScore` further down on the console output for better visibility of issues.
30+
- Removed used variables output from scan usage to reduce noise.
31+
- Removed header output from scan usage to reduce noise.
32+
- Shortened config file path in CLI output to show only the filename.
33+
- Updated README documentation for better clarity.
1634

1735
### Fixed
1836

19-
-
37+
- Fixed false positive secret detection for certain harmless attribute keys in codebase scanner.
2038

2139
## [2.3.11] - 2025-12-13
2240

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# dotenv-diff
22

3-
![Demo](./public/demo2.png)
3+
![Demo](./public/demo3.png)
44

55
`dotenv-diff` scans your codebase to detect which environment variables are used
66
and compares them against your `.env` or `.env.example` files.

public/demo3.png

80.3 KB
Loading

src/commands/scanUsage.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ export async function scanUsage(
5050
const endTime = performance.now();
5151
scanResult.stats.duration = (endTime - startTime) / 1000; // Convert to seconds
5252

53-
// Recalculate stats after filtering
54-
calculateStats(scanResult);
55-
5653
// If user explicitly passed --example flag, but the file doesn't exist:
5754
if (printMissingExample(opts)) {
5855
return { exitWithError: true };
@@ -128,6 +125,9 @@ export async function scanUsage(
128125
}
129126
}
130127

128+
// Recalculate stats after filtering
129+
calculateStats(scanResult);
130+
131131
// JSON output
132132
if (opts.json) {
133133
const jsonOutput = createJsonOutput(
@@ -237,10 +237,25 @@ function calculateStats(scanResult: ScanResult): ScanResult {
237237
scanResult.used.map((u: EnvUsage) => u.variable),
238238
).size;
239239

240+
const warningsCount =
241+
(scanResult.frameworkWarnings?.length ?? 0) +
242+
(scanResult.exampleWarnings?.length ?? 0) +
243+
(scanResult.t3EnvWarnings?.length ?? 0) +
244+
(scanResult.logged?.length ?? 0) +
245+
(scanResult.uppercaseWarnings?.length ?? 0) +
246+
(scanResult.expireWarnings?.length ?? 0) +
247+
(scanResult.inconsistentNamingWarnings?.length ?? 0) +
248+
(scanResult.secrets?.length ?? 0) +
249+
(scanResult.missing.length ?? 0) +
250+
(scanResult.unused.length ?? 0) +
251+
(scanResult.duplicates?.env?.length ?? 0) +
252+
(scanResult.duplicates?.example?.length ?? 0);
253+
240254
scanResult.stats = {
241255
filesScanned: scanResult.stats.filesScanned,
242256
totalUsages: scanResult.used.length,
243257
uniqueVariables,
258+
warningsCount: warningsCount,
244259
duration: scanResult.stats.duration,
245260
};
246261

src/config/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export interface ScanResult {
149149
filesScanned: number;
150150
totalUsages: number;
151151
uniqueVariables: number;
152+
warningsCount: number;
152153
duration: number;
153154
};
154155
secrets: SecretFinding[];
@@ -188,6 +189,7 @@ export interface ScanJsonEntry {
188189
filesScanned: number;
189190
totalUsages: number;
190191
uniqueVariables: number;
192+
warningsCount: number;
191193
duration: number;
192194
};
193195
missing: Array<{

src/core/scanJsonOutput.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,6 @@ export function createJsonOutput(
8686
output.totalEnvVariables = totalEnvVariables;
8787
}
8888

89-
// Optionally include all usages
90-
if (opts.showStats) {
91-
output.allUsages = scanResult.used.map((u: EnvUsage) => ({
92-
variable: u.variable,
93-
file: u.file,
94-
line: u.line,
95-
pattern: u.pattern,
96-
context: u.context,
97-
}));
98-
}
99-
10089
output.healthScore = healthScore;
10190

10291
return output;

src/core/secretDetectors.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ const HARMLESS_URLS = [
4444
/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/i, // SVG namespace
4545
];
4646

47+
// Known harmless attribute keys commonly used in UI / analytics
48+
const HARMLESS_ATTRIBUTE_KEYS =
49+
/\b(trackingId|trackingContext|data-testid|data-test|aria-label)\b/i;
50+
4751
/**
4852
* Determines the severity of a secret finding.
4953
* @param kind 'pattern' | 'entropy'
@@ -256,7 +260,10 @@ export function detectSecretsInSource(
256260

257261
// 1) Suspicious key literal assignments
258262
if (SUSPICIOUS_KEYS.test(line)) {
259-
const m = line!.match(/=\s*["'`](.+?)["'`]/);
263+
// Ignore known harmless UI / analytics attributes
264+
if (HARMLESS_ATTRIBUTE_KEYS.test(line)) continue;
265+
266+
const m = line.match(/=\s*["'`](.+?)["'`]/);
260267
if (
261268
m &&
262269
m[1] &&

src/services/codeBaseScanner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export async function scanCodebase(opts: ScanOptions): Promise<ScanResult> {
7070
filesScanned,
7171
totalUsages: filteredUsages.length,
7272
uniqueVariables: uniqueVariables.length,
73+
warningsCount: 0,
7374
duration: 0,
7475
},
7576
duplicates: {

src/services/scanOutputToConsole.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { printGitignoreWarning } from '../ui/shared/printGitignore.js';
44
import type { ScanUsageOptions, ScanResult } from '../config/types.js';
55
import { printHeader } from '../ui/scan/printHeader.js';
66
import { printStats } from '../ui/scan/printStats.js';
7-
import { printUniqueVariables } from '../ui/scan/printUniqueVariables.js';
8-
import { printVariables } from '../ui/scan/printVariables.js';
97
import { printMissing } from '../ui/scan/printMissing.js';
108
import { printUnused } from '../ui/scan/printUnused.js';
119
import { printDuplicates } from '../ui/shared/printDuplicates.js';
@@ -54,14 +52,6 @@ export function outputToConsole(
5452
// Show stats if requested
5553
printStats(scanResult.stats, isJson, opts.showStats ?? true);
5654

57-
// Show used variables if any found
58-
if (scanResult.stats.uniqueVariables > 0) {
59-
// Show unique variables found
60-
printUniqueVariables(scanResult.stats.uniqueVariables);
61-
// Print used variables with locations
62-
printVariables(scanResult.used, opts.showStats ?? false, isJson);
63-
}
64-
6555
// Missing variables (used in code but not in env file)
6656
if (
6757
printMissing(

src/ui/scan/printHeader.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@ import chalk from 'chalk';
66
* @returns void
77
*/
88
export function printHeader(comparedAgainst?: string): void {
9-
console.log();
10-
console.log(
11-
chalk.blue('🔍 Scanning codebase for environment variable usage...'),
12-
);
139
if (comparedAgainst) {
1410
console.log();
1511
console.log(
1612
chalk.magenta(`📋 Comparing codebase usage against: ${comparedAgainst}`),
1713
);
1814
}
19-
console.log();
2015
}

0 commit comments

Comments
 (0)