Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# SIPp clang-format configuration
# Based on existing code style patterns in the repository

Language: Cpp
Standard: c++17

# Base style - start from LLVM and customize
BasedOnStyle: LLVM

# Indentation
IndentWidth: 4
TabWidth: 4
UseTab: Never
IndentCaseLabels: false
IndentPPDirectives: None
NamespaceIndentation: None

# Braces - Allman/BSD style (braces on their own lines)
BreakBeforeBraces: Allman
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code has both Allman and Linux. I generally prefer Linux actually (https://clang.llvm.org/docs/ClangFormatStyleOptions.html#breakbeforebraces)

# More granular control if needed:
# BraceWrapping:
# AfterClass: true
# AfterControlStatement: Always
# AfterEnum: true
# AfterFunction: true
# AfterNamespace: true
# AfterStruct: true
# AfterUnion: true
# BeforeCatch: true
# BeforeElse: true
# IndentBraces: false

# Line length
ColumnLimit: 120

# Pointer and reference alignment - attach to variable name
PointerAlignment: Right
ReferenceAlignment: Right
# e.g., char *ptr, int &ref

# Spacing
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false

# Alignment
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true

# Short statements
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false

# Breaking
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakStringLiterals: true

# Arguments and parameters
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
BinPackArguments: true
BinPackParameters: true

# Includes
IncludeBlocks: Preserve
SortIncludes: false # Don't reorder includes - can break builds

# Other
FixNamespaceComments: true
MaxEmptyLinesToKeep: 2
ReflowComments: false # Don't reflow comments - can break formatting
59 changes: 59 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
## Code Formatting

This project uses [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to maintain consistent code style. Pull requests are automatically checked for formatting compliance.

### Setup

Install clang-format (version 18 recommended):

```bash
# Ubuntu/Debian
sudo apt install clang-format-18

# macOS
brew install clang-format

# Fedora
sudo dnf install clang-tools-extra
```

### Usage

Format a single file:

```bash
clang-format -i src/myfile.cpp
```

Format all source files:

```bash
find src include -type f \( -name '*.cpp' -o -name '*.hpp' -o -name '*.c' -o -name '*.h' \) | xargs clang-format -i
```

Check formatting without modifying files:

```bash
clang-format --dry-run --Werror src/myfile.cpp
```

### Editor Integration

Most editors support automatic formatting on save:

- **VS Code**: Install the "C/C++" extension, enable "Format On Save"
- **CLion**: Built-in support, enable in Settings → Editor → Code Style
- **Vim**: Use [vim-clang-format](https://github.com/rhysd/vim-clang-format)
- **Emacs**: Use [clang-format.el](https://clang.llvm.org/docs/ClangFormat.html#emacs-integration)

### Style Overview

The project uses a style based on LLVM with these key settings:

- 4-space indentation (no tabs)
- Allman/BSD brace style (braces on their own lines)
- 120 character line limit
- Pointer/reference aligned right (`char *ptr`, not `char* ptr`)
- Includes are not sorted (to avoid breaking builds)

See `.clang-format` in the repository root for the complete configuration.
Loading