Skip to content

Commit 5dee007

Browse files
committed
prettier
1 parent aa77c22 commit 5dee007

21 files changed

Lines changed: 97 additions & 107 deletions

src/config/options.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ function parseList(val?: string | string[]): string[] {
3030
* @param flagName - The name of the flag being parsed (for error messages).
3131
* @returns An array of categories.
3232
*/
33-
function parseCategories(val?: string | string[], flagName = '--only'): Category[] {
33+
function parseCategories(
34+
val?: string | string[],
35+
flagName = '--only',
36+
): Category[] {
3437
const raw = parseList(val);
3538
const bad = raw.filter((c) => !ALLOWED_CATEGORIES.includes(c as Category));
3639
if (bad.length) {
@@ -90,9 +93,12 @@ export function normalizeOptions(raw: RawOptions): Options {
9093
const files = parseList(raw.files);
9194

9295
const cwd = process.cwd();
93-
const envFlag = typeof raw.env === 'string' ? path.resolve(cwd, raw.env) : undefined;
96+
const envFlag =
97+
typeof raw.env === 'string' ? path.resolve(cwd, raw.env) : undefined;
9498
const exampleFlag =
95-
typeof raw.example === 'string' ? path.resolve(cwd, raw.example) : undefined;
99+
typeof raw.example === 'string'
100+
? path.resolve(cwd, raw.example)
101+
: undefined;
96102

97103
if (isCiMode && isYesMode) {
98104
printCiYesWarning();

src/core/fixEnv.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,22 @@ export type FixResult = {
1919

2020
/**
2121
* Applies fixes to the .env and .env.example files based on the detected issues.
22-
*
22+
*
2323
* This function will:
2424
* - Remove duplicate keys from .env (keeping the last occurrence)
2525
* - Add missing keys to .env with empty values
2626
* - Add missing keys to .env.example (if not already present)
2727
* - Ensure .env is ignored in .gitignore (if in a git repo and ensureGitignore is true)
28-
*
28+
*
2929
* @param options - Fix options including file paths and keys to fix
3030
* @returns An object indicating whether changes were made and details of the changes
3131
*/
3232
export function applyFixes(options: ApplyFixesOptions): {
3333
changed: boolean;
3434
result: FixResult;
3535
} {
36-
const {
37-
envPath,
38-
examplePath,
39-
missingKeys,
40-
duplicateKeys,
41-
ensureGitignore,
42-
} = options;
36+
const { envPath, examplePath, missingKeys, duplicateKeys, ensureGitignore } =
37+
options;
4338

4439
const result: FixResult = {
4540
removedDuplicates: [],
@@ -53,12 +48,12 @@ export function applyFixes(options: ApplyFixesOptions): {
5348
const lines = fs.readFileSync(envPath, 'utf-8').split('\n');
5449
const seen = new Set<string>();
5550
const newLines: string[] = [];
56-
51+
5752
// Process from bottom to top, keeping last occurrence
5853
for (let i = lines.length - 1; i >= 0; i--) {
5954
const line = lines[i];
6055
if (line === undefined) continue;
61-
56+
6257
const match = line.match(/^\s*([\w.-]+)\s*=/);
6358
if (match) {
6459
const key = match[1] || '';
@@ -69,7 +64,7 @@ export function applyFixes(options: ApplyFixesOptions): {
6964
}
7065
newLines.unshift(line);
7166
}
72-
67+
7368
fs.writeFileSync(envPath, newLines.join('\n'));
7469
result.removedDuplicates = duplicateKeys;
7570
}
@@ -96,7 +91,7 @@ export function applyFixes(options: ApplyFixesOptions): {
9691
.filter(Boolean),
9792
);
9893
const newExampleKeys = missingKeys.filter((k) => !existingExKeys.has(k));
99-
94+
10095
if (newExampleKeys.length) {
10196
const newExContent =
10297
exContent +
@@ -125,15 +120,15 @@ export function applyFixes(options: ApplyFixesOptions): {
125120
/**
126121
* Ensures .env patterns are present in .gitignore at the git repository root.
127122
* This is a best-effort operation and will not throw errors.
128-
*
123+
*
129124
* @param envPath - Path to the .env file to check gitignore for
130125
* @returns true if .gitignore was updated, false otherwise
131126
*/
132127
function updateGitignoreForEnv(envPath: string): boolean {
133128
try {
134129
const startDir = path.dirname(envPath);
135130
const gitRoot = findGitRoot(startDir);
136-
131+
137132
if (!gitRoot || !isGitRepo(gitRoot)) {
138133
return false;
139134
}
@@ -149,18 +144,17 @@ function updateGitignoreForEnv(envPath: string): boolean {
149144

150145
// Need to add patterns
151146
const patterns = ['.env', '.env.*'];
152-
147+
153148
if (fs.existsSync(gitignorePath)) {
154149
const current = fs.readFileSync(gitignorePath, 'utf8');
155150
const existingLines = current.split(/\r?\n/).map((l) => l.trim());
156-
151+
157152
const missingPatterns = patterns.filter(
158-
(pattern) => !existingLines.includes(pattern)
153+
(pattern) => !existingLines.includes(pattern),
159154
);
160155

161156
if (missingPatterns.length) {
162-
const toAppend =
163-
`${current.endsWith('\n') ? '' : '\n'}${missingPatterns.join('\n')}\n`;
157+
const toAppend = `${current.endsWith('\n') ? '' : '\n'}${missingPatterns.join('\n')}\n`;
164158
fs.appendFileSync(gitignorePath, toAppend);
165159
return true;
166160
}

src/core/helpers/updateTotals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface Totals {
88
mismatch: number;
99
duplicate: number;
1010
gitignore: number;
11-
};
11+
}
1212

1313
/**
1414
* Update totals and entry fields based on filtered issues.

src/core/processComparisonFile.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ export function processComparisonFile(
6666
}
6767

6868
// Apply fixes (both duplicates + missing keys + gitignore)
69-
if (opts.fix && (duplicatesFound || scanResult.missing.length > 0 || true)) {
69+
if (
70+
opts.fix &&
71+
(duplicatesFound || scanResult.missing.length > 0 || true)
72+
) {
7073
const { changed, result } = applyFixes({
7174
envPath: compareFile.path,
7275
examplePath: opts.examplePath

src/services/ensureFilesOrPrompt.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ export async function ensureFilesOrPrompt(args: {
5050
const createEnv = isYesMode
5151
? true
5252
: isCiMode
53-
? false
54-
: await confirmYesNo(
55-
`❓ Do you want to create a new ${path.basename(envPath)} file from ${path.basename(examplePath)}?`,
56-
{ isCiMode, isYesMode },
57-
);
53+
? false
54+
: await confirmYesNo(
55+
`❓ Do you want to create a new ${path.basename(envPath)} file from ${path.basename(examplePath)}?`,
56+
{ isCiMode, isYesMode },
57+
);
5858

5959
if (!createEnv) {
6060
printPrompt.skipCreation('.env');
@@ -75,11 +75,11 @@ export async function ensureFilesOrPrompt(args: {
7575
const createExample = isYesMode
7676
? true
7777
: isCiMode
78-
? false
79-
: await confirmYesNo(
80-
`❓ Do you want to create a new ${path.basename(examplePath)} file from ${path.basename(envPath)}?`,
81-
{ isCiMode, isYesMode },
82-
);
78+
? false
79+
: await confirmYesNo(
80+
`❓ Do you want to create a new ${path.basename(examplePath)} file from ${path.basename(envPath)}?`,
81+
{ isCiMode, isYesMode },
82+
);
8383

8484
if (!createExample) {
8585
printPrompt.skipCreation('.env.example');

src/services/git.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export function warnIfEnvNotIgnored(options: GitignoreCheckOptions = {}): void {
109109
}
110110
}
111111

112-
113112
/**
114113
* Checks if .env file has gitignore issues.
115114
* Returns null if no issue, otherwise returns the reason.

src/services/scanOutputToConsole.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ export function outputToConsole(
4848
// Show unique variables found
4949
printUniqueVariables(scanResult.stats.uniqueVariables);
5050
// Print used variables with locations
51-
printVariables(
52-
scanResult.used,
53-
opts.showStats ?? false,
54-
isJson,
55-
);
51+
printVariables(scanResult.used, opts.showStats ?? false, isJson);
5652
}
5753

5854
// Missing variables (used in code but not in env file)
@@ -151,16 +147,16 @@ export function outputToConsole(
151147

152148
// Filtered results for fix tips
153149
printFixTips(
154-
{
155-
missing: scanResult.missing,
156-
duplicatesEnv: scanResult.duplicates?.env ?? [],
157-
duplicatesEx: scanResult.duplicates?.example ?? [],
158-
gitignoreIssue: hasGitignoreIssue ? { reason: 'not-ignored' } : null,
159-
},
160-
hasGitignoreIssue,
161-
isJson,
162-
opts.fix ?? false,
163-
);
150+
{
151+
missing: scanResult.missing,
152+
duplicatesEnv: scanResult.duplicates?.env ?? [],
153+
duplicatesEx: scanResult.duplicates?.example ?? [],
154+
gitignoreIssue: hasGitignoreIssue ? { reason: 'not-ignored' } : null,
155+
},
156+
hasGitignoreIssue,
157+
isJson,
158+
opts.fix ?? false,
159+
);
164160

165161
return { exitWithError };
166162
}

src/ui/compare/printAutoFix.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ export function printAutoFix(
4949
);
5050
}
5151
if (gitignoreUpdated) {
52-
console.log(
53-
chalk.green(` - Added ${envName} to .gitignore`),
54-
);
52+
console.log(chalk.green(` - Added ${envName} to .gitignore`));
5553
}
5654
} else {
5755
console.log(chalk.green('✅ Auto-fix applied: no changes needed.'));

src/ui/compare/printErrorNotFound.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export function printErrorNotFound(
2121
}
2222
if (!exExists) {
2323
console.error(
24-
chalk.red(`❌ Error: --example file not found: ${path.basename(exampleFlag)}`),
24+
chalk.red(
25+
`❌ Error: --example file not found: ${path.basename(exampleFlag)}`,
26+
),
2527
);
2628
}
2729
}

src/ui/compare/printIssues.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import { type Filtered } from '../../config/types.js';
77
* @param json Whether to output in JSON format.
88
* @returns void
99
*/
10-
export function printIssues(
11-
filtered: Filtered,
12-
json: boolean,
13-
) {
10+
export function printIssues(filtered: Filtered, json: boolean) {
1411
if (json) return;
1512
if (filtered.missing.length) {
1613
const header = chalk.red('❌ Missing keys:');
@@ -37,4 +34,4 @@ export function printIssues(
3734
);
3835
console.log();
3936
}
40-
}
37+
}

0 commit comments

Comments
 (0)