π Coding Style
πGeneral Rulesβ
- Follow
.editorconfigexactly:- Indent: 2 spaces (except Makefile: tabs)
- Charset: UTF-8
- Line endings: LF
- Max line length: 120 (off for JSON, Markdown, lock files, images)
- Insert final newline at EOF
- Trim trailing whitespace (exceptions: JSON, Markdown, YAML, binary, lock files)
- Use Prettier for JS/React:
npm run format-js - Use clang-format for C++:
npm run format-wasm - Lint JS/React:
npm run lintand fix withnpm run lint:fix - Do not manually override formatting outside Prettier/clang-format unless necessary.
β JavaScript / Reactβ
- Indent: 2 spaces
- Max line length: 120
- Single quotes
'...' - Semicolons: required
- Trailing commas: ES5
- JSX: Prettier defaults,
bracketSameLine: true - React Hooks rules:
react-hooks/rules-of-hooks: errorreact-hooks/exhaustive-deps: warn
- Globals: browser
π» C / C++β
- Indent: 2 spaces
- Max line length: 120
- Brace style: Allman (opening brace on a new line)
#include- angle brackets: for external libraries (e.g.,
iostream) - quotes: for internal libraries
- angle brackets: for external libraries (e.g.,
- Use namespaces to avoid collisions
- Use
clang-format(npm run format-wasm)
Example C++ Header
exampleFunction.h
#ifndef EXAMPLE_FUNCTION_H
#define EXAMPLE_FUNCTION_H
#include <cstdint>
namespace exampleNamespace
{
void exampleFunction(uint8_t x);
}
#endif // EXAMPLE_FUNCTION_H
Example C++ Implementation
exampleFunction.cpp
#include "exampleFunction.h"
#include "internalLibrary.h"
#include <iostream>
namespace exampleNamespace
{
void exampleFunction(uint8_t x)
{
if (internalLibrary::isPrime(x))
{
std::cout << "Prime" << std::endl;
return;
}
std::cout << "Non-prime" << std::endl;
}
}
π HTML / CSS / Markdown / YAMLβ
- Indent: 2 spaces
- Trim trailing whitespace (except Markdown/YAML)
- Insert final newline
- Max line length: 120 (off for Markdown/YAML)
π¦ JSON / lock filesβ
- Indent: 2 spaces
- Do not trim trailing whitespace
- Final newline: true (lock files: false)
- Max line length: off
π Makefilesβ
- Indent: tabs only
πΌ Images / Binary Assetsβ
- Charset: binary
- Do not trim trailing whitespace
- No final newline
- Max line length: off