Skip to content

Commit abaa636

Browse files
authored
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
1 parent 64149e7 commit abaa636

File tree

6 files changed

+45
-21
lines changed

6 files changed

+45
-21
lines changed

.github/workflows/fmt.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Format Code
2+
3+
on: [pull_request, workflow_dispatch]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v2
11+
- run: go fmt
12+
- name: go generate (clang-format)
13+
run: go generate
14+
- name: Display missing format changes
15+
run: git diff --exit-code

isolate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func TestIsolateCompileUnboundScript_InvalidOptions(t *testing.T) {
132132

133133
opts := v8.CompileOptions{
134134
CachedData: &v8.CompilerCachedData{Bytes: []byte("unused")},
135-
Mode: v8.CompileModeEager,
135+
Mode: v8.CompileModeEager,
136136
}
137137
panicErr := recoverPanic(func() { iso.CompileUnboundScript("console.log(1)", "script.js", opts) })
138138
if panicErr == nil {

leak_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
package v8go_test
99

1010
import (
11-
"testing"
1211
"os"
12+
"testing"
1313

1414
"rogchap.com/v8go"
1515
)

script_compiler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type CompileMode C.int
1111

1212
var (
1313
CompileModeDefault = CompileMode(C.ScriptCompilerNoCompileOptions)
14-
CompileModeEager = CompileMode(C.ScriptCompilerEagerCompile)
14+
CompileModeEager = CompileMode(C.ScriptCompilerEagerCompile)
1515
)
1616

1717
type CompilerCachedData struct {

v8go.cc

+18-10
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ IsolateHStatistics IsolationGetHeapStatistics(IsolatePtr iso) {
217217
hs.number_of_detached_contexts()};
218218
}
219219

220-
RtnUnboundScript IsolateCompileUnboundScript(IsolatePtr iso, const char* s, const char* o, CompileOptions opts) {
220+
RtnUnboundScript IsolateCompileUnboundScript(IsolatePtr iso,
221+
const char* s,
222+
const char* o,
223+
CompileOptions opts) {
221224
ISOLATE_SCOPE_INTERNAL_CONTEXT(iso);
222225
TryCatch try_catch(iso);
223226
Local<Context> local_ctx = ctx->ptr.Get(iso);
@@ -230,20 +233,23 @@ RtnUnboundScript IsolateCompileUnboundScript(IsolatePtr iso, const char* s, cons
230233
Local<String> ogn =
231234
String::NewFromUtf8(iso, o, NewStringType::kNormal).ToLocalChecked();
232235

233-
ScriptCompiler::CompileOptions option = static_cast<ScriptCompiler::CompileOptions>(opts.compileOption);
236+
ScriptCompiler::CompileOptions option =
237+
static_cast<ScriptCompiler::CompileOptions>(opts.compileOption);
234238

235239
ScriptCompiler::CachedData* cached_data = nullptr;
236240

237241
if (opts.cachedData.data) {
238-
cached_data = new ScriptCompiler::CachedData(opts.cachedData.data, opts.cachedData.length);
242+
cached_data = new ScriptCompiler::CachedData(opts.cachedData.data,
243+
opts.cachedData.length);
239244
}
240245

241246
ScriptOrigin script_origin(ogn);
242247

243248
ScriptCompiler::Source source(src, script_origin, cached_data);
244249

245250
Local<UnboundScript> unbound_script;
246-
if (!ScriptCompiler::CompileUnboundScript(iso, &source, option).ToLocal(&unbound_script)) {
251+
if (!ScriptCompiler::CompileUnboundScript(iso, &source, option)
252+
.ToLocal(&unbound_script)) {
247253
rtn.error = ExceptionError(try_catch, iso, local_ctx);
248254
return rtn;
249255
};
@@ -269,8 +275,8 @@ ValuePtr IsolateThrowException(IsolatePtr iso, ValuePtr value) {
269275
m_value* new_val = new m_value;
270276
new_val->iso = iso;
271277
new_val->ctx = ctx;
272-
new_val->ptr = Persistent<Value, CopyablePersistentTraits<Value>>(
273-
iso, throw_ret_val);
278+
new_val->ptr =
279+
Persistent<Value, CopyablePersistentTraits<Value>>(iso, throw_ret_val);
274280

275281
return tracked_value(ctx, new_val);
276282
}
@@ -454,8 +460,7 @@ RtnValue ObjectTemplateNewInstance(TemplatePtr ptr, ContextPtr ctx) {
454460
return rtn;
455461
}
456462

457-
void ObjectTemplateSetInternalFieldCount(TemplatePtr ptr,
458-
int field_count) {
463+
void ObjectTemplateSetInternalFieldCount(TemplatePtr ptr, int field_count) {
459464
LOCAL_TEMPLATE(ptr);
460465

461466
Local<ObjectTemplate> obj_tmpl = tmpl.As<ObjectTemplate>();
@@ -647,12 +652,15 @@ RtnValue RunScript(ContextPtr ctx, const char* source, const char* origin) {
647652

648653
/********** UnboundScript & ScriptCompilerCachedData **********/
649654

650-
ScriptCompilerCachedData* UnboundScriptCreateCodeCache(IsolatePtr iso, UnboundScriptPtr us_ptr) {
655+
ScriptCompilerCachedData* UnboundScriptCreateCodeCache(
656+
IsolatePtr iso,
657+
UnboundScriptPtr us_ptr) {
651658
ISOLATE_SCOPE(iso);
652659

653660
Local<UnboundScript> unbound_script = us_ptr->ptr.Get(iso);
654661

655-
ScriptCompiler::CachedData* cached_data = ScriptCompiler::CreateCodeCache(unbound_script);
662+
ScriptCompiler::CachedData* cached_data =
663+
ScriptCompiler::CreateCodeCache(unbound_script);
656664

657665
ScriptCompilerCachedData* cd = new ScriptCompilerCachedData;
658666
cd->ptr = cached_data;

v8go.h

+9-8
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,15 @@ extern IsolateHStatistics IsolationGetHeapStatistics(IsolatePtr ptr);
146146
extern ValuePtr IsolateThrowException(IsolatePtr iso, ValuePtr value);
147147

148148
extern RtnUnboundScript IsolateCompileUnboundScript(IsolatePtr iso_ptr,
149-
const char* source,
150-
const char* origin,
151-
CompileOptions options);
152-
extern ScriptCompilerCachedData* UnboundScriptCreateCodeCache(IsolatePtr iso_ptr,
153-
UnboundScriptPtr us_ptr);
154-
extern void ScriptCompilerCachedDataDelete(ScriptCompilerCachedData* cached_data);
155-
extern RtnValue UnboundScriptRun(ContextPtr ctx_ptr,
156-
UnboundScriptPtr us_ptr);
149+
const char* source,
150+
const char* origin,
151+
CompileOptions options);
152+
extern ScriptCompilerCachedData* UnboundScriptCreateCodeCache(
153+
IsolatePtr iso_ptr,
154+
UnboundScriptPtr us_ptr);
155+
extern void ScriptCompilerCachedDataDelete(
156+
ScriptCompilerCachedData* cached_data);
157+
extern RtnValue UnboundScriptRun(ContextPtr ctx_ptr, UnboundScriptPtr us_ptr);
157158

158159
extern CPUProfiler* NewCPUProfiler(IsolatePtr iso_ptr);
159160
extern void CPUProfilerDispose(CPUProfiler* ptr);

0 commit comments

Comments
 (0)