Skip to content

Commit a4ee8c2

Browse files
authored
fix: removed mismatch from only flag (#250)
1 parent 3cccc35 commit a4ee8c2

6 files changed

Lines changed: 32 additions & 29 deletions

File tree

src/cli/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function createProgram() {
2828
.option('--no-color', 'Disable colored output')
2929
.option(
3030
'--only <list>',
31-
'Comma-separated categories to only run (missing,extra,empty,mismatch,duplicate,gitignore)',
31+
'Comma-separated categories to only run (missing,extra,empty,duplicate,gitignore)',
3232
)
3333
.option('--scan-usage', 'Scan codebase for environment variable usage')
3434
.option('--compare', 'Compare .env and .env.example files')

src/commands/compare.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export async function compareMany(
4646
missing: 0,
4747
extra: 0,
4848
empty: 0,
49-
mismatch: 0,
5049
duplicate: 0,
5150
gitignore: 0,
5251
};
@@ -94,8 +93,7 @@ export async function compareMany(
9493
missing: run('missing') ? diff.missing : [],
9594
extra: run('extra') ? diff.extra : [],
9695
empty: run('empty') ? emptyKeys : [],
97-
mismatches:
98-
run('mismatch') && opts.checkValues ? diff.valueMismatches : [],
96+
mismatches: opts.checkValues ? diff.valueMismatches : [],
9997
duplicatesEnv: run('duplicate') ? dupsEnv : [],
10098
duplicatesEx: run('duplicate') ? dupsEx : [],
10199
gitignoreIssue,

src/config/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export const ALLOWED_CATEGORIES = [
6161
'missing',
6262
'extra',
6363
'empty',
64-
'mismatch',
6564
'duplicate',
6665
'gitignore',
6766
] as const;

src/core/compare/updateTotals.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export interface Totals {
77
missing: number;
88
extra: number;
99
empty: number;
10-
mismatch: number;
1110
duplicate: number;
1211
gitignore: number;
1312
}
@@ -43,11 +42,6 @@ export function updateTotals(
4342
totals.empty += filtered.empty.length;
4443
}
4544

46-
if (filtered.mismatches?.length) {
47-
entry.valueMismatches = filtered.mismatches;
48-
totals.mismatch += filtered.mismatches.length;
49-
}
50-
5145
if (filtered.duplicatesEnv.length || filtered.duplicatesEx.length) {
5246
totals.duplicate +=
5347
filtered.duplicatesEnv.length + filtered.duplicatesEx.length;

test/e2e/cli.compare.e2e.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,34 @@ describe('added .env to gitignore with --compare and --fix', () => {
123123
expect(res.stdout).toContain('file not found');
124124
expect(res.stdout).toContain('Do you want to create a .env.example file from .env.local?');
125125
});
126+
127+
describe('Values mismatch checks', () => {
128+
it('will report value mismatches when --check-values is set', () => {
129+
const cwd = tmpDir();
130+
fs.writeFileSync(path.join(cwd, '.env'), 'API_KEY=actual_value\n');
131+
fs.writeFileSync(
132+
path.join(cwd, '.env.example'),
133+
'API_KEY=example_value\n',
134+
);
135+
136+
const res = runCli(cwd, ['--compare', '--check-values']);
137+
expect(res.status).toBe(0);
138+
expect(res.stdout).toContain('Value mismatches');
139+
expect(res.stdout).toContain('API_KEY');
140+
});
141+
142+
it('will not report value mismatches when --check-values is not set', () => {
143+
const cwd = tmpDir();
144+
fs.writeFileSync(path.join(cwd, '.env'), 'API_KEY=actual_value\n');
145+
fs.writeFileSync(
146+
path.join(cwd, '.env.example'),
147+
'API_KEY=example_value\n',
148+
);
149+
150+
const res = runCli(cwd, ['--compare']);
151+
expect(res.status).toBe(0);
152+
expect(res.stdout).not.toContain('Value mismatches');
153+
expect(res.stdout).not.toContain('API_KEY');
154+
});
155+
});
126156
});

test/unit/core/compare/updateTotals.test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe('updateTotals', () => {
1717
missing: 0,
1818
extra: 0,
1919
empty: 0,
20-
mismatch: 0,
2120
duplicate: 0,
2221
gitignore: 0,
2322
};
@@ -74,23 +73,6 @@ describe('updateTotals', () => {
7473
expect(entry.empty).toEqual(['EMPTY1']);
7574
});
7675

77-
it('updates value mismatches', () => {
78-
const filtered: Filtered = {
79-
missing: [],
80-
mismatches: [{ key: 'KEY1', expected: 'a', actual: 'b' }],
81-
duplicatesEnv: [],
82-
duplicatesEx: [],
83-
gitignoreIssue: null,
84-
};
85-
86-
updateTotals(filtered, totals, entry);
87-
88-
expect(totals.mismatch).toBe(1);
89-
expect(entry.valueMismatches).toEqual([
90-
{ key: 'KEY1', expected: 'a', actual: 'b' },
91-
]);
92-
});
93-
9476
it('updates duplicates from both env and example', () => {
9577
const filtered: Filtered = {
9678
missing: [],

0 commit comments

Comments
 (0)