Skip to content

Commit 423c4c8

Browse files
committed
codebase m
1 parent 1ac31d0 commit 423c4c8

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/core/determineComparisonFile.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,26 @@ import path from 'path';
33
import { type ScanUsageOptions } from '../config/types.js';
44
import { resolveFromCwd } from './helpers/resolveFromCwd.js';
55

6+
type ComparisonFile = {
7+
path: string;
8+
name: string;
9+
};
10+
11+
const DEFAULT_ENV_FILES = [
12+
'.env',
13+
'.env.example',
14+
'.env.local',
15+
'.env.production',
16+
] as const;
17+
618
/**
719
* Determines which file to use for comparison based on provided options
820
* @param {ScanUsageOptions} opts - Scan configuration options
9-
* @returns {Object|null} - The comparison file information or undefined if not found
21+
* @returns Comparison file info with absolute path and basename, or undefined if not found
1022
*/
1123
export function determineComparisonFile(
1224
opts: ScanUsageOptions,
13-
): { path: string; name: string } | undefined {
25+
): ComparisonFile | undefined {
1426
// Priority: explicit flags first, then auto-discovery
1527

1628
if (opts.examplePath) {
@@ -28,8 +40,7 @@ export function determineComparisonFile(
2840
}
2941

3042
// Auto-discovery: look for common env files relative to cwd
31-
const candidates = ['.env', '.env.example', '.env.local', '.env.production'];
32-
for (const candidate of candidates) {
43+
for (const candidate of DEFAULT_ENV_FILES) {
3344
const fullPath = path.resolve(opts.cwd, candidate);
3445
if (fs.existsSync(fullPath)) {
3546
return { path: fullPath, name: candidate };

src/services/duplicates.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'fs';
2+
import type { Duplicate } from '../config/types.js';
23

34
/**
45
* Scan a .env-like file for duplicate keys.
@@ -11,7 +12,7 @@ import fs from 'fs';
1112
*/
1213
export function findDuplicateKeys(
1314
filePath: string,
14-
): Array<{ key: string; count: number }> {
15+
): Array<Duplicate> {
1516
if (!fs.existsSync(filePath)) return [];
1617

1718
const raw = fs.readFileSync(filePath, 'utf8');
@@ -32,7 +33,7 @@ export function findDuplicateKeys(
3233
counts.set(key, (counts.get(key) ?? 0) + 1);
3334
}
3435

35-
const duplicates: Array<{ key: string; count: number }> = [];
36+
const duplicates: Array<Duplicate> = [];
3637
for (const [key, count] of counts) {
3738
if (count > 1) duplicates.push({ key, count });
3839
}

0 commit comments

Comments
 (0)