Skip to content

Commit ba76c1c

Browse files
committed
fix(scripts): resolve ESLint violations in validation scripts
Move inline comments above code and remove unused error parameters to satisfy ESLint rules (line-comment-position, no-unused-vars).
1 parent 2f242d7 commit ba76c1c

5 files changed

Lines changed: 155 additions & 137 deletions

File tree

scripts/validate-esbuild-minify.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ async function main() {
6868
for (const violation of violations) {
6969
console.error(` ${violation.message}`)
7070
console.error(` Found: minify: ${violation.value}`)
71-
console.error(` Expected: minify: false`)
71+
console.error(' Expected: minify: false')
7272
console.error(` Location: ${violation.location}`)
7373
console.error('')
7474
}
7575

76-
console.error('Minification breaks ESM/CJS interop and makes debugging harder.')
76+
console.error(
77+
'Minification breaks ESM/CJS interop and makes debugging harder.',
78+
)
7779
console.error('')
7880

7981
process.exitCode = 1

scripts/validate-file-count.mjs

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,100 +8,107 @@
88
* - Prevents overly large commits that are hard to review
99
*/
1010

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';
11+
import { exec } from 'node:child_process'
12+
import path from 'node:path'
13+
import { fileURLToPath } from 'node:url'
14+
import { promisify } from 'node:util'
1615

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

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

2324
// Maximum number of files in a single commit
24-
const MAX_FILES_PER_COMMIT = 50;
25+
const MAX_FILES_PER_COMMIT = 50
2526

2627
/**
2728
* Check if too many files are staged for commit.
2829
*/
2930
async function validateStagedFileCount() {
3031
try {
3132
// Check if we're in a git repository
32-
const { stdout: gitRoot } = await execAsync('git rev-parse --show-toplevel', {
33-
cwd: rootPath,
34-
});
35-
33+
const { stdout: gitRoot } = await execAsync(
34+
'git rev-parse --show-toplevel',
35+
{
36+
cwd: rootPath,
37+
},
38+
)
39+
40+
// Not a git repository
3641
if (!gitRoot.trim()) {
37-
return null; // Not a git repository
42+
return null
3843
}
3944

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

4350
const stagedFiles = stdout
4451
.trim()
4552
.split('\n')
46-
.filter(line => line.length > 0);
53+
.filter(line => line.length > 0)
4754

4855
if (stagedFiles.length >= MAX_FILES_PER_COMMIT) {
4956
return {
5057
count: stagedFiles.length,
5158
files: stagedFiles,
5259
limit: MAX_FILES_PER_COMMIT,
53-
};
60+
}
5461
}
5562

56-
return null;
63+
return null
5764
} catch {
5865
// Not a git repo or git not available
59-
return null;
66+
return null
6067
}
6168
}
6269

6370
async function main() {
6471
try {
65-
const violation = await validateStagedFileCount();
72+
const violation = await validateStagedFileCount()
6673

6774
if (!violation) {
68-
logger.success('Commit size is acceptable');
69-
process.exitCode = 0;
70-
return;
75+
logger.success('Commit size is acceptable')
76+
process.exitCode = 0
77+
return
7178
}
7279

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('');
80+
logger.fail('Too many files staged for commit')
81+
logger.log('')
82+
logger.log(`Staged files: ${violation.count}`)
83+
logger.log(`Maximum allowed: ${violation.limit}`)
84+
logger.log('')
85+
logger.log('Staged files:')
86+
logger.log('')
8087

8188
// Show first 20 files, then summary if more
82-
const filesToShow = violation.files.slice(0, 20);
89+
const filesToShow = violation.files.slice(0, 20)
8390
for (const file of filesToShow) {
84-
logger.log(` ${file}`);
91+
logger.log(` ${file}`)
8592
}
8693

8794
if (violation.files.length > 20) {
88-
logger.log(` ... and ${violation.files.length - 20} more files`);
95+
logger.log(` ... and ${violation.files.length - 20} more files`)
8996
}
9097

91-
logger.log('');
98+
logger.log('')
9299
logger.log(
93100
'Split into smaller commits, check for accidentally staged files, or exclude generated files.',
94-
);
95-
logger.log('');
101+
)
102+
logger.log('')
96103

97-
process.exitCode = 1;
104+
process.exitCode = 1
98105
} catch (error) {
99-
logger.fail(`Validation failed: ${error.message}`);
100-
process.exitCode = 1;
106+
logger.fail(`Validation failed: ${error.message}`)
107+
process.exitCode = 1
101108
}
102109
}
103110

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

scripts/validate-file-size.mjs

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88
* - Excludes: node_modules, .git, dist, build, coverage directories
99
*/
1010

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';
11+
import { promises as fs } from 'node:fs'
12+
import path from 'node:path'
13+
import { fileURLToPath } from 'node:url'
1514

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

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

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

2425
// Directories to skip
2526
const SKIP_DIRS = new Set([
@@ -36,28 +37,30 @@ const SKIP_DIRS = new Set([
3637
'.vercel',
3738
'.vscode',
3839
'tmp',
39-
]);
40+
])
4041

4142
/**
4243
* Format bytes to human-readable size.
4344
*/
4445
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]}`;
46+
if (bytes === 0) {
47+
return '0 B'
48+
}
49+
const k = 1024
50+
const sizes = ['B', 'KB', 'MB', 'GB']
51+
const i = Math.floor(Math.log(bytes) / Math.log(k))
52+
return `${(bytes / k ** i).toFixed(2)} ${sizes[i]}`
5053
}
5154

5255
/**
5356
* Recursively scan directory for files exceeding size limit.
5457
*/
5558
async function scanDirectory(dir, violations = []) {
5659
try {
57-
const entries = await fs.readdir(dir, { withFileTypes: true });
60+
const entries = await fs.readdir(dir, { withFileTypes: true })
5861

5962
for (const entry of entries) {
60-
const fullPath = path.join(dir, entry.name);
63+
const fullPath = path.join(dir, entry.name)
6164

6265
if (entry.isDirectory()) {
6366
// Skip excluded directories and hidden directories (except .claude, .config, .github)
@@ -68,19 +71,19 @@ async function scanDirectory(dir, violations = []) {
6871
entry.name === '.config' ||
6972
entry.name === '.github')
7073
) {
71-
await scanDirectory(fullPath, violations);
74+
await scanDirectory(fullPath, violations)
7275
}
7376
} else if (entry.isFile()) {
7477
try {
75-
const stats = await fs.stat(fullPath);
78+
const stats = await fs.stat(fullPath)
7679
if (stats.size > MAX_FILE_SIZE) {
77-
const relativePath = path.relative(rootPath, fullPath);
80+
const relativePath = path.relative(rootPath, fullPath)
7881
violations.push({
7982
file: relativePath,
8083
size: stats.size,
8184
formattedSize: formatBytes(stats.size),
8285
maxSize: formatBytes(MAX_FILE_SIZE),
83-
});
86+
})
8487
}
8588
} catch {
8689
// Skip files we can't stat
@@ -91,58 +94,60 @@ async function scanDirectory(dir, violations = []) {
9194
// Skip directories we can't read
9295
}
9396

94-
return violations;
97+
return violations
9598
}
9699

97100
/**
98101
* Validate file sizes in repository.
99102
*/
100103
async function validateFileSizes() {
101-
const violations = await scanDirectory(rootPath);
104+
const violations = await scanDirectory(rootPath)
102105

103106
// Sort by size descending (largest first)
104-
violations.sort((a, b) => b.size - a.size);
107+
violations.sort((a, b) => b.size - a.size)
105108

106-
return violations;
109+
return violations
107110
}
108111

109112
async function main() {
110113
try {
111-
const violations = await validateFileSizes();
114+
const violations = await validateFileSizes()
112115

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

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('');
122+
logger.fail('File size violations found')
123+
logger.log('')
124+
logger.log(`Maximum allowed file size: ${formatBytes(MAX_FILE_SIZE)}`)
125+
logger.log('')
126+
logger.log('Files exceeding limit:')
127+
logger.log('')
125128

126129
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('');
130+
logger.log(` ${violation.file}`)
131+
logger.log(` Size: ${violation.formattedSize}`)
132+
logger.log(
133+
` Exceeds limit by: ${formatBytes(violation.size - MAX_FILE_SIZE)}`,
134+
)
135+
logger.log('')
131136
}
132137

133138
logger.log(
134139
'Reduce file sizes, move large files to external storage, or exclude from repository.',
135-
);
136-
logger.log('');
140+
)
141+
logger.log('')
137142

138-
process.exitCode = 1;
143+
process.exitCode = 1
139144
} catch (error) {
140-
logger.fail(`Validation failed: ${error.message}`);
141-
process.exitCode = 1;
145+
logger.fail(`Validation failed: ${error.message}`)
146+
process.exitCode = 1
142147
}
143148
}
144149

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

0 commit comments

Comments
 (0)