Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0bf14a1
draft
licanhua Nov 30, 2021
ec915c1
update readme
licanhua Nov 30, 2021
5d71677
format project
licanhua Nov 30, 2021
43798c6
update pipeline
licanhua Nov 30, 2021
9d2c700
revert change on ios
licanhua Nov 30, 2021
d3ca076
revert change on PerfApp because it's C++/CX project and ^ is not wel…
licanhua Nov 30, 2021
95c0185
update local vs version and make BasedOnStyle:Microsoft
licanhua Dec 1, 2021
8d03136
disable pipeline check and revert change on formatted files
licanhua Dec 1, 2021
8a21c5b
remove .h, .cpp from .editorconfig
licanhua Dec 1, 2021
ae9d843
Apply suggestions from code review
licanhua Dec 3, 2021
8599a38
Update .clang-format
licanhua Dec 3, 2021
211ea7e
enable hooks and recover clang-format
licanhua Dec 3, 2021
ece507a
rollback to cpp11
licanhua Dec 3, 2021
700de21
format files
licanhua Dec 3, 2021
ee45fe9
Revert "format files"
licanhua Dec 3, 2021
946ab61
Revert "format files"
licanhua Dec 3, 2021
be36875
add clang-format-launcher
licanhua Dec 6, 2021
01d30f5
Merge branch 'clang-format' of https://github.com/microsoft/adaptivec…
licanhua Dec 6, 2021
848a995
clang-format exception
licanhua Dec 6, 2021
84575c1
update documents
licanhua Dec 6, 2021
63276aa
add npm run format to error
licanhua Dec 6, 2021
bad13cb
update package-lock
licanhua Dec 6, 2021
72d3def
add pipeline to check the format and create patch file if failed
licanhua Dec 7, 2021
1a133c2
update echo message
licanhua Dec 7, 2021
21248a9
Merge branch 'main' into clang-format
licanhua Dec 7, 2021
d25f9f7
move clang.format.json to package.json
licanhua Dec 8, 2021
c69536b
Merge branch 'main' into clang-format
beervoley Dec 9, 2021
756e486
address comments
licanhua Dec 9, 2021
4554100
Merge branch 'clang-format' of https://github.com/microsoft/adaptivec…
licanhua Dec 9, 2021
7c09754
Merge branch 'main' into clang-format
licanhua Dec 9, 2021
c9ca001
Deleting outdated VsCode extension (#6831)
Dec 8, 2021
eba8150
provide crossplatform hooks
licanhua Dec 10, 2021
15a3efb
Merge branch 'clang-format' of https://github.com/microsoft/adaptivec…
licanhua Dec 10, 2021
b3f3162
Merge branch 'main' into clang-format
licanhua Dec 10, 2021
3c13d07
Update scripts/hooks/clangFormatFunc
licanhua Dec 11, 2021
493f1b8
address comment
licanhua Dec 11, 2021
576b2b5
limit error number
licanhua Dec 11, 2021
1cc02c8
Merge branch 'main' into clang-format
licanhua Dec 11, 2021
1b0e1d5
update clang-format-launcher version
licanhua Dec 13, 2021
c4c62f3
Update .clang-format
licanhua Dec 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 1 addition & 62 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ BasedOnStyle: Microsoft
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignEscapedNewlines: DontAlign
AllowShortBlocksOnASingleLine: Never
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterUnion: true
Expand All @@ -24,69 +22,10 @@ IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^"(stdafx.h|pch.h|precomp.h)"$'
Priority: -1
MacroBlockBegin: '^BEGIN_COM_MAP$|^BEGIN_CONNECTION_POINT_MAP$|^BEGIN_HELPER_NODEMAP$|^BEGIN_MODULE$|^BEGIN_MSG_MAP$|^BEGIN_OBJECT_MAP$|^BEGIN_TEST_CLASS$|^BEGIN_TEST_METHOD$|^BEGIN_TEST_METHOD_PROPERTIES$'
MacroBlockEnd: '^END_COM_MAP$|^END_CONNECTION_POINT_MAP$|^END_HELPER_NODEMAP$|^END_MODULE$|^END_MSG_MAP$|^END_OBJECT_MAP$|^END_TEST_CLASS$|^END_TEST_METHOD$|^END_TEST_METHOD_PROPERTIES$'
NamespaceIndentation: Inner
PenaltyExcessCharacter: 1
PointerAlignment: Left
SortIncludes: false
Standard: Cpp11
StatementMacros: [
_Acquires_exclusive_lock_,
_Acquires_lock_,
_Acquires_nonreentrant_lock_,
_Acquires_shared_lock_,
_Analysis_assume_smart_lock_acquired_,
_Analysis_assume_smart_lock_released_,
_Create_lock_level_,
_Detaches_lock_,
_Function_class_,
_Global_cancel_spin_lock_,
_Global_critical_region_,
_Global_interlock_,
_Global_priority_region_,
_Has_lock_kind_,
_Has_lock_level_,
_IRQL_always_function_max_,
_IRQL_always_function_min_,
_IRQL_raises_,
_IRQL_requires_,
_IRQL_requires_max_,
_IRQL_requires_min_,
_IRQL_requires_same_,
_IRQL_restores_,
_IRQL_restores_global_,
_IRQL_saves_,
_IRQL_saves_global_,
_Lock_level_order_,
_Moves_lock_,
_Must_inspect_result_,
_No_competing_thread_,
_Post_same_lock_,
_Post_writable_byte_size_,
_Pre_satisfies_,
_Releases_exclusive_lock_,
_Releases_lock_,
_Releases_nonreentrant_lock_,
_Releases_shared_lock_,
_Replaces_lock_,
_Requires_exclusive_lock_held_,
_Requires_lock_held_,
_Requires_lock_not_held_,
_Requires_no_locks_held_,
_Requires_shared_lock_held_,
_Ret_maybenull_,
_Ret_range_,
_Success_,
_Swaps_locks_,
_Use_decl_annotations_,
_When_,
RpcEndExcept,
]
TabWidth: 4
TypenameMacros: [
IFACEMETHOD,
STDMETHOD,
]
UseTab: Never
...
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
root = true

[**.{java,mm,cs,ts,js,tsx}]
[**.{cpp,h,java,mm,cs}]
indent_style = spaces
indent_size = 4
charset = utf-8
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
## files generated by popular Visual Studio add-ons.
.gitconfig

scripts/hooks/pre-push
scripts/hooks/pre-commit

# User-specific files
Expand Down
35 changes: 14 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ PS: Latest Build Status is against `main` branch.

We require the C++ code inside this project to follow the clang-format. If you change them, please make sure your changed files are formatted correctly.

Make sure clang-format version 12.0.0 and above version are used.
Make sure clang-format version 12.0.0 and above version is used.

### IDE integration
ClangFormat describes a set of tools that are built on top of LibFormat. It can support your workflow in a variety of ways including a standalone tool and editor integrations. For details, refer to https://clang.llvm.org/docs/ClangFormat.html

### Format with scripts
### Format with script
Two scripts are provided to help you format files.
- Windows only user: use FormatSource.ps1. This script use clang-format.exe which is built into Visual Studio by default.
- Windows user only: use FormatSource.ps1. This script use clang-format.exe which is built into Visual Studio by default.

Execute below command in the root folder of the project

Expand All @@ -54,7 +54,7 @@ If it's the first time to run the script, make sure clang-format version 12.0.0
clang-format version 12.0.0
```

- Both Windows and MAC user: Use clang-format npmjs package
- Both Windows and MAC users: Use clang-format npmjs package

Execute below command in source/nodejs

Expand All @@ -64,27 +64,20 @@ clang-format version 12.0.0

Make sure `npm install` is run before.

#### Setup Git hooks
This is an optional process and a one time setup for Windows user only. When you `git commit` or `git push`, it will automatically do the format check and ask you to correct it if format error detected.
### Use Git pre-commit hook
`git pre-commit hook` is an optional process. When you run `git commit`, it will automatically do the format check and auto fix the format if error detected.

```
scripts\SetupClangFormat.bat
```

then choose `scripts/hooks/pre-commit.txt` or `scripts/hooks/pre-commit.txt` and remove the `.txt` to enable that hook.

### Two ways to format the files
First make sure clang-format binary is installed in your dev enviroment.
Then modify scripts/hooks/pre-commit to make sure clangFormat is point to the correct path.
And finally setup the git hook.

### 1) Use script to format files before you submit the change

`PowerShell.exe -ExecutionPolicy Bypass scripts\FormatSource.ps1 -ModifiedOnly $False`

or

`PowerShell.exe -ExecutionPolicy Bypass scripts\FormatSource.ps1 -ModifiedOnly $False -Path yourfolder`
Two ways to setup the hook:
1. Copy `scripts/hooks/pre-commit` to `.git/hooks`
2. `git config --local core.hooksPath scripts/hooks`

then choose `scripts/hooks/pre-commit.txt` or `scripts/hooks/pre-commit.txt` and remove the `.txt` to enable that hook.

#### End User License Agreement for our binary packages
## End User License Agreement for our binary packages
Consumption of the AdaptiveCards binary packages are subject to the Microsoft EULA (End User License Agreement). Please see the relevant terms as listed below:
- [UWP/.NET](https://github.com/microsoft/AdaptiveCards/blob/main/source/EULA-Windows.txt)
- [Android/iOS](https://github.com/microsoft/AdaptiveCards/blob/main/source/EULA-Non-Windows.txt)
Expand Down
9 changes: 0 additions & 9 deletions scripts/SetupClangFormat.bat

This file was deleted.

32 changes: 32 additions & 0 deletions scripts/hooks/clangFormatFunc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

endWith='\.(cpp|cc|h|hpp)$'
ignoreFolder='/(PerfApp|android|ios|nodejs|vscode|community|dotnet)/'

function checkFormat() {
if [ -z "$clangFormat" ]; then
echo '$clangFormat is not set correct in clangFormatCheck'
return 1
fi

for file in $(git diff-index --cached --name-only HEAD | grep -iE "${endWith}" | grep -iE -v "${ignoreFolder}"); do
"$clangFormat" --style=file -Werror --dry-run --verbose "$file"
if [ $? -ne 0 ]; then
echo "Bad format for $file"
return 1
fi
done
return 0
}

function fixFormat() {
for file in $(git diff-index --cached --name-only HEAD | grep -iE "${endWith}" | grep -iE -v "${ignoreFolder}"); do
"$clangFormat" --style=file -Werror -i --verbose "$file"
if [ $? -ne 0 ]; then
echo "clang-format auto fix failed for $file, please run below command manually:"
echo " \"$clangFormat\" --style=file -Werror -i --verbose \"$file\""
return 1
fi
done
return 0
}
34 changes: 34 additions & 0 deletions scripts/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

# clangFormat="c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\Llvm\x64\bin\clang-format.exe"
if [ -z "$clangFormat" ]; then
clangFormat="clang-format"
else
if [[ ! -f "$clangFormat" ]]; then
echo "Can't find the binary $clangFormat"
exit 1
fi
fi

"$clangFormat" --version
if [ "$?" -ne "0" ]; then
echo "'git commit' aborted! Please make sure clangFormat is set correctly in pre-commit."
exit 1
fi

. "scripts/hooks/clangFormatFunc"

checkFormat

if [ "$?" -ne "0" ]; then
echo "start auto fix clang-format"
fixFormat
if [ "$?" -ne "0" ]; then
echo "'git commit' aborted! Clang-format auto fix failed, and you have to manually fix the format issue."
else
echo "'git commit' aborted! But clang-format auto fix success, please re-run 'git add' and 'git commit'."
fi
exit 1
else
echo "clang-format check passed, and will continue the commit"
fi
8 changes: 0 additions & 8 deletions scripts/hooks/pre-commit.txt

This file was deleted.

8 changes: 0 additions & 8 deletions scripts/hooks/pre-push.txt

This file was deleted.

3 changes: 2 additions & 1 deletion source/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"start:all": "lerna run --parallel watch && lerna run --parallel start",
"audit-all": "lerna-audit",
"format": "clang-format-launcher --verbose",
"verify": "clang-format-launcher -verify --verbose"
"verify": "clang-format-launcher -verify --verbose",
"prepare": "cd ../.. && husky install source/nodejs/.husky"
},
"devDependencies": {
"@types/jest": "^27.0.2",
Expand Down
8 changes: 4 additions & 4 deletions source/shared/cpp/ObjectModel/jsoncpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ license you like.
// End of content of file: LICENSE
// //////////////////////////////////////////////////////////////////////

// clang-format off

#include "pch.h"

#ifdef USE_CPPCORECHECK
Expand Down Expand Up @@ -3315,13 +3317,11 @@ double Value::asDouble() const {
case intValue:
return static_cast<double>(value_.int_);
case uintValue:
// clang-format off
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
return static_cast<double>(value_.uint_);
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
return integerToDouble(value_.uint_);
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
// clang-format on
case realValue:
return value_.real_;
case nullValue:
Expand All @@ -3339,14 +3339,12 @@ float Value::asFloat() const {
case intValue:
return static_cast<float>(value_.int_);
case uintValue:
// clang-format off
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
return static_cast<float>(value_.uint_);
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
// This can fail (silently?) if the value is bigger than MAX_FLOAT.
return static_cast<float>(integerToDouble(value_.uint_));
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
// clang-format on
case realValue:
return static_cast<float>(value_.real_);
case nullValue:
Expand Down Expand Up @@ -5398,3 +5396,5 @@ JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM& sout, Value const& root) {
#ifdef USE_CPPCORECHECK
#pragma warning(pop)
#endif

// clang-format on
4 changes: 2 additions & 2 deletions source/uwp/Renderer/lib/ElementTagContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace AdaptiveCards::Rendering::Uwp
{
// clang-format off
// clang-format off
interface __declspec(uuid("0331D653-957C-4385-A327-D326750C10B6")) IElementTagContent : IInspectable
{
public:
Expand All @@ -22,7 +22,7 @@ namespace AdaptiveCards::Rendering::Uwp
virtual HRESULT get_IsStretchable(_Outptr_ boolean * isStretchable) = 0;
virtual HRESULT put_IsStretchable(boolean isStretchable) = 0;
};
// clang-format on
// clang-format on

class ElementTagContent
: public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::WinRtClassicComMix>, IElementTagContent>
Expand Down