-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add formatting infrastructure to the project and upgrade LLVM.
Upgrading project wide LLVM version to 18 and add infrastructure to format c++ files with clang-format. We upgrade to llvm-18 because some of the clang-format options we're using have only been released with clang-format 18. Added: 1. clang-format file matching internal one 2. formatting tool based on python for cross-platform 3. pre-commit and pre-push hooks for formatting validation 4. Lint CI action.
- Loading branch information
Showing
18 changed files
with
394 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,91 @@ | ||
Language: Cpp | ||
Standard: c++20 | ||
ColumnLimit: 100 | ||
|
||
WhitespaceSensitiveMacros: | ||
# clang format doesn't understand TypeScript, so make sure it doesn't mangle | ||
# overrides and additional definitions | ||
- JSG_TS_OVERRIDE | ||
- JSG_TS_DEFINE | ||
- JSG_STRUCT_TS_OVERRIDE | ||
- JSG_STRUCT_TS_DEFINE | ||
PointerAlignment: Left | ||
ColumnLimit: 100 | ||
AllowShortFunctionsOnASingleLine: Empty | ||
|
||
# We should have "true" here but adding an include header would result in too many changed lines. | ||
# Once we turn this on we should use IncludeCategories so that things are consistently sorted. | ||
# For example, to protect against brittle headers (a header not including everything its using | ||
# because existing users happened to include a dependency for it), one could use the following | ||
# order: | ||
# local folder files | ||
# project files | ||
# 3p dependency includes | ||
# standard language headers (put kj/ here?) | ||
# system headers | ||
# While this would be ideal it's also important to note that this isn't the (non-documented) style | ||
# that KJ uses, so it may be worth documenting the style & making it consistent. | ||
SortIncludes: false | ||
|
||
AllowShortIfStatementsOnASingleLine: true | ||
AllowShortLoopsOnASingleLine: true | ||
|
||
IndentWidth: 2 | ||
IndentCaseBlocks: false | ||
IndentCaseLabels: true | ||
PointerAlignment: Left | ||
DerivePointerAlignment: true | ||
|
||
# Really "Attach" but empty braces aren't split. | ||
BreakBeforeBraces: Custom | ||
BraceWrapping: | ||
AfterCaseLabel: false | ||
AfterClass: false | ||
AfterControlStatement: Never | ||
AfterEnum: false | ||
AfterFunction: false | ||
AfterNamespace: false | ||
AfterObjCDeclaration: false | ||
AfterStruct: false | ||
AfterUnion: false | ||
AfterExternBlock: false | ||
BeforeCatch: false | ||
BeforeElse: false | ||
BeforeLambdaBody: false | ||
BeforeWhile: false | ||
IndentBraces: false | ||
SplitEmptyFunction: false | ||
SplitEmptyRecord: false | ||
SplitEmptyNamespace: false | ||
|
||
Cpp11BracedListStyle: true | ||
|
||
AlignAfterOpenBracket: DontAlign | ||
AlignOperands: DontAlign | ||
AlignTrailingComments: | ||
Kind: Always | ||
OverEmptyLines: 0 | ||
AlwaysBreakAfterReturnType: None | ||
AlwaysBreakTemplateDeclarations: Yes | ||
BreakStringLiterals: false | ||
BinPackArguments: true | ||
BinPackParameters: false | ||
BracedInitializerIndentWidth: 2 | ||
BreakInheritanceList: BeforeColon | ||
ContinuationIndentWidth: 4 | ||
IfMacros: | ||
[ | ||
"KJ_SWITCH_ONEOF", | ||
"KJ_CASE_ONEOF", | ||
"KJ_IF_MAYBE", | ||
"KJ_IF_SOME", | ||
"CFJS_RESOURCE_TYPE", | ||
] | ||
LambdaBodyIndentation: OuterScope | ||
Macros: ["KJ_MAP(x,y)=[y](auto x)", "JSG_VISITABLE_LAMBDA(x,y,z)=[x,y]z"] | ||
PenaltyReturnTypeOnItsOwnLine: 1000 | ||
PackConstructorInitializers: CurrentLine | ||
ReflowComments: false | ||
SpaceBeforeCtorInitializerColon: false | ||
SpaceBeforeInheritanceColon: false | ||
SpaceBeforeParens: ControlStatementsExceptControlMacros | ||
SpaceBeforeRangeBasedForLoopColon: false | ||
SpacesBeforeTrailingComments: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Tests | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- src/** | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
show-progress: false | ||
- name: Setup Linux | ||
run: | | ||
sudo apt-get install -y --no-install-recommends clang-format-18 | ||
- name: Lint | ||
run: | | ||
python3 ./tools/cross/format.py --check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
|
||
source "$(dirname -- $BASH_SOURCE)/../tools/unix/find-python3.sh" | ||
PYTHON_PATH=$(get_python3) | ||
if [[ -z "$PYTHON_PATH" ]]; then | ||
echo | ||
echo "python3 is required for formatting and was not found" | ||
echo | ||
echo "ERROR: you must either install python3 and try pushing again or run `git push` with `--no-verify`" | ||
exit 1 | ||
fi | ||
|
||
while read LOCAL_REF LOCAL_SHA REMOTE_REF REMOTE_SHA | ||
do | ||
git fetch origin master &>/dev/null | ||
# Check all local changes, not present in origin/master, for lint. | ||
set +e | ||
$PYTHON_PATH "$(dirname -- $BASH_SOURCE)/../tools/cross/format.py" --check git --source $LOCAL_SHA --target origin/master | ||
EXIT_CODE=$? | ||
set -e | ||
case $EXIT_CODE in | ||
0) | ||
# No lint. | ||
;; | ||
1) | ||
echo | ||
echo "ERROR: changes in $LOCAL_REF have lint which may fail CI." | ||
echo | ||
echo "To fix lint:" | ||
echo " python3 ./tools/cross/format.py" | ||
echo | ||
exit 1 | ||
;; | ||
2) | ||
echo | ||
echo "ERROR: failed to run format.py, Pass '--no-verify' or '-n' to skip." | ||
echo | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
Oops, something went wrong.