GeezerVison is showing github.com — add clang-format hook (#167) · nodejs/node-addon-examples@c1bdff0
File treeExpand file treeCollapse file tree Open diff view settings function-reference-demo/node-addon-api/src inherits_from_event_emitter/node-addon-api/src napi-asyncworker-example/node-addon-api/src object-wrap-demo/node-addon-api/src thread_safe_function_counting/node-addon-api typescript_with_addon/node-addon-api
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +111Lines changed: 111 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +Language: Cpp | | 3 | +# BasedOnStyle: Google | | 4 | +AccessModifierOffset: -1 | | 5 | +AlignAfterOpenBracket: Align | | 6 | +AlignConsecutiveAssignments: false | | 7 | +AlignConsecutiveDeclarations: false | | 8 | +AlignEscapedNewlines: Right | | 9 | +AlignOperands: true | | 10 | +AlignTrailingComments: true | | 11 | +AllowAllParametersOfDeclarationOnNextLine: true | | 12 | +AllowShortBlocksOnASingleLine: false | | 13 | +AllowShortCaseLabelsOnASingleLine: false | | 14 | +AllowShortFunctionsOnASingleLine: Inline | | 15 | +AllowShortIfStatementsOnASingleLine: true | | 16 | +AllowShortLoopsOnASingleLine: true | | 17 | +AlwaysBreakAfterDefinitionReturnType: None | | 18 | +AlwaysBreakAfterReturnType: None | | 19 | +AlwaysBreakBeforeMultilineStrings: false | | 20 | +AlwaysBreakTemplateDeclarations: true | | 21 | +BinPackArguments: false | | 22 | +BinPackParameters: false | | 23 | +BraceWrapping: | | 24 | + AfterClass: false | | 25 | + AfterControlStatement: false | | 26 | + AfterEnum: false | | 27 | + AfterFunction: false | | 28 | + AfterNamespace: false | | 29 | + AfterObjCDeclaration: false | | 30 | + AfterStruct: false | | 31 | + AfterUnion: false | | 32 | + AfterExternBlock: false | | 33 | + BeforeCatch: false | | 34 | + BeforeElse: false | | 35 | + IndentBraces: false | | 36 | + SplitEmptyFunction: true | | 37 | + SplitEmptyRecord: true | | 38 | + SplitEmptyNamespace: true | | 39 | +BreakBeforeBinaryOperators: None | | 40 | +BreakBeforeBraces: Attach | | 41 | +BreakBeforeInheritanceComma: false | | 42 | +BreakBeforeTernaryOperators: true | | 43 | +BreakConstructorInitializersBeforeComma: false | | 44 | +BreakConstructorInitializers: BeforeColon | | 45 | +BreakAfterJavaFieldAnnotations: false | | 46 | +BreakStringLiterals: true | | 47 | +ColumnLimit: 80 | | 48 | +CommentPragmas: '^ IWYU pragma:' | | 49 | +CompactNamespaces: false | | 50 | +ConstructorInitializerAllOnOneLineOrOnePerLine: true | | 51 | +ConstructorInitializerIndentWidth: 4 | | 52 | +ContinuationIndentWidth: 4 | | 53 | +Cpp11BracedListStyle: true | | 54 | +DerivePointerAlignment: false | | 55 | +DisableFormat: false | | 56 | +ExperimentalAutoDetectBinPacking: false | | 57 | +FixNamespaceComments: true | | 58 | +ForEachMacros: | | 59 | + - foreach | | 60 | + - Q_FOREACH | | 61 | + - BOOST_FOREACH | | 62 | +IncludeBlocks: Preserve | | 63 | +IncludeCategories: | | 64 | + - Regex: '^<ext/.*\.h>' | | 65 | + Priority: 2 | | 66 | + - Regex: '^<.*\.h>' | | 67 | + Priority: 1 | | 68 | + - Regex: '^<.*' | | 69 | + Priority: 2 | | 70 | + - Regex: '.*' | | 71 | + Priority: 3 | | 72 | +IncludeIsMainRegex: '([-_](test|unittest))?$' | | 73 | +IndentCaseLabels: true | | 74 | +IndentPPDirectives: None | | 75 | +IndentWidth: 2 | | 76 | +IndentWrappedFunctionNames: false | | 77 | +JavaScriptQuotes: Leave | | 78 | +JavaScriptWrapImports: true | | 79 | +KeepEmptyLinesAtTheStartOfBlocks: false | | 80 | +MacroBlockBegin: '' | | 81 | +MacroBlockEnd: '' | | 82 | +MaxEmptyLinesToKeep: 1 | | 83 | +NamespaceIndentation: None | | 84 | +ObjCBlockIndentWidth: 2 | | 85 | +ObjCSpaceAfterProperty: false | | 86 | +ObjCSpaceBeforeProtocolList: false | | 87 | +PenaltyBreakAssignment: 2 | | 88 | +PenaltyBreakBeforeFirstCallParameter: 1 | | 89 | +PenaltyBreakComment: 300 | | 90 | +PenaltyBreakFirstLessLess: 120 | | 91 | +PenaltyBreakString: 1000 | | 92 | +PenaltyExcessCharacter: 1000000 | | 93 | +PenaltyReturnTypeOnItsOwnLine: 200 | | 94 | +PointerAlignment: Left | | 95 | +ReflowComments: true | | 96 | +SortIncludes: true | | 97 | +SortUsingDeclarations: true | | 98 | +SpaceAfterCStyleCast: false | | 99 | +SpaceAfterTemplateKeyword: true | | 100 | +SpaceBeforeAssignmentOperators: true | | 101 | +SpaceBeforeParens: ControlStatements | | 102 | +SpaceInEmptyParentheses: false | | 103 | +SpacesBeforeTrailingComments: 2 | | 104 | +SpacesInAngles: false | | 105 | +SpacesInContainerLiterals: true | | 106 | +SpacesInCStyleCastParentheses: false | | 107 | +SpacesInParentheses: false | | 108 | +SpacesInSquareBrackets: false | | 109 | +Standard: Auto | | 110 | +TabWidth: 8 | | 111 | +UseTab: Never |
Collapse file Copy file name to clipboard +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +name: clang-format | | 2 | + | | 3 | +on: [push, pull_request] | | 4 | + | | 5 | +jobs: | | 6 | + check-clang-format: | | 7 | + runs-on: ubuntu-latest | | 8 | + steps: | | 9 | + - uses: actions/checkout@v2 | | 10 | + - run: npm install | | 11 | + - name: check clang-format | | 12 | + run: | | | 13 | + git config clangFormat.binary node_modules/.bin/clang-format | | 14 | + git config clangFormat.style file | | 15 | + npx check-clang-format |
Collapse file Copy file name to clipboardExpand all lines: 6_object_wrap/napi/myobject.cc +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -44,13 +44,16 @@ napi_value MyObject::Init(napi_env env, napi_value exports) { | 44 | 44 | napi_ref* constructor = new napi_ref; | 45 | 45 | status = napi_create_reference(env, cons, 1, constructor); | 46 | 46 | assert(status == napi_ok); | 47 | | - status = napi_set_instance_data(env, constructor, | | 47 | + status = napi_set_instance_data( | | 48 | + env, | | 49 | + constructor, | 48 | 50 | [](napi_env env, void* data, void* hint) { | 49 | 51 | napi_ref* constructor = static_cast<napi_ref*>(data); | 50 | 52 | napi_status status = napi_delete_reference(env, *constructor); | 51 | 53 | assert(status == napi_ok); | 52 | 54 | delete constructor; | 53 | | - }, nullptr); | | 55 | + }, | | 56 | + nullptr); | 54 | 57 | assert(status == napi_ok); | 55 | 58 |
| 56 | 59 | status = napi_set_named_property(env, exports, "MyObject", cons); | |
Collapse file Copy file name to clipboardExpand all lines: 6_object_wrap/node-addon-api/myobject.cc -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #include "myobject.h" | 2 | 2 |
| 3 | 3 | Napi::Object MyObject::Init(Napi::Env env, Napi::Object exports) { | 4 | | - | 5 | 4 | Napi::Function func = | 6 | 5 | DefineClass(env, | 7 | 6 | "MyObject", | |
Collapse file Copy file name to clipboardExpand all lines: 7_factory_wrap/napi/myobject.cc +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,13 +41,16 @@ napi_status MyObject::Init(napi_env env) { | 41 | 41 | napi_ref* constructor = new napi_ref; | 42 | 42 | status = napi_create_reference(env, cons, 1, constructor); | 43 | 43 | assert(status == napi_ok); | 44 | | - status = napi_set_instance_data(env, constructor, | | 44 | + status = napi_set_instance_data( | | 45 | + env, | | 46 | + constructor, | 45 | 47 | [](napi_env env, void* data, void* hint) { | 46 | 48 | napi_ref* constructor = static_cast<napi_ref*>(data); | 47 | 49 | napi_status status = napi_delete_reference(env, *constructor); | 48 | 50 | assert(status == napi_ok); | 49 | 51 | delete constructor; | 50 | | - }, nullptr); | | 52 | + }, | | 53 | + nullptr); | 51 | 54 | assert(status == napi_ok); | 52 | 55 |
| 53 | 56 | return napi_ok; | |
Collapse file Copy file name to clipboardExpand all lines: 7_factory_wrap/node-addon-api/myobject.cc -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | using namespace Napi; | 6 | 6 |
| 7 | 7 | Napi::Object MyObject::Init(Napi::Env env, Napi::Object exports) { | 8 | | - | 9 | 8 | Napi::Function func = DefineClass( | 10 | 9 | env, "MyObject", {InstanceMethod("plusOne", &MyObject::PlusOne)}); | 11 | 10 |
| @@ -19,7 +18,6 @@ Napi::Object MyObject::Init(Napi::Env env, Napi::Object exports) { | 19 | 18 |
| 20 | 19 | MyObject::MyObject(const Napi::CallbackInfo& info) | 21 | 20 | : Napi::ObjectWrap<MyObject>(info) { | 22 | | - | 23 | 21 | this->counter_ = info[0].As<Napi::Number>().DoubleValue(); | 24 | 22 | }; | 25 | 23 |
| |
Collapse file Copy file name to clipboardExpand all lines: 8_passing_wrapped/napi/myobject.cc +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -35,13 +35,16 @@ napi_status MyObject::Init(napi_env env) { | 35 | 35 | napi_ref* constructor = new napi_ref; | 36 | 36 | status = napi_create_reference(env, cons, 1, constructor); | 37 | 37 | assert(status == napi_ok); | 38 | | - status = napi_set_instance_data(env, constructor, | | 38 | + status = napi_set_instance_data( | | 39 | + env, | | 40 | + constructor, | 39 | 41 | [](napi_env env, void* data, void* hint) { | 40 | 42 | napi_ref* constructor = static_cast<napi_ref*>(data); | 41 | 43 | napi_status status = napi_delete_reference(env, *constructor); | 42 | 44 | assert(status == napi_ok); | 43 | 45 | delete constructor; | 44 | | - }, nullptr); | | 46 | + }, | | 47 | + nullptr); | 45 | 48 | assert(status == napi_ok); | 46 | 49 |
| 47 | 50 | return napi_ok; | |
Collapse file Copy file name to clipboardExpand all lines: 8_passing_wrapped/node-addon-api/myobject.cc -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 |
| 5 | 5 | MyObject::MyObject(const Napi::CallbackInfo& info) | 6 | 6 | : Napi::ObjectWrap<MyObject>(info) { | 7 | | - | 8 | 7 | this->val_ = info[0].As<Napi::Number>().DoubleValue(); | 9 | 8 | }; | 10 | 9 |
| 11 | 10 | void MyObject::Init(Napi::Env env, Napi::Object exports) { | 12 | | - | 13 | 11 | Napi::Function func = DefineClass(env, "MyObject", {}); | 14 | 12 |
| 15 | 13 | Napi::FunctionReference* constructor = new Napi::FunctionReference(); | |
Collapse file Copy file name to clipboardExpand all lines: function-reference-demo/node-addon-api/src/binding.cc +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | #include "native-addon.h" | 3 | 3 |
| 4 | 4 | Napi::Object Init(Napi::Env env, Napi::Object exports) { | 5 | | - NativeAddon::Init(env, exports); | 6 | | - return exports; | | 5 | + NativeAddon::Init(env, exports); | | 6 | + return exports; | 7 | 7 | } | 8 | 8 |
| 9 | 9 | NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init) |
Collapse file Copy file name to clipboardExpand all lines: function-reference-demo/node-addon-api/src/native-addon.cc +13-11Lines changed: 13 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | Napi::FunctionReference NativeAddon::constructor; | 5 | 5 |
| 6 | 6 | Napi::Object NativeAddon::Init(Napi::Env env, Napi::Object exports) { | 7 | | - | 8 | | - Napi::Function func = DefineClass(env, "NativeAddon", { | 9 | | - InstanceMethod("tryCallByStoredReference", &NativeAddon::TryCallByStoredReference), | 10 | | - InstanceMethod("tryCallByStoredFunction", &NativeAddon::TryCallByStoredFunction) | 11 | | - }); | | 7 | + Napi::Function func = | | 8 | + DefineClass(env, | | 9 | + "NativeAddon", | | 10 | + {InstanceMethod("tryCallByStoredReference", | | 11 | + &NativeAddon::TryCallByStoredReference), | | 12 | + InstanceMethod("tryCallByStoredFunction", | | 13 | + &NativeAddon::TryCallByStoredFunction)}); | 12 | 14 |
| 13 | 15 | constructor = Napi::Persistent(func); | 14 | 16 | constructor.SuppressDestruct(); | @@ -17,18 +19,18 @@ Napi::Object NativeAddon::Init(Napi::Env env, Napi::Object exports) { | 17 | 19 | return exports; | 18 | 20 | } | 19 | 21 |
| 20 | | -NativeAddon::NativeAddon(const Napi::CallbackInfo& info) | 21 | | -: Napi::ObjectWrap<NativeAddon>(info) { | | 22 | +NativeAddon::NativeAddon(const Napi::CallbackInfo& info) | | 23 | + : Napi::ObjectWrap<NativeAddon>(info) { | 22 | 24 | jsFnRef = Napi::Persistent(info[0].As<Napi::Function>()); | 23 | 25 | jsFn = info[1].As<Napi::Function>(); | 24 | 26 | } | 25 | 27 |
| 26 | 28 | void NativeAddon::TryCallByStoredReference(const Napi::CallbackInfo& info) { | 27 | | - // Napi::Env env = info.Env(); | 28 | | - jsFnRef.Call({}); | | 29 | + // Napi::Env env = info.Env(); | | 30 | + jsFnRef.Call({}); | 29 | 31 | } | 30 | 32 |
| 31 | 33 | void NativeAddon::TryCallByStoredFunction(const Napi::CallbackInfo& info) { | 32 | | - // Napi::Env env = info.Env(); | 33 | | - jsFn.Call({}); | | 34 | + // Napi::Env env = info.Env(); | | 35 | + jsFn.Call({}); | 34 | 36 | } |
|