Skip to content

Commit 9d1c484

Browse files
authored
Feat/code formatting (#1912)
* Add resharper workspace shared settings * Add formatting settings - Added `RunClangFormat` shell script - Added workflow to check if formatting was applied to PR's * Remove include sorting * Convert to shell script * Fix failing tests * Format all c++ files * Create .git-blame-ignore-revs * Update clang-format-check.yml * Update namespace formatting to inner
1 parent fe7afc3 commit 9d1c484

Some content is hidden

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

64 files changed

+7322
-5927
lines changed

.clang-format

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
2+
Language : Cpp
3+
BasedOnStyle : Microsoft
4+
Standard : Latest
5+
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
6+
AccessModifierOffset : -4
7+
AlignTrailingComments :
8+
Kind : Always
9+
OverEmptyLines : 0
10+
11+
AllowAllParametersOfDeclarationOnNextLine : false
12+
AllowShortBlocksOnASingleLine : Empty
13+
AllowShortIfStatementsOnASingleLine : Never
14+
AllowShortLoopsOnASingleLine : false
15+
AllowShortCaseLabelsOnASingleLine : true
16+
AllowShortFunctionsOnASingleLine : Inline
17+
AllowShortLambdasOnASingleLine : Empty
18+
AlwaysBreakTemplateDeclarations : Yes
19+
BinPackParameters : false
20+
21+
BreakBeforeBraces : Custom
22+
BraceWrapping :
23+
AfterCaseLabel : true
24+
AfterClass : true
25+
AfterControlStatement : Always
26+
AfterEnum : true
27+
AfterFunction : true
28+
AfterNamespace : false
29+
AfterObjCDeclaration : true
30+
AfterStruct : true
31+
AfterUnion : true
32+
AfterExternBlock : true
33+
BeforeCatch : true
34+
BeforeElse : true
35+
BeforeLambdaBody : true
36+
BeforeWhile : true
37+
IndentBraces : false
38+
SplitEmptyFunction : true
39+
SplitEmptyRecord : false
40+
SplitEmptyNamespace : true
41+
42+
BreakAfterAttributes : Leave
43+
BreakBeforeTernaryOperators : false
44+
BreakConstructorInitializers : BeforeComma
45+
BreakBeforeConceptDeclarations : Always
46+
47+
ColumnLimit : 0
48+
Cpp11BracedListStyle : false
49+
CompactNamespaces : true
50+
IndentWidth : 4
51+
IndentCaseLabels : true
52+
IndentRequiresClause : true
53+
SortIncludes : Never
54+
IncludeBlocks : Preserve
55+
KeepEmptyLinesAtTheStartOfBlocks : true
56+
MaxEmptyLinesToKeep : 2
57+
EmptyLineAfterAccessModifier : Leave
58+
EmptyLineBeforeAccessModifier : LogicalBlock
59+
NamespaceIndentation : Inner
60+
PointerAlignment : Left
61+
SpacesBeforeTrailingComments : 1
62+
SpacesInAngles : Never
63+
SpacesInSquareBrackets : false
64+
RequiresClausePosition : OwnLine
65+
RequiresExpressionIndentation : Keyword
66+
67+
SpacesInLineCommentPrefix :
68+
Minimum : 1
69+
Maximum : -1
70+
71+
TabWidth : 4
72+
UseTab : Never
73+
74+
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
75+
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
76+
77+
---
78+
Language: CSharp
79+
BasedOnStyle : Microsoft
80+
Standard : Latest

.editorconfig

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
[*.cs]
2+
3+
# IDE0011: Add braces
4+
csharp_prefer_braces = false:silent
5+
6+
# IDE0008: Use explicit type
7+
dotnet_diagnostic.IDE0008.severity = none
8+
csharp_indent_labels = one_less_than_current
9+
csharp_using_directive_placement = outside_namespace:silent
10+
csharp_prefer_simple_using_statement = true:suggestion
11+
csharp_style_namespace_declarations = block_scoped:silent
12+
csharp_style_expression_bodied_methods = false:silent
13+
csharp_style_expression_bodied_constructors = false:silent
14+
csharp_style_expression_bodied_operators = false:silent
15+
csharp_style_expression_bodied_properties = true:silent
16+
csharp_style_expression_bodied_indexers = true:silent
17+
csharp_style_expression_bodied_accessors = true:silent
18+
csharp_style_expression_bodied_lambdas = true:silent
19+
csharp_style_expression_bodied_local_functions = false:silent
20+
csharp_style_throw_expression = true:suggestion
21+
csharp_style_prefer_null_check_over_type_check = true:suggestion
22+
csharp_style_prefer_method_group_conversion = true:silent
23+
csharp_space_around_binary_operators = before_and_after
24+
25+
[*.{cs,vb}]
26+
#### Naming styles ####
27+
28+
# Naming rules
29+
30+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
31+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
32+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
33+
34+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
35+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
36+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
37+
38+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
39+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
40+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
41+
42+
# Symbol specifications
43+
44+
dotnet_naming_symbols.interface.applicable_kinds = interface
45+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
46+
dotnet_naming_symbols.interface.required_modifiers =
47+
48+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
49+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
50+
dotnet_naming_symbols.types.required_modifiers =
51+
52+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
53+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
54+
dotnet_naming_symbols.non_field_members.required_modifiers =
55+
56+
# Naming styles
57+
58+
dotnet_naming_style.begins_with_i.required_prefix = I
59+
dotnet_naming_style.begins_with_i.required_suffix =
60+
dotnet_naming_style.begins_with_i.word_separator =
61+
dotnet_naming_style.begins_with_i.capitalization = pascal_case
62+
63+
dotnet_naming_style.pascal_case.required_prefix =
64+
dotnet_naming_style.pascal_case.required_suffix =
65+
dotnet_naming_style.pascal_case.word_separator =
66+
dotnet_naming_style.pascal_case.capitalization = pascal_case
67+
68+
dotnet_naming_style.pascal_case.required_prefix =
69+
dotnet_naming_style.pascal_case.required_suffix =
70+
dotnet_naming_style.pascal_case.word_separator =
71+
dotnet_naming_style.pascal_case.capitalization = pascal_case
72+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
73+
tab_width = 4
74+
indent_size = 4
75+
end_of_line = lf
76+
dotnet_style_coalesce_expression = true:suggestion
77+
dotnet_style_null_propagation = true:suggestion
78+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
79+
dotnet_style_prefer_auto_properties = true:silent
80+
dotnet_style_object_initializer = true:suggestion
81+
dotnet_style_collection_initializer = true:suggestion
82+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
83+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
84+
dotnet_style_prefer_conditional_expression_over_return = true:silent
85+
dotnet_style_explicit_tuple_names = true:suggestion
86+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
87+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
88+
dotnet_style_prefer_compound_assignment = true:suggestion
89+
dotnet_style_prefer_simplified_interpolation = true:suggestion
90+
dotnet_style_namespace_match_folder = true:suggestion

.git-blame-ignore-revs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# When making commits that are strictly formatting/style changes, add the
2+
# commit hash here, so git blame can ignore the change. See docs for more
3+
# details:
4+
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-blameignoreRevsFile
5+
#
6+
#
7+
# Example entries:
8+
#
9+
# <full commit hash> # Formating changes
10+
# <full commit hash> # rename something internal
11+
4352a86efc9a0270ecd0c1712c9f470a9bd8fb75 # Format all c++ files
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: clang-format Check
2+
3+
4+
on: [push, pull_request, workflow_dispatch]
5+
6+
# Cancel any previous workflows if the pull request was updated
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
formatting-check:
13+
name: Formatting Check
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
path:
18+
- 'src'
19+
- 'tests'
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Run clang-format style check for C/C++/Protobuf programs.
25+
uses: jidicula/clang-format-action@v4.14.0
26+
with:
27+
clang-format-version: 19
28+
fallback-style: none
29+
check-path: ${{ matrix.path }}
30+
exclude-regex: '(Bindings|CLI)/|(CppParser/(Parse)?(Expr|Stmt))'

.github/workflows/main.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ jobs:
3535

3636
steps:
3737
- uses: actions/checkout@v4
38-
with:
39-
fetch-depth: '0'
4038

4139
- name: Setup emsdk
4240
uses: mymindstorm/setup-emsdk@v11
@@ -127,8 +125,6 @@ jobs:
127125

128126
steps:
129127
- uses: actions/checkout@v4
130-
with:
131-
fetch-depth: '0'
132128

133129
- name: Set version
134130
run: nbgv cloud --all-vars

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ src/generator/generator
1717
.DS_Store
1818
*.user
1919
*.suo
20-
*.DotSettings
2120
*.sdf
2221
*.opensdf
2322
*.pdb

CppSharp.sln.DotSettings

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CLI/@EntryIndexedValue">CLI</s:String>
3+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MSVC/@EntryIndexedValue">MSVC</s:String>
4+
<s:Boolean x:Key="/Default/UserDictionary/Words/=diag/@EntryIndexedValue">True</s:Boolean>
5+
<s:Boolean x:Key="/Default/UserDictionary/Words/=undefine/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

RunClangFormat.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
solution_dir=$(cd "$(dirname "$0")"; pwd)
4+
FOLDERS="src tests"
5+
ALLOWED_EXTENSIONS_RE=".*\.\(cpp\|hpp\|c\|h\|inl\)"
6+
EXCLUSION_RE="\(Bindings\|CLI\)/\|\(CppParser/\(Parse\)?\(Expr\|Stmt\)\)"
7+
CLANG_FORMAT_OPTIONS="--fallback-style=none -i --verbose"
8+
9+
clang_format=""
10+
VS_INSTALL_DIR=""
11+
12+
13+
format()
14+
{
15+
find_clang_format
16+
17+
DRY_RUN=0
18+
# read -p "Dry run? (1/0): " DRY_RUN
19+
20+
if [ "$DRY_RUN" -eq 1 ]; then
21+
CLANG_FORMAT_OPTIONS="$CLANG_FORMAT_OPTIONS --dry-run --Werror"
22+
fi
23+
24+
# Format all files, in the specified list of directories
25+
# Loop through each file in the directory (and subdirectories)
26+
for p in $FOLDERS; do
27+
echo "Formatting files in folder \"$p\"..."
28+
cd "$solution_dir/$p"
29+
30+
file_list=$(find . -type f -regex $ALLOWED_EXTENSIONS_RE -and -not -regex ".*/\($EXCLUSION_RE\).*" -print)
31+
32+
"$clang_format" $CLANG_FORMAT_OPTIONS $file_list
33+
34+
cd ..
35+
done
36+
}
37+
38+
find_vswhere()
39+
{
40+
echo "Looking for 'vswhere'..."
41+
VSWHERE_PATH="$(printenv 'ProgramFiles(x86)')/Microsoft Visual Studio/Installer/vswhere.exe"
42+
43+
if [ -x "$(command -v vswhere.exe)" ]; then
44+
vswhere="vswhere.exe"
45+
elif [ -f "$VSWHERE_PATH" ]; then
46+
vswhere=$VSWHERE_PATH
47+
else
48+
echo -e "Could not locate vswhere.exe at:\n " $VSWHERE_PATH
49+
read -n 1 -s -r -p "Press any key to continue, or Ctrl+C to exit" key
50+
exit 1
51+
fi
52+
53+
echo -e "Found 'vswhere.exe':\n @" $vswhere "\n"
54+
}
55+
56+
find_visual_studio()
57+
{
58+
find_vswhere
59+
60+
echo "Looking for visual studio..."
61+
62+
# Find visual studio installation path
63+
VS_INSTALL_DIR=$("$vswhere" -latest -property installationPath)
64+
65+
# Find visual studio installation path
66+
if [ ! -d "$VS_INSTALL_DIR" ]; then
67+
echo -e "Visual Studio Installation directory not found at vswhere specified path:\n " $VS_INSTALL_DIR
68+
read -n 1 -s -r -p "Press any key to continue, or Ctrl+C to exit" key
69+
exit 1
70+
fi
71+
72+
echo -e "Found Visual Studio:\n @" $VS_INSTALL_DIR "\n"
73+
}
74+
75+
find_clang_format()
76+
{
77+
echo "Looking for clang-format..."
78+
find_visual_studio
79+
80+
CLANG_FORMAT_PATH="VC/Tools/Llvm/bin/clang-format.exe"
81+
clang_format="$VS_INSTALL_DIR/$CLANG_FORMAT_PATH"
82+
83+
# Verify clang-format actually exists as well
84+
if ! [ -f "$clang_format" ]; then
85+
echo "clang-format.exe could not be located at: $clang_format"
86+
read -n 1 -s -r -p "Press any key to continue, or Ctrl+C to exit" key
87+
exit 1
88+
fi
89+
90+
echo -e "Found clang-format.exe:\n" " Using" $("$clang_format" --version) "\n" " @" $clang_format "\n"
91+
}
92+
93+
format
94+
95+
echo "Done!"
96+
read -n 1 -s -r -p "Press any key to continue, or Ctrl+C to exit" key
97+
exit 0

0 commit comments

Comments
 (0)