| title | Formatting & Linting |
|---|
This guide explains how to format and lint code in Cataclysm: Bright Nights.
| File Type | Tool | Command |
|---|---|---|
C++ (.cpp/.h) |
astyle | cmake --build build --target astyle |
| JSON | json_formatter | cmake --build build --target style-json-parallel |
| Markdown | deno fmt | deno fmt |
| TypeScript | deno fmt | deno fmt |
| Lua | dprint | deno task dprint fmt |
Pull requests are automatically formatted by autofix.ci. If your code has style violations, a commit will be pushed to fix them.
Tip
To avoid merge conflicts after autofix commits, either:
- Run
git pullto merge the autofix commit, then continue working - Format locally before pushing, then
git push --forceif needed
C++ files are formatted with astyle.
# Install astyle (Ubuntu/Debian)
sudo apt install astyle
# Install astyle (Fedora)
sudo dnf install astyle
# Install astyle (macOS)
brew install astyle# Configure (only needed once, or use an existing build)
cmake --preset lint
# Format all C++ files
cmake --build build --target astyleThe style configuration is in .astylerc at the repository root.
JSON files are formatted with json_formatter, a custom tool built from the project source.
# Configure (only needed once, or use an existing build)
cmake --preset lint
# Format all JSON files in parallel
cmake --build build --target style-json-parallel
# Format all JSON files sequentially (slower, but useful for debugging)
cmake --build build --target style-jsonNote
The data/names/ directory is excluded from formatting because name files have special formatting
requirements.
Before formatting, you can validate JSON syntax:
build-scripts/lint-json.shThis runs Python's json.tool on all JSON files to catch syntax errors.
Markdown and TypeScript files are formatted with Deno.
# Install Deno
curl -fsSL https://deno.land/install.sh | sh
# Format Markdown and TypeScript
deno fmtLua files are formatted with dprint via Deno.
# Format Lua files
deno task dprint fmtNPC dialogue files have additional validation:
tools/dialogue_validator.py data/json/npcs/* data/json/npcs/*/* data/json/npcs/*/*/*Before committing, run these checks:
# Configure once (creates build directory with formatting tools)
cmake --preset lint
# Format all code
cmake --build build --target astyle # C++
cmake --build build --target style-json-parallel # JSON
deno fmt # Markdown/TypeScript
deno task dprint fmt # LuaThe CI pipeline runs these checks automatically:
- JSON syntax validation -
build-scripts/lint-json.sh - JSON formatting -
cmake --build build --target style-json-parallel - Dialogue validation -
tools/dialogue_validator.py
If any check fails, the build will fail. Use the commands above to fix issues locally before pushing.
Install these extensions for automatic formatting:
Add to your config:
" Format C++ with astyle on save
autocmd BufWritePre *.cpp,*.h !astyle --options=.astylerc %
" Format with deno
autocmd BufWritePre *.md,*.ts !deno fmt %Make sure you configured CMake with the lint preset or with -DJSON_FORMAT=ON:
cmake --preset lint
cmake --build build --target json_formatterMake sure astyle is installed and in your PATH:
# Check if astyle is available
which astyle
# Install if missing (Ubuntu/Debian)
sudo apt install astyleThen reconfigure CMake:
cmake --preset lintMake sure you're using the .astylerc from the repository root:
astyle --options=.astylerc src/*.cpp