From abaa636d50469b70e91d01a050d5f9ee99deddca Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Thu, 18 Nov 2021 07:26:48 -0500 Subject: [PATCH] CI: Run gofmt and clang-format automatically on pull requests (#233) * go fmt * clang-format * CI: Run gofmt and clang-format automatically on pull requests --- .github/workflows/fmt.yml | 15 +++++++++++++++ isolate_test.go | 2 +- leak_test.go | 2 +- script_compiler.go | 2 +- v8go.cc | 28 ++++++++++++++++++---------- v8go.h | 17 +++++++++-------- 6 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/fmt.yml diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml new file mode 100644 index 00000000..aed5aa3f --- /dev/null +++ b/.github/workflows/fmt.yml @@ -0,0 +1,15 @@ +name: Format Code + +on: [pull_request, workflow_dispatch] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - run: go fmt + - name: go generate (clang-format) + run: go generate + - name: Display missing format changes + run: git diff --exit-code diff --git a/isolate_test.go b/isolate_test.go index a912276f..c06f4397 100644 --- a/isolate_test.go +++ b/isolate_test.go @@ -132,7 +132,7 @@ func TestIsolateCompileUnboundScript_InvalidOptions(t *testing.T) { opts := v8.CompileOptions{ CachedData: &v8.CompilerCachedData{Bytes: []byte("unused")}, - Mode: v8.CompileModeEager, + Mode: v8.CompileModeEager, } panicErr := recoverPanic(func() { iso.CompileUnboundScript("console.log(1)", "script.js", opts) }) if panicErr == nil { diff --git a/leak_test.go b/leak_test.go index a0e2bdb1..f58e0c6f 100644 --- a/leak_test.go +++ b/leak_test.go @@ -8,8 +8,8 @@ package v8go_test import ( - "testing" "os" + "testing" "rogchap.com/v8go" ) diff --git a/script_compiler.go b/script_compiler.go index 337bf568..ecbf8abc 100644 --- a/script_compiler.go +++ b/script_compiler.go @@ -11,7 +11,7 @@ type CompileMode C.int var ( CompileModeDefault = CompileMode(C.ScriptCompilerNoCompileOptions) - CompileModeEager = CompileMode(C.ScriptCompilerEagerCompile) + CompileModeEager = CompileMode(C.ScriptCompilerEagerCompile) ) type CompilerCachedData struct { diff --git a/v8go.cc b/v8go.cc index bd47588f..7c682d0d 100644 --- a/v8go.cc +++ b/v8go.cc @@ -217,7 +217,10 @@ IsolateHStatistics IsolationGetHeapStatistics(IsolatePtr iso) { hs.number_of_detached_contexts()}; } -RtnUnboundScript IsolateCompileUnboundScript(IsolatePtr iso, const char* s, const char* o, CompileOptions opts) { +RtnUnboundScript IsolateCompileUnboundScript(IsolatePtr iso, + const char* s, + const char* o, + CompileOptions opts) { ISOLATE_SCOPE_INTERNAL_CONTEXT(iso); TryCatch try_catch(iso); Local local_ctx = ctx->ptr.Get(iso); @@ -230,12 +233,14 @@ RtnUnboundScript IsolateCompileUnboundScript(IsolatePtr iso, const char* s, cons Local ogn = String::NewFromUtf8(iso, o, NewStringType::kNormal).ToLocalChecked(); - ScriptCompiler::CompileOptions option = static_cast(opts.compileOption); + ScriptCompiler::CompileOptions option = + static_cast(opts.compileOption); ScriptCompiler::CachedData* cached_data = nullptr; if (opts.cachedData.data) { - cached_data = new ScriptCompiler::CachedData(opts.cachedData.data, opts.cachedData.length); + cached_data = new ScriptCompiler::CachedData(opts.cachedData.data, + opts.cachedData.length); } ScriptOrigin script_origin(ogn); @@ -243,7 +248,8 @@ RtnUnboundScript IsolateCompileUnboundScript(IsolatePtr iso, const char* s, cons ScriptCompiler::Source source(src, script_origin, cached_data); Local unbound_script; - if (!ScriptCompiler::CompileUnboundScript(iso, &source, option).ToLocal(&unbound_script)) { + if (!ScriptCompiler::CompileUnboundScript(iso, &source, option) + .ToLocal(&unbound_script)) { rtn.error = ExceptionError(try_catch, iso, local_ctx); return rtn; }; @@ -269,8 +275,8 @@ ValuePtr IsolateThrowException(IsolatePtr iso, ValuePtr value) { m_value* new_val = new m_value; new_val->iso = iso; new_val->ctx = ctx; - new_val->ptr = Persistent>( - iso, throw_ret_val); + new_val->ptr = + Persistent>(iso, throw_ret_val); return tracked_value(ctx, new_val); } @@ -454,8 +460,7 @@ RtnValue ObjectTemplateNewInstance(TemplatePtr ptr, ContextPtr ctx) { return rtn; } -void ObjectTemplateSetInternalFieldCount(TemplatePtr ptr, - int field_count) { +void ObjectTemplateSetInternalFieldCount(TemplatePtr ptr, int field_count) { LOCAL_TEMPLATE(ptr); Local obj_tmpl = tmpl.As(); @@ -647,12 +652,15 @@ RtnValue RunScript(ContextPtr ctx, const char* source, const char* origin) { /********** UnboundScript & ScriptCompilerCachedData **********/ -ScriptCompilerCachedData* UnboundScriptCreateCodeCache(IsolatePtr iso, UnboundScriptPtr us_ptr) { +ScriptCompilerCachedData* UnboundScriptCreateCodeCache( + IsolatePtr iso, + UnboundScriptPtr us_ptr) { ISOLATE_SCOPE(iso); Local unbound_script = us_ptr->ptr.Get(iso); - ScriptCompiler::CachedData* cached_data = ScriptCompiler::CreateCodeCache(unbound_script); + ScriptCompiler::CachedData* cached_data = + ScriptCompiler::CreateCodeCache(unbound_script); ScriptCompilerCachedData* cd = new ScriptCompilerCachedData; cd->ptr = cached_data; diff --git a/v8go.h b/v8go.h index 787a7328..591b5472 100644 --- a/v8go.h +++ b/v8go.h @@ -146,14 +146,15 @@ extern IsolateHStatistics IsolationGetHeapStatistics(IsolatePtr ptr); extern ValuePtr IsolateThrowException(IsolatePtr iso, ValuePtr value); extern RtnUnboundScript IsolateCompileUnboundScript(IsolatePtr iso_ptr, - const char* source, - const char* origin, - CompileOptions options); -extern ScriptCompilerCachedData* UnboundScriptCreateCodeCache(IsolatePtr iso_ptr, - UnboundScriptPtr us_ptr); -extern void ScriptCompilerCachedDataDelete(ScriptCompilerCachedData* cached_data); -extern RtnValue UnboundScriptRun(ContextPtr ctx_ptr, - UnboundScriptPtr us_ptr); + const char* source, + const char* origin, + CompileOptions options); +extern ScriptCompilerCachedData* UnboundScriptCreateCodeCache( + IsolatePtr iso_ptr, + UnboundScriptPtr us_ptr); +extern void ScriptCompilerCachedDataDelete( + ScriptCompilerCachedData* cached_data); +extern RtnValue UnboundScriptRun(ContextPtr ctx_ptr, UnboundScriptPtr us_ptr); extern CPUProfiler* NewCPUProfiler(IsolatePtr iso_ptr); extern void CPUProfilerDispose(CPUProfiler* ptr);