Skip to content

feat: add a clang-format playground - #104

Open
shenxianpeng wants to merge 2 commits into
mainfrom
claude/project-thread-1t3184
Open

shenxianpeng wants to merge 2 commits into
mainfrom
claude/project-thread-1t3184

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

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 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.

@shenxianpeng shenxianpeng self-assigned this Nov 20, 2026
@netlify

netlify Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cpp-linter-github-io ready!

Name Link
🔨 Latest commit f7ef69e
🔍 Latest deploy log https://app.netlify.com/projects/cpp-linter-github-io/deploys/6b00da01a66d1152a4ec4017
😎 Deploy Preview https://deploy-preview-104--cpp-linter-github-io.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

A page at /playground/ where you paste C or C++ code, pick an LLVM
version from 16 to 23 and a style (a preset or your own .clang-format),
and see what clang-format changes as a diff or as the formatted file.
clang-format runs in the browser: the WebAssembly builds of the
@wasm-fmt/clang-format npm package are imported from jsDelivr, one per
version picked, so the code never leaves the page.

Below the result, the page shows the same check for the version and
style picked: the clang-tools commands, the cpp-linter-hooks entry and
the cpp-linter-action step. The URL hash keeps the code and settings,
so "Copy link" shares what is on screen.

The page is in the top navigation, the home page header and its footer.
scripts/update-versions.py now also updates the cpp-linter-hooks rev in
the playground's script.
Opening /playground/ no longer writes the sample code into the URL hash. The hash is written after the first change, and Copy link writes it as before.
@shenxianpeng
shenxianpeng force-pushed the claude/project-thread-1t3184 branch from 223c49c to f7ef69e Compare November 20, 2026 23:38

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant