Skip to content

Commit 713cfab

Browse files
authored
feat: add a clang-format playground (#104)
<!-- claude-projects-attribution: {"github_login":"shenxianpeng"} --> A new page at `/playground/`: paste C or C++ code, pick an LLVM version and a style, and see what clang-format changes. Preview: https://deploy-preview-104--cpp-linter-github-io.netlify.app/playground/ ## What it does - **LLVM 16 to 23.** clang-format runs in the browser as WebAssembly, from the [@wasm-fmt/clang-format](https://www.npmjs.com/package/@wasm-fmt/clang-format) npm package (MIT), imported from jsDelivr the first time a version is picked. The code never leaves the page. - **Styles.** The 7 presets (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU) or your own `.clang-format` text. A bad config shows clang-format's own reason, for example `Unknown value for BasedOnStyle: Nope`. - **Result.** A line diff with unchanged runs folded, or the formatted file with a Copy button. "Already formatted" when nothing changes. The status line uses the brand status marks. - **Run the same check.** For the version and style picked, the page writes the clang-tools commands, the cpp-linter-hooks entry and the cpp-linter-action step, each with a Copy button. - **Copy link.** The URL hash keeps the code and the settings once something changes, so a link opens exactly what is on screen. ## Where it is linked - Top navigation, after Get started (`mkdocs.yml`). - Home page header and the Learn column of its footer (`docs/overrides/home.html`). - `scripts/update-versions.py` now also updates the cpp-linter-hooks `rev:` in the playground's script, so that example stays current like the others. ## Notes - The page has no clang-tidy: it needs the compile flags and headers of a real build. The page says so. - The WebAssembly build of a version can be a different patch release from the one cpp-linter installs, for example 21.1.8 here. The page says so too. - `playground.css` and `playground.js` load only on this page, through `docs/overrides/playground.html`. ## Checked - `mkdocs build --strict` and the repository's pre-commit hooks pass. - In Chromium: versions 16, 21 and 23, a custom `.clang-format`, a broken config, already-formatted input, a shared link reopened in a new tab, and light, dark and 390 px wide layouts (no sideways scroll). The same run passes on the deploy preview.
1 parent 78e0c77 commit 713cfab

8 files changed

Lines changed: 889 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# cpp-linter.github.io
22

3-
The source of <https://cpp-linter.github.io/>: the home page, Get started, Why cpp-linter, the
4-
showcase, the blog and the community and sponsor pages.
3+
The source of <https://cpp-linter.github.io/>: the home page, Get started, the clang-format
4+
playground, Why cpp-linter, the showcase, the blog and the community and sponsor pages.
55

66
[Website](https://cpp-linter.github.io/) ·
77
[Get started](https://cpp-linter.github.io/getting-started/) ·

0 commit comments

Comments
 (0)