Skip to content

Commit 5c6e1db

Browse files
authored
Formatting (#47)
1 parent 749b1e7 commit 5c6e1db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3760
-3751
lines changed

.clang-format

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
AccessModifierOffset: -2
2+
AlignAfterOpenBracket: BlockIndent
3+
AlignConsecutiveAssignments: false
4+
AlignConsecutiveDeclarations: true
5+
AlignEscapedNewlines: Left
6+
AlignOperands: DontAlign
7+
AlignTrailingComments: false
8+
AllowAllArgumentsOnNextLine: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: None
13+
AllowShortIfStatementsOnASingleLine: WithoutElse
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterDefinitionReturnType: None
16+
AlwaysBreakAfterReturnType: None
17+
AlwaysBreakBeforeMultilineStrings: true
18+
AlwaysBreakTemplateDeclarations: Yes
19+
BinPackArguments: false
20+
BinPackParameters: false
21+
BraceWrapping:
22+
AfterClass: false
23+
AfterControlStatement: false
24+
AfterEnum: false
25+
AfterFunction: false
26+
AfterNamespace: false
27+
AfterStruct: false
28+
AfterUnion: false
29+
AfterExternBlock: false
30+
BeforeCatch: false
31+
BeforeElse: false
32+
IndentBraces: false
33+
SplitEmptyFunction: false
34+
SplitEmptyRecord: false
35+
SplitEmptyNamespace: false
36+
BreakAfterJavaFieldAnnotations: false
37+
BreakBeforeBinaryOperators: None
38+
BreakBeforeBraces: Custom
39+
BreakBeforeInheritanceComma: false
40+
BreakBeforeTernaryOperators: true
41+
BreakConstructorInitializers: BeforeComma
42+
BreakConstructorInitializersBeforeComma: false
43+
BreakStringLiterals: true
44+
ColumnLimit: 80
45+
CompactNamespaces: false
46+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
47+
ConstructorInitializerIndentWidth: 2
48+
ContinuationIndentWidth: 2
49+
Cpp11BracedListStyle: true
50+
DerivePointerAlignment: false
51+
DisableFormat: false
52+
ExperimentalAutoDetectBinPacking: false
53+
FixNamespaceComments: true
54+
IncludeBlocks: Preserve
55+
IncludeIsMainRegex: "(Test)?$"
56+
IndentCaseLabels: true
57+
IndentPPDirectives: AfterHash
58+
IndentWidth: 2
59+
IndentWrappedFunctionNames: false
60+
InsertBraces: true
61+
JavaScriptQuotes: Leave
62+
JavaScriptWrapImports: true
63+
KeepEmptyLinesAtTheStartOfBlocks: false
64+
MacroBlockBegin: ""
65+
MacroBlockEnd: ""
66+
MaxEmptyLinesToKeep: 1
67+
NamespaceIndentation: None
68+
PackConstructorInitializers: NextLine
69+
PenaltyBreakAssignment: 10
70+
PenaltyBreakBeforeFirstCallParameter: 30
71+
PenaltyBreakComment: 10
72+
PenaltyBreakFirstLessLess: 0
73+
PenaltyBreakString: 10
74+
PenaltyExcessCharacter: 400
75+
PenaltyReturnTypeOnItsOwnLine: 350
76+
PointerAlignment: Left
77+
ReflowComments: true
78+
RequiresClausePosition: OwnLine
79+
SortIncludes: false
80+
SortUsingDeclarations: true
81+
SpaceAfterCStyleCast: false
82+
SpaceAfterLogicalNot: false
83+
SpaceAfterTemplateKeyword: false
84+
SpaceBeforeAssignmentOperators: true
85+
SpaceBeforeCtorInitializerColon: true
86+
SpaceBeforeInheritanceColon: true
87+
SpaceBeforeParens: Never
88+
SpaceBeforeRangeBasedForLoopColon: true
89+
SpaceInEmptyParentheses: false
90+
SpacesBeforeTrailingComments: 1
91+
SpacesInAngles: Never
92+
SpacesInContainerLiterals: false
93+
SpacesInCStyleCastParentheses: false
94+
SpacesInParentheses: false
95+
SpacesInSquareBrackets: false
96+
SeparateDefinitionBlocks: Always
97+
Standard: Latest
98+
TabWidth: 2
99+
UseTab: ForContinuationAndIndentation
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Johanan Idicula <johanan@forcepush.tech>
4+
Copyright (c) 2022 Seaube Software CORP.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: "clang-format Check"
2+
description: "Use clang-format to see if your C/C++/Protobuf code is formatted according to project guidelines."
3+
4+
branding:
5+
icon: "check-circle"
6+
color: "blue"
7+
8+
inputs:
9+
clang-format-version:
10+
description: 'The version of clang-format that you want to use.'
11+
required: false
12+
default: '15'
13+
check-path:
14+
description: 'The path to the directory you want to check for correct C/C++/Protobuf formatting. Default is the full repository.'
15+
required: false
16+
default: '.'
17+
exclude-regex:
18+
description: 'A regex to exclude files or directories that should not be checked. Default is empty.'
19+
required: false
20+
default: ''
21+
fallback-style:
22+
description: 'The fallback style for clang-format if no .clang-format file exists in your repository.'
23+
required: false
24+
default: 'llvm'
25+
26+
runs:
27+
using: "composite"
28+
steps:
29+
- run: |
30+
"${{ github.action_path }}/check.sh" "${{ inputs.clang-format-version }}" "${{ inputs.check-path }}" "${{ inputs.fallback-style }}" "${{ inputs.exclude-regex }}"
31+
shell: bash
32+
- name: Save PR head commit SHA
33+
if: failure() && github.event_name == 'pull_request'
34+
shell: bash
35+
run: |
36+
SHA="${{ github.event.pull_request.head.sha }}"
37+
echo "SHA=$SHA" >> $GITHUB_ENV
38+
- name: Save latest commit SHA if not PR
39+
if: failure() && github.event_name != 'pull_request'
40+
shell: bash
41+
run: echo "SHA=${{ github.sha }}" >> $GITHUB_ENV
42+
43+
- name: Report failure in job summary
44+
if: failure()
45+
run: |
46+
DEEPLINK="https://github.com/${{ github.repository }}/commit/${{ env.SHA }}"
47+
echo -e "Format check failed on commit [${GITHUB_SHA:0:8}]($DEEPLINK) with files:\n$(<$GITHUB_WORKSPACE/.github/workflows/clang-format-action/failing-files.txt)" >> $GITHUB_STEP_SUMMARY
48+
shell: bash
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
3+
###############################################################################
4+
# entrypoint.sh #
5+
###############################################################################
6+
# USAGE: ./entrypoint.sh [<path>] [<fallback style>]
7+
#
8+
# Checks all C/C++/Protobuf files (.h, .H, .hpp, .hh, .h++, .hxx and .c, .C,
9+
# .cpp, .cc, .c++, .cxx, .proto) in the provided GitHub repository path
10+
# (arg1) for conforming to clang-format. If no path is provided or provided path
11+
# is not a directory, all C/C++/Protobuf files are checked. If any files are
12+
# incorrectly formatted, the script lists them and exits with 1.
13+
#
14+
# Define your own formatting rules in a .clang-format file at your repository
15+
# root. Otherwise, the provided style guide (arg2) is used as a fallback.
16+
17+
# format_diff function
18+
# Accepts a filepath argument. The filepath passed to this function must point
19+
# to a C/C++/Protobuf file.
20+
format_diff() {
21+
local filepath="$1"
22+
# Invoke clang-format with dry run and formatting error output
23+
if [[ $CLANG_FORMAT_VERSION -gt "9" ]]; then
24+
local_format="$(docker run -i -v "$(pwd)":"$(pwd)" -w "$(pwd)" --rm ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_VERSION" -n --Werror --style=file --fallback-style="$FALLBACK_STYLE" "${filepath}")"
25+
else # Versions below 9 don't have dry run
26+
formatted="$(docker run -i -v "$(pwd)":"$(pwd)" -w "$(pwd)" --rm ghcr.io/jidicula/clang-format:"$CLANG_FORMAT_VERSION" --style=file --fallback-style="$FALLBACK_STYLE" "${filepath}")"
27+
local_format="$(diff -q <(cat "${filepath}") <(echo "${formatted}"))"
28+
fi
29+
30+
local format_status="$?"
31+
if [[ ${format_status} -ne 0 ]]; then
32+
# Append Markdown-bulleted monospaced filepath of failing file to
33+
# summary file.
34+
echo "* \`$filepath\`" >>.github/workflows/clang-format-action/failing-files.txt
35+
36+
echo "Failed on file: $filepath" >&2
37+
echo "$local_format" >&2
38+
exit_code=1 # flip the global exit code
39+
return "${format_status}"
40+
fi
41+
return 0
42+
}
43+
44+
CLANG_FORMAT_VERSION="$1"
45+
CHECK_PATH="$2"
46+
FALLBACK_STYLE="$3"
47+
EXCLUDE_REGEX="$4"
48+
49+
# Set the regex to an empty string regex if nothing was provided
50+
if [ -z "$EXCLUDE_REGEX" ]; then
51+
EXCLUDE_REGEX="^$"
52+
fi
53+
54+
cd "$GITHUB_WORKSPACE" || exit 2
55+
56+
if [[ ! -d $CHECK_PATH ]]; then
57+
echo "Not a directory in the workspace, fallback to all files." >&2
58+
CHECK_PATH="."
59+
fi
60+
61+
# initialize exit code
62+
exit_code=0
63+
64+
# All files improperly formatted will be printed to the output.
65+
# find all C/C++/Protobuf files:
66+
# h, H, hpp, hh, h++, hxx
67+
# c, C, cpp, cc, c++, cxx
68+
# ino, pde
69+
# proto
70+
src_files=$(find "$CHECK_PATH" -name .git -prune -o -regextype posix-egrep -regex '^.*\.((((c|C)(c|pp|xx|\+\+)?$)|((h|H)h?(pp|xx|\+\+)?$))|(ino|pde)|(proto)|(cs))$' -print)
71+
72+
# check formatting in each source file
73+
for file in $src_files; do
74+
# Only check formatting if the path doesn't match the regex
75+
if ! [[ ${file} =~ $EXCLUDE_REGEX ]]; then
76+
format_diff "${file}"
77+
fi
78+
done
79+
80+
# global exit code is flipped to nonzero if any invocation of `format_diff` has
81+
# a formatting difference.
82+
exit "$exit_code"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ARG UBUNTU_VERSION
2+
FROM ubuntu:${UBUNTU_VERSION}
3+
4+
ARG CLANG_FORMAT_VERSION
5+
6+
RUN apt-get update \
7+
&& apt-get install --no-install-recommends -y \
8+
clang-format-${CLANG_FORMAT_VERSION} \
9+
# Clean cache
10+
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
11+
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* \
12+
&& mv /usr/bin/clang-format-${CLANG_FORMAT_VERSION} /usr/bin/clang-format
13+
14+
15+
ENTRYPOINT ["/usr/bin/clang-format"]

.github/workflows/clang-format-action/failing-files.txt

Whitespace-only changes.

.github/workflows/main.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
8+
concurrency:
9+
group: ${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
formatting-check:
14+
name: Formatting Check
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: ./.github/workflows/clang-format-action

.vscode/settings.json

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
11
{
2-
"editor.insertSpaces": false,
2+
"editor.formatOnSave": true,
33
"files.insertFinalNewline": true,
4+
"files.eol": "\n",
5+
"editor.insertSpaces": false,
6+
"files.associations": {},
7+
"editor.wordWrap": "wordWrapColumn",
8+
"C_Cpp.autocomplete": "default",
9+
"C_Cpp.autoAddFileAssociations": false,
10+
"C_Cpp.default.compileCommands": "${workspaceFolder}/compile_commands.json",
11+
"lldb.launch.sourceMap": {
12+
"/proc/self/cwd": "${workspaceFolder}"
13+
},
14+
"[yaml]": {
15+
"editor.formatOnSave": false
16+
},
17+
"[csharp]": {
18+
"editor.defaultFormatter": "seaube.clangformat"
19+
},
20+
"[json]": {
21+
"editor.defaultFormatter": "vscode.json-language-features"
22+
},
23+
"[jsonc]": {
24+
"editor.defaultFormatter": "vscode.json-language-features"
25+
},
26+
"[markdown]": {
27+
"editor.defaultFormatter": "DavidAnson.vscode-markdownlint"
28+
},
29+
"[cpp]": {
30+
"editor.detectIndentation": false,
31+
"editor.defaultFormatter": "seaube.clangformat"
32+
},
433
"[starlark]": {
5-
"editor.formatOnSave": true,
6-
"editor.defaultFormatter": "BazelBuild.vscode-bazel"
34+
"editor.defaultFormatter": "BazelBuild.vscode-bazel",
35+
"editor.insertSpaces": true,
36+
"editor.detectIndentation": false
737
}
838
}

EcsactCsharpSystemImpl/Editor/CsharpSystemImplSettings.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ public static CsharpSystemImplSettings Get() {
1919
return _instance;
2020
}
2121

22-
_instance = AssetDatabase.LoadAssetAtPath<CsharpSystemImplSettings>(
23-
assetPath
24-
);
22+
_instance =
23+
AssetDatabase.LoadAssetAtPath<CsharpSystemImplSettings>(assetPath);
2524
if(_instance == null) {
2625
_instance = ScriptableObject.CreateInstance<CsharpSystemImplSettings>();
2726
Directory.CreateDirectory(Path.GetDirectoryName(assetPath));
@@ -37,7 +36,6 @@ public static CsharpSystemImplSettings Get() {
3736

3837
return _instance;
3938
}
40-
4139
}
4240

4341
} // namespace Ecsact.Editor

0 commit comments

Comments
 (0)