-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45ff44b
commit 01adc80
Showing
6 changed files
with
731 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env node | ||
|
||
import init, { format } from '@wasm-fmt/clang-format'; | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import process from 'node:process'; | ||
|
||
await init(); | ||
|
||
// Check if -i flag is present | ||
const args = process.argv.slice(2); | ||
const inplace = args.includes('-i'); | ||
const fileArguments = args.filter((arg) => !arg.startsWith('-')); | ||
|
||
// Read .clang-format configuration | ||
const config = await fs.readFile('.clang-format', 'utf8'); | ||
|
||
for (const file of fileArguments) { | ||
try { | ||
const content = await fs.readFile(file, 'utf8'); | ||
const name = path.basename(file); | ||
const formatted = format(content, name, config); | ||
|
||
if (inplace) { | ||
if (formatted !== content) await fs.writeFile(file, formatted); | ||
} else { | ||
console.log(formatted); | ||
} | ||
} catch (error) { | ||
console.error(`Error processing file ${file}:`, error); | ||
} | ||
} |
Oops, something went wrong.