Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yoink and apply .clang-format from pret/pokeplatinum #324

Merged
merged 19 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
103 changes: 103 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
BasedOnStyle: WebKit
Language: Cpp
LineEnding: LF
ColumnLimit: 0

AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments:
Enabled: true
AlignConsecutiveBitFields:
Enabled: true
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: Consecutive
AlignTrailingComments: false
AlignArrayOfStructures: Left

AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false

BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both

InsertBraces: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterStruct: false
AfterUnion: false
BeforeElse: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: false

AlwaysBreakAfterReturnType: None
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: true
BreakStringLiterals: true

DerivePointerAlignment: false
PointerAlignment: Right
ReferenceAlignment: Right

ContinuationIndentWidth: 4
IndentCaseBlocks: false
IndentCaseLabels: false
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth: 4

SortIncludes: CaseSensitive
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '((<.+>)|("nitro/.*\.h"))'
Priority: 1
- Regex: '"global\.h"'
Priority: 2
- Regex: '"(consts|constants)/.*\.h"'
Priority: 3
- Regex: '"(struct_(decls|defs))/.*\.h"'
Priority: 4
- Regex: '"(constdata|res)/.*\.(h|naix)"'
Priority: 7
- Regex: '"[[:alnum:]_]+/.*\.(h|naix)"'
Priority: 5
- Regex: '"[[:alnum:]_]+\.(h|naix)"'
Priority: 6
- Regex: '.*'
Priority: 8

InsertTrailingCommas: Wrapped
InsertNewlineAtEOF: true
KeepEmptyLinesAtEOF: false
MaxEmptyLinesToKeep: 1
RemoveParentheses: ReturnStatement
RemoveSemicolon: true

# QualifierAlignment: Custom
# QualifierOrder: [static, inline, const, volatile, type]

SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParens: Never
4 changes: 4 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/*.s
**/*.inc
**/*.json
lib/
9 changes: 9 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
# Redirect output to stderr.
exec 1>&2

# Run clang-format on staged files; abort the commit if any files are changed
if ! git clang-format --extensions c,cpp,h,hpp ; then
echo "linting made changes to source files; aborting commit"
exit 1
fi
49 changes: 49 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Contributing to pret/pokeheartgold

<!--toc:start-->
- [Code Formatting](#code-formatting)
<!--toc:end-->

This document provides a synopsis and loose guidelines for how to contribute to this project. It is a work in progress. Maintainers should expand this document.

## Code Formatting

This repository includes an opinionated `clang-format` specification to ensure that we maintain a common code style. For convenience, a pre-commit hook is also provided in `.githooks` which will run `clang-format` against any staged changes prior to executing a commit.

### Requirements

- `clang-format@17` or newer

### Usage

To set up the pre-commit hook:

```sh
git config --local core.hooksPath .githooks/
```

To run the formatter on the full source tree:

```bash
./format.sh
```

### Nonmatching functions

clang-format does not recognize the syntax for inline asm that is required by mwccarm, so it should be disabled for non-matching functions specifically. clang-format accepts directives via comments of the form `// clang-format [on|off]`. Example:

```c
#ifdef NONMATCHING
void func() {
// ...
}
#else
// clang-format off
asm void func() {
push {lr}
// ...
pop {pc}
}
// clang-format on
#endif // NONMATCHING
```
4 changes: 4 additions & 0 deletions format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e

find src include -name "*.c" -or -name "*.cpp" -or -name "*.h" -or -name "*.hpp" | xargs clang-format -i --verbose
Loading