Skip to content

Commit 9c4228b

Browse files
committed
chore: enable eslint/curly rule to require braces on all control flow
1 parent e150380 commit 9c4228b

File tree

3 files changed

+59
-24
lines changed

3 files changed

+59
-24
lines changed

.oxlintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"suspicious": "error"
77
},
88
"rules": {
9-
"eslint/curly": "off",
9+
"eslint/curly": ["error", "all"],
1010
"eslint/no-await-in-loop": "off",
1111
"eslint/no-console": "off",
1212
"eslint/no-control-regex": "off",

packages/cli/scripts/sync-checksums.mjs

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
*/
1818

1919
import { createHash } from 'node:crypto'
20-
import { createReadStream, existsSync, readFileSync, promises as fs } from 'node:fs'
20+
import {
21+
createReadStream,
22+
existsSync,
23+
readFileSync,
24+
promises as fs,
25+
} from 'node:fs'
2126
import os from 'node:os'
2227
import path from 'node:path'
2328
import { fileURLToPath } from 'node:url'
@@ -48,7 +53,9 @@ function parseChecksums(content) {
4853
const checksums = {}
4954
for (const line of content.split('\n')) {
5055
const trimmed = line.trim()
51-
if (!trimmed) continue
56+
if (!trimmed) {
57+
continue
58+
}
5259
// Format: hash filename (two spaces or whitespace between)
5360
const match = trimmed.match(/^([a-f0-9]{64})\s+(.+)$/)
5461
if (match) {
@@ -64,7 +71,7 @@ function parseChecksums(content) {
6471
async function downloadFile(url, destPath) {
6572
const response = await fetch(url, {
6673
headers: {
67-
'Accept': 'application/octet-stream',
74+
Accept: 'application/octet-stream',
6875
'User-Agent': 'socket-cli-sync-checksums',
6976
},
7077
redirect: 'follow',
@@ -87,21 +94,27 @@ async function downloadFile(url, destPath) {
8794
* Fetch checksums for a GitHub release.
8895
* First tries checksums.txt, then falls back to downloading assets.
8996
*/
90-
async function fetchGitHubReleaseChecksums(repo, releaseTag, existingChecksums = {}) {
97+
async function fetchGitHubReleaseChecksums(
98+
repo,
99+
releaseTag,
100+
existingChecksums = {},
101+
) {
91102
const [owner, repoName] = repo.split('/')
92103
const apiUrl = `https://api.github.com/repos/${owner}/${repoName}/releases/tags/${releaseTag}`
93104

94105
console.log(` Fetching release info from ${apiUrl}...`)
95106

96107
const response = await fetch(apiUrl, {
97108
headers: {
98-
'Accept': 'application/vnd.github.v3+json',
109+
Accept: 'application/vnd.github.v3+json',
99110
'User-Agent': 'socket-cli-sync-checksums',
100111
},
101112
})
102113

103114
if (!response.ok) {
104-
throw new Error(`GitHub API error: ${response.status} ${response.statusText}`)
115+
throw new Error(
116+
`GitHub API error: ${response.status} ${response.statusText}`,
117+
)
105118
}
106119

107120
const release = await response.json()
@@ -111,7 +124,9 @@ async function fetchGitHubReleaseChecksums(repo, releaseTag, existingChecksums =
111124
const checksumsAsset = assets.find(a => a.name === 'checksums.txt')
112125
if (checksumsAsset) {
113126
console.log(` Found checksums.txt, downloading...`)
114-
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'socket-checksums-'))
127+
const tempDir = await fs.mkdtemp(
128+
path.join(os.tmpdir(), 'socket-checksums-'),
129+
)
115130
const checksumPath = path.join(tempDir, 'checksums.txt')
116131

117132
try {
@@ -122,7 +137,9 @@ async function fetchGitHubReleaseChecksums(repo, releaseTag, existingChecksums =
122137
// Clean up.
123138
await fs.rm(tempDir, { recursive: true })
124139

125-
console.log(` Parsed ${Object.keys(checksums).length} checksums from checksums.txt`)
140+
console.log(
141+
` Parsed ${Object.keys(checksums).length} checksums from checksums.txt`,
142+
)
126143
return checksums
127144
} catch (error) {
128145
console.log(` Failed to download checksums.txt: ${error.message}`)
@@ -139,7 +156,9 @@ async function fetchGitHubReleaseChecksums(repo, releaseTag, existingChecksums =
139156
return {}
140157
}
141158

142-
console.log(` No checksums.txt found, downloading ${assetNames.length} assets to compute checksums...`)
159+
console.log(
160+
` No checksums.txt found, downloading ${assetNames.length} assets to compute checksums...`,
161+
)
143162

144163
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'socket-checksums-'))
145164
const checksums = {}
@@ -192,24 +211,32 @@ async function main() {
192211
// Find all GitHub-released tools.
193212
const githubTools = Object.entries(externalTools)
194213
.filter(([key, value]) => {
195-
if (key.startsWith('$')) return false // Skip schema keys
214+
if (key.startsWith('$')) {
215+
return false
216+
} // Skip schema keys
196217
return value.release === 'asset'
197218
})
198219
.map(([key, value]) => ({ key, ...value }))
199220

200221
if (toolFilter) {
201222
const filtered = githubTools.filter(t => t.key === toolFilter)
202223
if (filtered.length === 0) {
203-
console.error(`Error: Tool '${toolFilter}' not found or is not a GitHub release tool`)
204-
console.log(`Available GitHub release tools: ${githubTools.map(t => t.key).join(', ')}`)
224+
console.error(
225+
`Error: Tool '${toolFilter}' not found or is not a GitHub release tool`,
226+
)
227+
console.log(
228+
`Available GitHub release tools: ${githubTools.map(t => t.key).join(', ')}`,
229+
)
205230
process.exitCode = 1
206231
return
207232
}
208233
githubTools.length = 0
209234
githubTools.push(...filtered)
210235
}
211236

212-
console.log(`Syncing checksums for ${githubTools.length} GitHub release tool(s)...\n`)
237+
console.log(
238+
`Syncing checksums for ${githubTools.length} GitHub release tool(s)...\n`,
239+
)
213240

214241
let updated = 0
215242
let unchanged = 0
@@ -235,10 +262,13 @@ async function main() {
235262

236263
// Check if update is needed.
237264
const oldChecksums = tool.checksums || {}
238-
const checksumChanged = JSON.stringify(newChecksums) !== JSON.stringify(oldChecksums)
265+
const checksumChanged =
266+
JSON.stringify(newChecksums) !== JSON.stringify(oldChecksums)
239267

240268
if (!force && !checksumChanged) {
241-
console.log(` Unchanged: ${Object.keys(newChecksums).length} checksums\n`)
269+
console.log(
270+
` Unchanged: ${Object.keys(newChecksums).length} checksums\n`,
271+
)
242272
unchanged++
243273
continue
244274
}
@@ -269,7 +299,9 @@ async function main() {
269299
}
270300

271301
// Summary.
272-
console.log(`\nSummary: ${updated} updated, ${unchanged} unchanged, ${failed} failed`)
302+
console.log(
303+
`\nSummary: ${updated} updated, ${unchanged} unchanged, ${failed} failed`,
304+
)
273305

274306
if (failed > 0) {
275307
process.exitCode = 1

scripts/validate-checksums.mjs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
2626
const rootPath = path.join(__dirname, '..')
2727

2828
// Load external tools configuration.
29-
const externalToolsPath = path.join(
30-
rootPath,
31-
'packages/cli/bundle-tools.json',
32-
)
29+
const externalToolsPath = path.join(rootPath, 'packages/cli/bundle-tools.json')
3330
const externalTools = JSON.parse(readFileSync(externalToolsPath, 'utf8'))
3431

3532
/**
@@ -47,10 +44,14 @@ function validateChecksums() {
4744

4845
// Collect all assets needed across all platforms.
4946
for (const [platform, tools] of Object.entries(PLATFORM_MAP_TOOLS)) {
50-
if (!tools) continue
47+
if (!tools) {
48+
continue
49+
}
5150

5251
for (const [toolName, assetName] of Object.entries(tools)) {
53-
if (!assetName) continue
52+
if (!assetName) {
53+
continue
54+
}
5455

5556
if (!requiredAssets.has(toolName)) {
5657
requiredAssets.set(toolName, new Set())
@@ -130,7 +131,9 @@ function validateChecksums() {
130131
logger.error(
131132
'All external tool assets MUST have SHA-256 checksums defined in bundle-tools.json.',
132133
)
133-
logger.error('This is a security requirement to prevent supply chain attacks.')
134+
logger.error(
135+
'This is a security requirement to prevent supply chain attacks.',
136+
)
134137
return false
135138
}
136139

0 commit comments

Comments
 (0)