Add .clang-format(-[include,ignore]) and format script

This commit is contained in:
Rachel 2024-04-03 18:28:16 -07:00
parent 34dce4f0f5
commit 373398d047
5 changed files with 152 additions and 5 deletions

98
.clang-format Normal file
View File

@ -0,0 +1,98 @@
---
BasedOnStyle: WebKit
Language: Cpp
LineEnding: LF
ColumnLimit: 0
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: Consecutive
AlignTrailingComments: false
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: true
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: '"(consts|constants)/.*\.h"'
Priority: 2
- Regex: '"(struct_(decls|defs))/.*\.h"'
Priority: 3
- Regex: '"(constdata|res)/.*\.(h|naix)"'
Priority: 6
- Regex: '"[[:alnum:]_]+/.*\.(h|naix)"'
Priority: 4
- Regex: '"[[:alnum:]_]+\.(h|naix)"'
Priority: 5
- Regex: '.*'
Priority: 7
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

23
.clang-format-ignore Normal file
View File

@ -0,0 +1,23 @@
# These files still contain inline-ASM functions; ignore them for formatting for now
src/overlay117/ov117_02260668.c
src/overlay112/ov112_0225C700.c
src/overlay110/ov110_021D0D80.c
src/overlay020/ov20_021D4728.c
src/unk_0208A3F4.c
src/unk_02089604.c
src/overlay073/ov73_021D3250.c
src/overlay107/ov107_02245EB0.c
src/overlay107/ov107_02241AE0.c
src/overlay007/ov7_02249960.c
src/overlay071/ov71_0223C69C.c
src/overlay019/ov19_021D0D80.c
src/overlay022/ov22_02259C58.c
src/overlay023/ov23_02253598.c
src/overlay065/ov65_0222DCE0.c
src/overlay064/ov64_0222DCE0.c
src/overlay098/ov98_022471C8.c
src/overlay062/ov62_02241204.c
src/overlay062/ov62_0223DFA8.c
src/overlay062/ov62_0223CAEC.c
src/overlay062/ov62_02231690.c
src/overlay062/ov62_02237D24.c

3
.clang-format-include Normal file
View File

@ -0,0 +1,3 @@
include/**/*
src/**/*

View File

@ -3,18 +3,19 @@
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.
## Contents
- [Editor enhancements](#editor-enhancements)
- [Editor Enhancements](#editor-enhancements)
- [Code Formatting](#code-formatting)
<a href="editor-enhancements"></a>
## Editor enhancements
## Editor Enhancements
This repository includes a script to generate a `compile_commands.json` that is compatible with C language servers such as `clangd`.
### Requirements
- python3.8 or newer
- gcc-arm-none-eabi
- clangd
- `python3.8` or newer
- `gcc-arm-none-eabi`
- `clangd`
### Usage
@ -23,3 +24,21 @@ This repository includes a script to generate a `compile_commands.json` that is
```
This will create a file named `compile_commands.json` in the project root, overwriting the previous copy.
<a href="code-formatting"></a>
## Code Formatting
This repository includes an opinionated `clang-format` specification which is integrated into the build system for convenience in ensuring that your code adheres to repository style guidelines.
### Requirements
- `clang-format`
### Usage
```bash
./build.sh format
```
This will traverse the source tree and format all found C sources and headers according to the specified style rules.

4
format.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
set -e
"${NINJA:-ninja}" -C build clang-format