Skip to content

Commit ef04c02

Browse files
committed
style(scripts): fix ESLint violations
- Move inline comments above code (line-comment-position) - Remove unused catch parameters (no-unused-vars) - Fix formatting to match ESLint rules
1 parent e05fcbf commit ef04c02

File tree

5 files changed

+154
-141
lines changed

5 files changed

+154
-141
lines changed

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: 49 additions & 43 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,100 +7,107 @@
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 loggerPkg from '@socketsecurity/lib/logger';
10+
import { exec } from 'node:child_process'
11+
import path from 'node:path'
12+
import { fileURLToPath } from 'node:url'
13+
import { promisify } from 'node:util'
1614

17-
const logger = loggerPkg.getDefaultLogger();
18-
const execAsync = promisify(exec);
15+
import loggerPkg from '@socketsecurity/lib/logger'
1916

20-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
21-
const rootPath = path.join(__dirname, '..');
17+
const logger = loggerPkg.getDefaultLogger()
18+
const execAsync = promisify(exec)
19+
20+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
21+
const rootPath = path.join(__dirname, '..')
2222

2323
// Maximum number of files in a single commit
24-
const MAX_FILES_PER_COMMIT = 50;
24+
const MAX_FILES_PER_COMMIT = 50
2525

2626
/**
2727
* Check if too many files are staged for commit.
2828
*/
2929
async function validateStagedFileCount() {
3030
try {
3131
// Check if we're in a git repository
32-
const { stdout: gitRoot } = await execAsync('git rev-parse --show-toplevel', {
33-
cwd: rootPath,
34-
});
32+
const { stdout: gitRoot } = await execAsync(
33+
'git rev-parse --show-toplevel',
34+
{
35+
cwd: rootPath,
36+
},
37+
)
3538

3639
if (!gitRoot.trim()) {
37-
return null; // Not a git repository
40+
// Not a git repository
41+
return null
3842
}
3943

4044
// Get list of staged files
41-
const { stdout } = await execAsync('git diff --cached --name-only', { cwd: rootPath });
45+
const { stdout } = await execAsync('git diff --cached --name-only', {
46+
cwd: rootPath,
47+
})
4248

4349
const stagedFiles = stdout
4450
.trim()
4551
.split('\n')
46-
.filter(line => line.length > 0);
52+
.filter(line => line.length > 0)
4753

4854
if (stagedFiles.length >= MAX_FILES_PER_COMMIT) {
4955
return {
5056
count: stagedFiles.length,
5157
files: stagedFiles,
5258
limit: MAX_FILES_PER_COMMIT,
53-
};
59+
}
5460
}
5561

56-
return null;
62+
return null
5763
} catch {
5864
// Not a git repo or git not available
59-
return null;
65+
return null
6066
}
6167
}
6268

6369
async function main() {
6470
try {
65-
const violation = await validateStagedFileCount();
71+
const violation = await validateStagedFileCount()
6672

6773
if (!violation) {
68-
logger.success('Commit size is acceptable');
69-
process.exitCode = 0;
70-
return;
74+
logger.success('Commit size is acceptable')
75+
process.exitCode = 0
76+
return
7177
}
7278

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

8187
// Show first 20 files, then summary if more
82-
const filesToShow = violation.files.slice(0, 20);
88+
const filesToShow = violation.files.slice(0, 20)
8389
for (const file of filesToShow) {
84-
logger.log(` ${file}`);
90+
logger.log(` ${file}`)
8591
}
8692

8793
if (violation.files.length > 20) {
88-
logger.log(` ... and ${violation.files.length - 20} more files`);
94+
logger.log(` ... and ${violation.files.length - 20} more files`)
8995
}
9096

91-
logger.log('');
97+
logger.log('')
9298
logger.log(
9399
'Split into smaller commits, check for accidentally staged files, or exclude generated files.',
94-
);
95-
logger.log('');
100+
)
101+
logger.log('')
96102

97-
process.exitCode = 1;
103+
process.exitCode = 1
98104
} catch (error) {
99-
logger.fail(`Validation failed: ${error.message}`);
100-
process.exitCode = 1;
105+
logger.fail(`Validation failed: ${error.message}`)
106+
process.exitCode = 1
101107
}
102108
}
103109

104110
main().catch(error => {
105-
logger.fail(`Validation failed: ${error}`);
106-
process.exitCode = 1;
107-
});
111+
logger.fail(`Validation failed: ${error}`)
112+
process.exitCode = 1
113+
})

scripts/validate-file-size.mjs

Lines changed: 52 additions & 48 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,18 +7,19 @@
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 loggerPkg from '@socketsecurity/lib/logger';
10+
import { promises as fs } from 'node:fs'
11+
import path from 'node:path'
12+
import { fileURLToPath } from 'node:url'
1513

16-
const logger = loggerPkg.getDefaultLogger();
14+
import loggerPkg from '@socketsecurity/lib/logger'
1715

18-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
19-
const rootPath = path.join(__dirname, '..');
16+
const logger = loggerPkg.getDefaultLogger()
2017

21-
// Maximum file size: 2MB
22-
const MAX_FILE_SIZE = 2 * 1024 * 1024; // 2,097,152 bytes
18+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
19+
const rootPath = path.join(__dirname, '..')
20+
21+
// Maximum file size: 2MB (2,097,152 bytes)
22+
const MAX_FILE_SIZE = 2 * 1024 * 1024
2323

2424
// Directories to skip
2525
const SKIP_DIRS = new Set([
@@ -36,28 +36,30 @@ const SKIP_DIRS = new Set([
3636
'.vercel',
3737
'.vscode',
3838
'tmp',
39-
]);
39+
])
4040

4141
/**
4242
* Format bytes to human-readable size.
4343
*/
4444
function formatBytes(bytes) {
45-
if (bytes === 0) return '0 B';
46-
const k = 1024;
47-
const sizes = ['B', 'KB', 'MB', 'GB'];
48-
const i = Math.floor(Math.log(bytes) / Math.log(k));
49-
return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
45+
if (bytes === 0) {
46+
return '0 B'
47+
}
48+
const k = 1024
49+
const sizes = ['B', 'KB', 'MB', 'GB']
50+
const i = Math.floor(Math.log(bytes) / Math.log(k))
51+
return `${(bytes / k ** i).toFixed(2)} ${sizes[i]}`
5052
}
5153

5254
/**
5355
* Recursively scan directory for files exceeding size limit.
5456
*/
5557
async function scanDirectory(dir, violations = []) {
5658
try {
57-
const entries = await fs.readdir(dir, { withFileTypes: true });
59+
const entries = await fs.readdir(dir, { withFileTypes: true })
5860

5961
for (const entry of entries) {
60-
const fullPath = path.join(dir, entry.name);
62+
const fullPath = path.join(dir, entry.name)
6163

6264
if (entry.isDirectory()) {
6365
// Skip excluded directories and hidden directories (except .claude, .config, .github)
@@ -68,19 +70,19 @@ async function scanDirectory(dir, violations = []) {
6870
entry.name === '.config' ||
6971
entry.name === '.github')
7072
) {
71-
await scanDirectory(fullPath, violations);
73+
await scanDirectory(fullPath, violations)
7274
}
7375
} else if (entry.isFile()) {
7476
try {
75-
const stats = await fs.stat(fullPath);
77+
const stats = await fs.stat(fullPath)
7678
if (stats.size > MAX_FILE_SIZE) {
77-
const relativePath = path.relative(rootPath, fullPath);
79+
const relativePath = path.relative(rootPath, fullPath)
7880
violations.push({
7981
file: relativePath,
8082
size: stats.size,
8183
formattedSize: formatBytes(stats.size),
8284
maxSize: formatBytes(MAX_FILE_SIZE),
83-
});
85+
})
8486
}
8587
} catch {
8688
// Skip files we can't stat
@@ -91,58 +93,60 @@ async function scanDirectory(dir, violations = []) {
9193
// Skip directories we can't read
9294
}
9395

94-
return violations;
96+
return violations
9597
}
9698

9799
/**
98100
* Validate file sizes in repository.
99101
*/
100102
async function validateFileSizes() {
101-
const violations = await scanDirectory(rootPath);
103+
const violations = await scanDirectory(rootPath)
102104

103105
// Sort by size descending (largest first)
104-
violations.sort((a, b) => b.size - a.size);
106+
violations.sort((a, b) => b.size - a.size)
105107

106-
return violations;
108+
return violations
107109
}
108110

109111
async function main() {
110112
try {
111-
const violations = await validateFileSizes();
113+
const violations = await validateFileSizes()
112114

113115
if (violations.length === 0) {
114-
logger.success('All files are within size limits');
115-
process.exitCode = 0;
116-
return;
116+
logger.success('All files are within size limits')
117+
process.exitCode = 0
118+
return
117119
}
118120

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

126128
for (const violation of violations) {
127-
logger.log(` ${violation.file}`);
128-
logger.log(` Size: ${violation.formattedSize}`);
129-
logger.log(` Exceeds limit by: ${formatBytes(violation.size - MAX_FILE_SIZE)}`);
130-
logger.log('');
129+
logger.log(` ${violation.file}`)
130+
logger.log(` Size: ${violation.formattedSize}`)
131+
logger.log(
132+
` Exceeds limit by: ${formatBytes(violation.size - MAX_FILE_SIZE)}`,
133+
)
134+
logger.log('')
131135
}
132136

133137
logger.log(
134138
'Reduce file sizes, move large files to external storage, or exclude from repository.',
135-
);
136-
logger.log('');
139+
)
140+
logger.log('')
137141

138-
process.exitCode = 1;
142+
process.exitCode = 1
139143
} catch (error) {
140-
logger.fail(`Validation failed: ${error.message}`);
141-
process.exitCode = 1;
144+
logger.fail(`Validation failed: ${error.message}`)
145+
process.exitCode = 1
142146
}
143147
}
144148

145149
main().catch(error => {
146-
logger.fail(`Validation failed: ${error}`);
147-
process.exitCode = 1;
148-
});
150+
logger.fail(`Validation failed: ${error}`)
151+
process.exitCode = 1
152+
})

0 commit comments

Comments
 (0)