Skip to content

Commit 48a9b55

Browse files
committed
format code for tests --format flag
1 parent 221bdce commit 48a9b55

22 files changed

+516
-354
lines changed

CHANGELOG.md

Lines changed: 118 additions & 5 deletions
Large diffs are not rendered by default.

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ Thanks for your interest in contributing to dotenv-diff! Contributions of all ki
1515
## Guidelines
1616

1717
**Code Quality**
18+
1819
- Keep changes small and focused
1920
- Follow the existing code style and project structure
2021
- Write clear, descriptive commit messages
2122

2223
**Testing & Documentation**
24+
2325
- Add or update tests when introducing new behavior
2426
- Update the README or documentation when relevant
2527

2628
**Communication**
29+
2730
- For larger changes or new features, open an issue first to discuss
2831
- Avoid large refactors or breaking changes unless discussed beforehand
2932

@@ -39,4 +42,4 @@ Feel free to open an issue for discussion — all feedback is welcome.
3942

4043
---
4144

42-
Thanks for contributing! 💚
45+
Thanks for contributing! 💚

dotenv-diff.config.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
{
22
"strict": false,
33
"example": ".env.example",
4-
"ignore": [
5-
"NODE_ENV",
6-
"VITE_MODE"
7-
],
8-
"ignoreUrls": [
9-
"https://example.com"
10-
]
11-
}
4+
"ignore": ["NODE_ENV", "VITE_MODE"],
5+
"ignoreUrls": ["https://example.com"]
6+
}

eslint.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ export default [
1818
...tseslint.configs.recommended.rules,
1919
'no-unused-vars': 'off',
2020
'@typescript-eslint/no-unused-vars': ['warn'],
21-
'quotes': ['warn', 'single', { avoidEscape: true }],
21+
quotes: ['warn', 'single', { avoidEscape: true }],
2222
},
2323
},
2424
{
2525
ignores: ['dist/**'],
2626
},
2727
];
28-

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test:unit": "vitest run test/unit",
3030
"test:e2e": "vitest run test/e2e",
3131
"lint": "eslint ./src --ext .ts",
32-
"format": "prettier --write \"src/**/*.ts\" \"src/*.ts\"",
32+
"format": "prettier --write \"**/*.{ts,js,json,md,yml}\"",
3333
"start": "node dist/bin/dotenv-diff.js",
3434
"dotenv-diff": "dotenv-diff",
3535
"prepublishOnly": "npm run lint && npm test && npm run build"

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@ function tmpDir() {
2929

3030
describe('added .env to gitignore with --compare and --fix', () => {
3131
it('will warn about .env not ignored by .gitignore', () => {
32-
const cwd = tmpDir();
33-
34-
fs.mkdirSync(path.join(cwd, '.git'));
35-
fs.writeFileSync(path.join(cwd, '.env'), 'API_KEY=test\n');
36-
fs.writeFileSync(path.join(cwd, '.env.example'), 'API_KEY=test\n');
37-
38-
fs.writeFileSync(path.join(cwd, '.gitignore'), 'node_modules\n');
39-
40-
fs.mkdirSync(path.join(cwd, 'src'), { recursive: true });
41-
fs.writeFileSync(
42-
path.join(cwd, 'src', 'index.ts'),
43-
`const apiKey = process.env.API_KEY;`.trimStart(),
44-
);
45-
46-
const res = runCli(cwd, ['--compare', '--fix']);
47-
48-
expect(res.status).toBe(0);
49-
expect(res.stdout).toContain('Auto-fix applied:');
50-
expect(res.stdout).toContain('Added .env to .gitignore');
51-
});
32+
const cwd = tmpDir();
33+
34+
fs.mkdirSync(path.join(cwd, '.git'));
35+
fs.writeFileSync(path.join(cwd, '.env'), 'API_KEY=test\n');
36+
fs.writeFileSync(path.join(cwd, '.env.example'), 'API_KEY=test\n');
37+
38+
fs.writeFileSync(path.join(cwd, '.gitignore'), 'node_modules\n');
39+
40+
fs.mkdirSync(path.join(cwd, 'src'), { recursive: true });
41+
fs.writeFileSync(
42+
path.join(cwd, 'src', 'index.ts'),
43+
`const apiKey = process.env.API_KEY;`.trimStart(),
44+
);
45+
46+
const res = runCli(cwd, ['--compare', '--fix']);
47+
48+
expect(res.status).toBe(0);
49+
expect(res.stdout).toContain('Auto-fix applied:');
50+
expect(res.stdout).toContain('Added .env to .gitignore');
51+
});
5252
});

test/e2e/cli.detectExpired.e2e.test.ts

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ function tmpDir() {
3030
describe('Expiration Warnings', () => {
3131
it('warns about expired environment variables', () => {
3232
const cwd = tmpDir();
33-
33+
3434
// Create .env with an expired variable (yesterday)
3535
const yesterday = new Date();
3636
yesterday.setDate(yesterday.getDate() - 1);
3737
const expiredDate = yesterday.toISOString().split('T')[0]; // YYYY-MM-DD format
38-
38+
3939
fs.writeFileSync(
4040
path.join(cwd, '.env'),
41-
`# @expire ${expiredDate}\nEXPIRED_API_KEY=secret123\n\nVALID_KEY=value456\n`
41+
`# @expire ${expiredDate}\nEXPIRED_API_KEY=secret123\n\nVALID_KEY=value456\n`,
4242
);
4343

4444
// Create a file that uses these env vars
4545
fs.mkdirSync(path.join(cwd, 'src'), { recursive: true });
4646
fs.writeFileSync(
4747
path.join(cwd, 'src', 'index.js'),
48-
'console.log(process.env.EXPIRED_API_KEY, process.env.VALID_KEY);'
48+
'console.log(process.env.EXPIRED_API_KEY, process.env.VALID_KEY);',
4949
);
5050

5151
const res = runCli(cwd, []);
@@ -58,22 +58,22 @@ describe('Expiration Warnings', () => {
5858

5959
it('warns about soon-to-expire environment variables', () => {
6060
const cwd = tmpDir();
61-
61+
6262
// Create .env with a variable expiring in 3 days
6363
const futureDate = new Date();
6464
futureDate.setDate(futureDate.getDate() + 3);
6565
const expiringDate = futureDate.toISOString().split('T')[0];
66-
66+
6767
fs.writeFileSync(
6868
path.join(cwd, '.env'),
69-
`# @expire ${expiringDate}\nSOON_EXPIRED_KEY=secret789\n\nVALID_KEY=value123\n`
69+
`# @expire ${expiringDate}\nSOON_EXPIRED_KEY=secret789\n\nVALID_KEY=value123\n`,
7070
);
7171

7272
// Create a file that uses these env vars
7373
fs.mkdirSync(path.join(cwd, 'src'), { recursive: true });
7474
fs.writeFileSync(
7575
path.join(cwd, 'src', 'index.js'),
76-
'console.log(process.env.SOON_EXPIRED_KEY, process.env.VALID_KEY);'
76+
'console.log(process.env.SOON_EXPIRED_KEY, process.env.VALID_KEY);',
7777
);
7878

7979
const res = runCli(cwd, []);
@@ -86,47 +86,49 @@ describe('Expiration Warnings', () => {
8686

8787
it('does not warn when no expiration comments are present', () => {
8888
const cwd = tmpDir();
89-
89+
9090
fs.writeFileSync(
9191
path.join(cwd, '.env'),
92-
`API_KEY=secret123\nVALID_KEY=value456\n`
92+
`API_KEY=secret123\nVALID_KEY=value456\n`,
9393
);
9494

9595
// Create a file that uses these env vars
9696
fs.mkdirSync(path.join(cwd, 'src'), { recursive: true });
9797
fs.writeFileSync(
9898
path.join(cwd, 'src', 'index.js'),
99-
'console.log(process.env.API_KEY, process.env.VALID_KEY);'
99+
'console.log(process.env.API_KEY, process.env.VALID_KEY);',
100100
);
101101

102102
const res = runCli(cwd, []);
103103

104104
expect(res.status).toBe(0);
105-
expect(res.stdout).not.toContain('Environment variables with expiration dates');
105+
expect(res.stdout).not.toContain(
106+
'Environment variables with expiration dates',
107+
);
106108
expect(res.stdout).not.toContain('expired');
107109
});
108110

109111
it('handles multiple expiration patterns correctly', () => {
110112
const cwd = tmpDir();
111-
113+
112114
const yesterday = new Date();
113115
yesterday.setDate(yesterday.getDate() - 1);
114116
const expiredDate = yesterday.toISOString().split('T')[0];
115-
117+
116118
const futureDate = new Date();
117119
futureDate.setDate(futureDate.getDate() + 7);
118120
const validDate = futureDate.toISOString().split('T')[0];
119-
121+
120122
fs.writeFileSync(
121123
path.join(cwd, '.env'),
122-
`# @expire ${expiredDate}\nOLD_TOKEN=expired123\n\n# This one is still valid\n# @expire ${validDate}\nNEW_TOKEN=valid456\n\nNO_EXPIRY=permanent\n`
124+
`# @expire ${expiredDate}\nOLD_TOKEN=expired123\n\n# This one is still valid\n# @expire ${validDate}\nNEW_TOKEN=valid456\n\nNO_EXPIRY=permanent\n`,
123125
);
124126

125127
// Create a file that uses these env vars
126128
fs.mkdirSync(path.join(cwd, 'src'), { recursive: true });
127129
fs.writeFileSync(
128130
path.join(cwd, 'src', 'index.js'),
129-
'console.log(process.env.OLD_TOKEN, process.env.NEW_TOKEN, process.env.NO_EXPIRY);'
131+
'console.log(process.env.OLD_TOKEN, process.env.NEW_TOKEN, process.env.NO_EXPIRY);',
130132
);
131133

132134
const res = runCli(cwd, []);
@@ -141,21 +143,21 @@ describe('Expiration Warnings', () => {
141143

142144
it('does not warn about expiration when --no-expire-warnings is used', () => {
143145
const cwd = tmpDir();
144-
146+
145147
const yesterday = new Date();
146148
yesterday.setDate(yesterday.getDate() - 1);
147149
const expiredDate = yesterday.toISOString().split('T')[0];
148-
150+
149151
fs.writeFileSync(
150152
path.join(cwd, '.env'),
151-
`# @expire ${expiredDate}\nEXPIRED_KEY=secret123\n\nVALID_KEY=value456\n`
153+
`# @expire ${expiredDate}\nEXPIRED_KEY=secret123\n\nVALID_KEY=value456\n`,
152154
);
153155

154156
// Create a file that uses these env vars
155157
fs.mkdirSync(path.join(cwd, 'src'), { recursive: true });
156158
fs.writeFileSync(
157159
path.join(cwd, 'src', 'index.js'),
158-
'console.log(process.env.EXPIRED_KEY, process.env.VALID_KEY);'
160+
'console.log(process.env.EXPIRED_KEY, process.env.VALID_KEY);',
159161
);
160162

161163
const res = runCli(cwd, ['--no-expire-warnings']);
@@ -166,21 +168,21 @@ describe('Expiration Warnings', () => {
166168

167169
it('supports different comment styles for expiration', () => {
168170
const cwd = tmpDir();
169-
171+
170172
const yesterday = new Date();
171173
yesterday.setDate(yesterday.getDate() - 1);
172174
const expiredDate = yesterday.toISOString().split('T')[0];
173-
175+
174176
fs.writeFileSync(
175177
path.join(cwd, '.env'),
176-
`// @expire ${expiredDate}\nJS_STYLE_KEY=value1\n\n# @expire ${expiredDate}\nSHELL_STYLE_KEY=value2\n\n@expire ${expiredDate}\nNO_COMMENT_KEY=value3\n`
178+
`// @expire ${expiredDate}\nJS_STYLE_KEY=value1\n\n# @expire ${expiredDate}\nSHELL_STYLE_KEY=value2\n\n@expire ${expiredDate}\nNO_COMMENT_KEY=value3\n`,
177179
);
178180

179181
// Create a file that uses these env vars
180182
fs.mkdirSync(path.join(cwd, 'src'), { recursive: true });
181183
fs.writeFileSync(
182184
path.join(cwd, 'src', 'index.js'),
183-
'console.log(process.env.JS_STYLE_KEY, process.env.SHELL_STYLE_KEY, process.env.NO_COMMENT_KEY);'
185+
'console.log(process.env.JS_STYLE_KEY, process.env.SHELL_STYLE_KEY, process.env.NO_COMMENT_KEY);',
184186
);
185187

186188
const res = runCli(cwd, []);
@@ -194,21 +196,21 @@ describe('Expiration Warnings', () => {
194196

195197
it('exits with error in strict mode when expired variables exist', () => {
196198
const cwd = tmpDir();
197-
199+
198200
const yesterday = new Date();
199201
yesterday.setDate(yesterday.getDate() - 1);
200202
const expiredDate = yesterday.toISOString().split('T')[0];
201-
203+
202204
fs.writeFileSync(
203205
path.join(cwd, '.env'),
204-
`# @expire ${expiredDate}\nEXPIRED_KEY=secret123\n`
206+
`# @expire ${expiredDate}\nEXPIRED_KEY=secret123\n`,
205207
);
206208

207209
// Create a file that uses the env var
208210
fs.mkdirSync(path.join(cwd, 'src'), { recursive: true });
209211
fs.writeFileSync(
210212
path.join(cwd, 'src', 'index.js'),
211-
'console.log(process.env.EXPIRED_KEY);'
213+
'console.log(process.env.EXPIRED_KEY);',
212214
);
213215

214216
const res = runCli(cwd, ['--strict']);
@@ -218,4 +220,4 @@ describe('Expiration Warnings', () => {
218220
expect(res.stdout).toContain('EXPIRED_KEY');
219221
expect(res.stdout).toContain('EXPIRED');
220222
});
221-
});
223+
});

test/e2e/cli.flags.e2e.test.ts

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -445,45 +445,44 @@ describe('duplicate detection', () => {
445445
expect(res.stdout).toContain('NEW_PHP_VAR');
446446
});
447447
it('should exclude file when using --exclude-files', () => {
448-
const cwd = tmpDir();
449-
fs.writeFileSync(path.join(cwd, '.env'), 'EXISTING=value\n');
450-
fs.writeFileSync(
451-
path.join(cwd, 'index.php'),
452-
`
448+
const cwd = tmpDir();
449+
fs.writeFileSync(path.join(cwd, '.env'), 'EXISTING=value\n');
450+
fs.writeFileSync(
451+
path.join(cwd, 'index.php'),
452+
`
453453
<?php
454454
$var = getenv('NEW_PHP_VAR');
455455
`,
456-
);
456+
);
457457

458-
// Exclude .php files → NEW_PHP_VAR må ikke blive fundet
459-
const res = runCli(cwd, ['--scan-usage', '--exclude-files', '*.php']);
460-
expect(res.status).toBe(0); // exit clean
461-
expect(res.stdout).not.toContain('NEW_PHP_VAR');
462-
});
458+
// Exclude .php files → NEW_PHP_VAR må ikke blive fundet
459+
const res = runCli(cwd, ['--scan-usage', '--exclude-files', '*.php']);
460+
expect(res.status).toBe(0); // exit clean
461+
expect(res.stdout).not.toContain('NEW_PHP_VAR');
462+
});
463463

464-
it('should only scan files provided with --files', () => {
465-
const cwd = tmpDir();
466-
fs.writeFileSync(path.join(cwd, '.env'), 'EXISTING=value\n');
464+
it('should only scan files provided with --files', () => {
465+
const cwd = tmpDir();
466+
fs.writeFileSync(path.join(cwd, '.env'), 'EXISTING=value\n');
467467

468-
// To filer: en php med NEW_PHP_VAR, en js med NEW_JS_VAR
469-
fs.writeFileSync(
470-
path.join(cwd, 'index.php'),
471-
`
468+
// To filer: en php med NEW_PHP_VAR, en js med NEW_JS_VAR
469+
fs.writeFileSync(
470+
path.join(cwd, 'index.php'),
471+
`
472472
<?php
473473
$var = getenv('NEW_PHP_VAR');
474474
`,
475-
);
476-
fs.writeFileSync(
477-
path.join(cwd, 'index.js'),
478-
`
475+
);
476+
fs.writeFileSync(
477+
path.join(cwd, 'index.js'),
478+
`
479479
console.log(process.env.NEW_JS_VAR);
480480
`,
481-
);
482-
483-
const res = runCli(cwd, ['--scan-usage', '--files', 'index.js']);
484-
expect(res.status).toBe(1);
485-
expect(res.stdout).toContain('NEW_JS_VAR');
486-
expect(res.stdout).not.toContain('NEW_PHP_VAR');
487-
});
481+
);
488482

483+
const res = runCli(cwd, ['--scan-usage', '--files', 'index.js']);
484+
expect(res.status).toBe(1);
485+
expect(res.stdout).toContain('NEW_JS_VAR');
486+
expect(res.stdout).not.toContain('NEW_PHP_VAR');
487+
});
489488
});

0 commit comments

Comments
 (0)