emscripten-core / emscripten-core/emscripten

Protection against clang-format

Open
#17,935 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Running clang-format on a piece of code such as `EM_ASM(a !== b);` results in `a != = b` (note broken code with space)

It appears clang-format doesn't understand that the code inside EM_ASM is javascript and shouldn't be reformatted.
One can somewhat workaround this with `// clang-format [on|off]` comments, but they need to be repeated at each callsite.
This bug is about recommending a best practice when using both clang-format & emscripten.

Possible approaches

Perhaps the EM_ASM macro could be marked up to indicate embedded JS & for clang-format to ignore it or use different formatting rules. Clang-format has support for this via RawStringFormats option which allows embedded code to be tagged e.g. `R"this-is-js(alert("Hello");)this-is-js"` but I didn't find a way to combine raw strings with the preprocessing stringizing.

Another option is to provide users with macros for passing raw strings instead of implicitly stringizing. e.g. one might write `EM_ASM_R( R"js( a!==b; )js" )`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.