Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions scripts/clang-format.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import child_process from 'child_process';

const args = ['--Werror', '-i', '--style=file', 'module.cc'];
const cmd = `./node_modules/.bin/clang-format ${args.join(' ')}`;

try {
child_process.execSync(cmd, {stdio: 'inherit'});
child_process.execFileSync('./node_modules/.bin/clang-format', args, {stdio: 'inherit'});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The switch to execFileSync will cause the script to fail on Windows because it cannot execute the .cmd wrapper for clang-format without a shell.
Severity: HIGH

Suggested Fix

Add the { shell: true } option to the execFileSync call. This will allow it to correctly execute shell scripts like .cmd files on Windows. The updated call would be child_process.execFileSync('./node_modules/.bin/clang-format', args, {stdio: 'inherit', shell: true});.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: scripts/clang-format.mjs#L6

Potential issue: The change from `execSync` to `execFileSync` to run the `clang-format`
command will cause a runtime failure on Windows. On Windows, the executable in
`node_modules/.bin` is a `.cmd` batch file. `execFileSync` does not use a shell by
default and cannot execute `.cmd` files directly, unlike `execSync`. This will cause the
script to throw an error when `yarn lint` or `yarn fix:clang` is run in a Windows
environment, breaking the linting process for developers on that platform. This issue is
not caught by the current CI, which only runs the lint job on Ubuntu.

Did we get this right? 👍 / 👎 to inform future reviews.

} catch (e) {
// This fails on linux_arm64
// eslint-disable-next-line no-console
Expand Down
Loading