Skip to content

Commit d2c2a2a

Browse files
committed
style(scripts): format validation scripts
- Remove shebang lines from validation scripts - Fix code formatting (consistent brace style, semicolons) - Replace Math.pow with exponentiation operator (**) - Add underscore prefix to unused catch parameters - Fix import ordering
1 parent f42852e commit d2c2a2a

5 files changed

Lines changed: 140 additions & 135 deletions

File tree

scripts/validate-esbuild-minify.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env node
21
/**
32
* @fileoverview Validates that esbuild configuration has minify: false.
43
* Minification breaks ESM/CJS interop and makes debugging harder.
@@ -68,12 +67,14 @@ async function main() {
6867
for (const violation of violations) {
6968
console.error(` ${violation.message}`)
7069
console.error(` Found: minify: ${violation.value}`)
71-
console.error(` Expected: minify: false`)
70+
console.error(' Expected: minify: false')
7271
console.error(` Location: ${violation.location}`)
7372
console.error('')
7473
}
7574

76-
console.error('Minification breaks ESM/CJS interop and makes debugging harder.')
75+
console.error(
76+
'Minification breaks ESM/CJS interop and makes debugging harder.',
77+
)
7778
console.error('')
7879

7980
process.exitCode = 1

scripts/validate-file-count.mjs

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env node
21
/**
32
* @fileoverview Validates that commits don't contain too many files.
43
*
@@ -8,99 +7,104 @@
87
* - Prevents overly large commits that are hard to review
98
*/
109

11-
import { exec } from 'node:child_process';
12-
import path from 'node:path';
13-
import { promisify } from 'node:util';
14-
import { fileURLToPath } from 'node:url';
15-
import { logger } from './utils/logger.mjs';
10+
import { exec } from 'node:child_process'
11+
import path from 'node:path'
12+
import { promisify } from 'node:util'
13+
import { fileURLToPath } from 'node:url'
14+
import { logger } from './utils/logger.mjs'
1615

17-
const execAsync = promisify(exec);
16+
const execAsync = promisify(exec)
1817

19-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
20-
const rootPath = path.join(__dirname, '..');
18+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
19+
const rootPath = path.join(__dirname, '..')
2120

2221
// Maximum number of files in a single commit
23-
const MAX_FILES_PER_COMMIT = 50;
22+
const MAX_FILES_PER_COMMIT = 50
2423

2524
/**
2625
* Check if too many files are staged for commit.
2726
*/
2827
async function validateStagedFileCount() {
2928
try {
3029
// Check if we're in a git repository
31-
const { stdout: gitRoot } = await execAsync('git rev-parse --show-toplevel', {
32-
cwd: rootPath,
33-
});
30+
const { stdout: gitRoot } = await execAsync(
31+
'git rev-parse --show-toplevel',
32+
{
33+
cwd: rootPath,
34+
},
35+
)
3436

3537
if (!gitRoot.trim()) {
36-
return null; // Not a git repository
38+
return null // Not a git repository
3739
}
3840

3941
// Get list of staged files
40-
const { stdout } = await execAsync('git diff --cached --name-only', { cwd: rootPath });
42+
const { stdout } = await execAsync('git diff --cached --name-only', {
43+
cwd: rootPath,
44+
})
4145

4246
const stagedFiles = stdout
4347
.trim()
4448
.split('\n')
45-
.filter(line => line.length > 0);
49+
.filter(line => line.length > 0)
4650

4751
if (stagedFiles.length >= MAX_FILES_PER_COMMIT) {
4852
return {
4953
count: stagedFiles.length,
5054
files: stagedFiles,
5155
limit: MAX_FILES_PER_COMMIT,
52-
};
56+
}
5357
}
5458

55-
return null;
59+
return null
5660
} catch {
5761
// Not a git repo or git not available
58-
return null;
62+
return null
5963
}
6064
}
6165

6266
async function main() {
6367
try {
64-
const violation = await validateStagedFileCount();
68+
const violation = await validateStagedFileCount()
6569

6670
if (!violation) {
67-
logger.success('Commit size is acceptable');
68-
process.exitCode = 0;
69-
return;
71+
logger.success('Commit size is acceptable')
72+
process.exitCode = 0
73+
return
7074
}
7175

72-
logger.fail('Too many files staged for commit');
73-
logger.log('');
74-
logger.log(`Staged files: ${violation.count}`);
75-
logger.log(`Maximum allowed: ${violation.limit}`);
76-
logger.log('');
77-
logger.log('Staged files:');
78-
logger.log('');
76+
logger.fail('Too many files staged for commit')
77+
logger.log('')
78+
logger.log(`Staged files: ${violation.count}`)
79+
logger.log(`Maximum allowed: ${violation.limit}`)
80+
logger.log('')
81+
logger.log('Staged files:')
82+
logger.log('')
7983

8084
// Show first 20 files, then summary if more
81-
const filesToShow = violation.files.slice(0, 20);
85+
const filesToShow = violation.files.slice(0, 20)
8286
for (const file of filesToShow) {
83-
logger.log(` ${file}`);
87+
logger.log(` ${file}`)
8488
}
8589

8690
if (violation.files.length > 20) {
87-
logger.log(` ... and ${violation.files.length - 20} more files`);
91+
logger.log(` ... and ${violation.files.length - 20} more files`)
8892
}
8993

90-
logger.log('');
94+
logger.log('')
9195
logger.log(
9296
'Split into smaller commits, check for accidentally staged files, or exclude generated files.',
93-
);
94-
logger.log('');
97+
)
98+
logger.log('')
9599

96-
process.exitCode = 1;
100+
process.exitCode = 1
97101
} catch (error) {
98-
logger.fail(`Validation failed: ${error.message}`);
99-
process.exitCode = 1;
102+
logger.fail(`Validation failed: ${error.message}`)
103+
process.exitCode = 1
100104
}
101105
}
102106

103107
main().catch(error => {
104-
logger.fail(`Validation failed: ${error}`);
105-
process.exitCode = 1;
106-
});
108+
logger.fail(`Validation failed: ${error}`)
109+
process.exitCode = 1
110+
})

scripts/validate-file-size.mjs

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env node
21
/**
32
* @fileoverview Validates that no individual files exceed size threshold.
43
*
@@ -8,16 +7,16 @@
87
* - Excludes: node_modules, .git, dist, build, coverage directories
98
*/
109

11-
import { promises as fs } from 'node:fs';
12-
import path from 'node:path';
13-
import { fileURLToPath } from 'node:url';
14-
import { logger } from './utils/logger.mjs';
10+
import { promises as fs } from 'node:fs'
11+
import path from 'node:path'
12+
import { fileURLToPath } from 'node:url'
13+
import { logger } from './utils/logger.mjs'
1514

16-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
17-
const rootPath = path.join(__dirname, '..');
15+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
16+
const rootPath = path.join(__dirname, '..')
1817

1918
// Maximum file size: 2MB
20-
const MAX_FILE_SIZE = 2 * 1024 * 1024; // 2,097,152 bytes
19+
const MAX_FILE_SIZE = 2 * 1024 * 1024 // 2,097,152 bytes
2120

2221
// Directories to skip
2322
const SKIP_DIRS = new Set([
@@ -34,28 +33,30 @@ const SKIP_DIRS = new Set([
3433
'.vercel',
3534
'.vscode',
3635
'tmp',
37-
]);
36+
])
3837

3938
/**
4039
* Format bytes to human-readable size.
4140
*/
4241
function formatBytes(bytes) {
43-
if (bytes === 0) return '0 B';
44-
const k = 1024;
45-
const sizes = ['B', 'KB', 'MB', 'GB'];
46-
const i = Math.floor(Math.log(bytes) / Math.log(k));
47-
return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
42+
if (bytes === 0) {
43+
return '0 B'
44+
}
45+
const k = 1024
46+
const sizes = ['B', 'KB', 'MB', 'GB']
47+
const i = Math.floor(Math.log(bytes) / Math.log(k))
48+
return `${(bytes / k ** i).toFixed(2)} ${sizes[i]}`
4849
}
4950

5051
/**
5152
* Recursively scan directory for files exceeding size limit.
5253
*/
5354
async function scanDirectory(dir, violations = []) {
5455
try {
55-
const entries = await fs.readdir(dir, { withFileTypes: true });
56+
const entries = await fs.readdir(dir, { withFileTypes: true })
5657

5758
for (const entry of entries) {
58-
const fullPath = path.join(dir, entry.name);
59+
const fullPath = path.join(dir, entry.name)
5960

6061
if (entry.isDirectory()) {
6162
// Skip excluded directories and hidden directories (except .claude, .config, .github)
@@ -66,19 +67,19 @@ async function scanDirectory(dir, violations = []) {
6667
entry.name === '.config' ||
6768
entry.name === '.github')
6869
) {
69-
await scanDirectory(fullPath, violations);
70+
await scanDirectory(fullPath, violations)
7071
}
7172
} else if (entry.isFile()) {
7273
try {
73-
const stats = await fs.stat(fullPath);
74+
const stats = await fs.stat(fullPath)
7475
if (stats.size > MAX_FILE_SIZE) {
75-
const relativePath = path.relative(rootPath, fullPath);
76+
const relativePath = path.relative(rootPath, fullPath)
7677
violations.push({
7778
file: relativePath,
7879
size: stats.size,
7980
formattedSize: formatBytes(stats.size),
8081
maxSize: formatBytes(MAX_FILE_SIZE),
81-
});
82+
})
8283
}
8384
} catch {
8485
// Skip files we can't stat
@@ -89,58 +90,60 @@ async function scanDirectory(dir, violations = []) {
8990
// Skip directories we can't read
9091
}
9192

92-
return violations;
93+
return violations
9394
}
9495

9596
/**
9697
* Validate file sizes in repository.
9798
*/
9899
async function validateFileSizes() {
99-
const violations = await scanDirectory(rootPath);
100+
const violations = await scanDirectory(rootPath)
100101

101102
// Sort by size descending (largest first)
102-
violations.sort((a, b) => b.size - a.size);
103+
violations.sort((a, b) => b.size - a.size)
103104

104-
return violations;
105+
return violations
105106
}
106107

107108
async function main() {
108109
try {
109-
const violations = await validateFileSizes();
110+
const violations = await validateFileSizes()
110111

111112
if (violations.length === 0) {
112-
logger.success('All files are within size limits');
113-
process.exitCode = 0;
114-
return;
113+
logger.success('All files are within size limits')
114+
process.exitCode = 0
115+
return
115116
}
116117

117-
logger.fail('File size violations found');
118-
logger.log('');
119-
logger.log(`Maximum allowed file size: ${formatBytes(MAX_FILE_SIZE)}`);
120-
logger.log('');
121-
logger.log('Files exceeding limit:');
122-
logger.log('');
118+
logger.fail('File size violations found')
119+
logger.log('')
120+
logger.log(`Maximum allowed file size: ${formatBytes(MAX_FILE_SIZE)}`)
121+
logger.log('')
122+
logger.log('Files exceeding limit:')
123+
logger.log('')
123124

124125
for (const violation of violations) {
125-
logger.log(` ${violation.file}`);
126-
logger.log(` Size: ${violation.formattedSize}`);
127-
logger.log(` Exceeds limit by: ${formatBytes(violation.size - MAX_FILE_SIZE)}`);
128-
logger.log('');
126+
logger.log(` ${violation.file}`)
127+
logger.log(` Size: ${violation.formattedSize}`)
128+
logger.log(
129+
` Exceeds limit by: ${formatBytes(violation.size - MAX_FILE_SIZE)}`,
130+
)
131+
logger.log('')
129132
}
130133

131134
logger.log(
132135
'Reduce file sizes, move large files to external storage, or exclude from repository.',
133-
);
134-
logger.log('');
136+
)
137+
logger.log('')
135138

136-
process.exitCode = 1;
139+
process.exitCode = 1
137140
} catch (error) {
138-
logger.fail(`Validation failed: ${error.message}`);
139-
process.exitCode = 1;
141+
logger.fail(`Validation failed: ${error.message}`)
142+
process.exitCode = 1
140143
}
141144
}
142145

143146
main().catch(error => {
144-
logger.fail(`Validation failed: ${error}`);
145-
process.exitCode = 1;
146-
});
147+
logger.fail(`Validation failed: ${error}`)
148+
process.exitCode = 1
149+
})

0 commit comments

Comments
 (0)