Repository navigation
Commit 713cfab
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
- docs
- javascripts
- overrides
- stylesheets
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
0 commit comments