Skip to content

Commit d5161be

Browse files
authored
chore(core): Run clippy/fmt from npm's lint/format (#980)
1 parent a0375f5 commit d5161be

File tree

9 files changed

+66
-42
lines changed

9 files changed

+66
-42
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ jobs:
116116
- uses: actions/setup-node@v1
117117
with:
118118
node-version: 16
119+
- name: Install protoc
120+
uses: arduino/setup-protoc@v1
121+
with:
122+
version: '3.x'
123+
repo-token: ${{ secrets.GITHUB_TOKEN }}
124+
- uses: Swatinem/rust-cache@v1
125+
with:
126+
working-directory: packages/core-bridge
119127
- run: npm ci --ignore-scripts
120128
# eslint-import-resolver-typescript requires packages to be built
121129
- name: Compile all non-rust code

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
"ci-stress": "node ./packages/test/lib/load/run-all-stress-ci-scenarios.js",
3030
"ci-nightly": "node ./packages/test/lib/load/run-all-nightly-scenarios.js",
3131
"wait-namespace": "node ./scripts/wait-on-temporal.mjs",
32-
"lint": "eslint packages/*/src --ext .ts --no-error-on-unmatched-pattern --fix && prettier --write .",
33-
"lint.check": "eslint packages/*/src --ext .ts --no-error-on-unmatched-pattern && prettier --end-of-line auto --check .",
32+
"lint": "eslint packages/*/src --ext .ts --no-error-on-unmatched-pattern --fix && prettier --write . && lerna run --no-bail --stream lint",
33+
"lint.check": "eslint packages/*/src --ext .ts --no-error-on-unmatched-pattern && prettier --end-of-line auto --check . && lerna run --no-bail --stream lint.check",
3434
"lint.prune": "ts-prune --error -p tsconfig.prune.json --ignore \"used in module\" --skip \".d.ts\"",
35-
"format": "prettier --write .",
35+
"format": "prettier --write . && lerna run --no-bail --stream format",
3636
"clean": "node ./scripts/clean.mjs",
3737
"docs": "lerna run --stream maybe-install-deps-and-build-docs"
3838
},

packages/core-bridge/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"build-rust": "node ./scripts/build.js --force",
99
"build": "npm run build-rust",
1010
"build-rust-release": "npm run build-rust -- --release",
11-
"install": "node ./scripts/build.js"
11+
"install": "node ./scripts/build.js",
12+
"format": "cargo fmt",
13+
"lint": "cargo clippy --fix",
14+
"lint.check": "cargo clippy"
1215
},
1316
"keywords": [
1417
"temporal",

packages/core-bridge/src/conversions.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,11 @@ impl ObjectHandleConversionsExt for Handle<'_, JsObject> {
237237
"metricPeriodicity",
238238
JsNumber
239239
) as u64));
240-
telemetry_opts
241-
.metrics(MetricsExporter::Otel(OtelCollectorOptions { url, headers, metric_periodicity }));
240+
telemetry_opts.metrics(MetricsExporter::Otel(OtelCollectorOptions {
241+
url,
242+
headers,
243+
metric_periodicity,
244+
}));
242245
} else {
243246
cx.throw_type_error(
244247
"Invalid telemetryOptions.metrics, missing `prometheus` or `otel` option",
@@ -262,12 +265,14 @@ impl ObjectHandleConversionsExt for Handle<'_, JsObject> {
262265
};
263266
telemetry_opts.tracing(TraceExportConfig {
264267
filter,
265-
exporter: TraceExporter::Otel(OtelCollectorOptions { url, headers, metric_periodicity: None }),
268+
exporter: TraceExporter::Otel(OtelCollectorOptions {
269+
url,
270+
headers,
271+
metric_periodicity: None,
272+
}),
266273
});
267274
} else {
268-
cx.throw_type_error(
269-
"Invalid telemetryOptions.tracing, missing `otel` option",
270-
)?
275+
cx.throw_type_error("Invalid telemetryOptions.tracing, missing `otel` option")?
271276
}
272277
}
273278

packages/core-bridge/src/errors.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ pub trait CustomError {
2020
where
2121
C: Context<'a>;
2222

23-
fn from_string<'a, C>(&self, cx: &mut C, message: impl Into<String>) -> JsResult<'a, JsObject>
23+
fn construct_from_string<'a, C>(&self, cx: &mut C, message: impl Into<String>) -> JsResult<'a, JsObject>
2424
where
2525
C: Context<'a>;
2626

27-
fn from_error<'a, C, E>(&self, cx: &mut C, err: E) -> JsResult<'a, JsObject>
27+
fn construct_from_error<'a, C, E>(&self, cx: &mut C, err: E) -> JsResult<'a, JsObject>
2828
where
2929
C: Context<'a>,
3030
E: std::error::Error;
@@ -46,20 +46,20 @@ impl CustomError for OnceCell<Root<JsFunction>> {
4646
error.construct(cx, args)
4747
}
4848

49-
fn from_string<'a, C>(&self, cx: &mut C, message: impl Into<String>) -> JsResult<'a, JsObject>
49+
fn construct_from_string<'a, C>(&self, cx: &mut C, message: impl Into<String>) -> JsResult<'a, JsObject>
5050
where
5151
C: Context<'a>,
5252
{
5353
let args = vec![cx.string(message.into()).upcast()];
5454
self.construct(cx, args)
5555
}
5656

57-
fn from_error<'a, C, E>(&self, cx: &mut C, err: E) -> JsResult<'a, JsObject>
57+
fn construct_from_error<'a, C, E>(&self, cx: &mut C, err: E) -> JsResult<'a, JsObject>
5858
where
5959
C: Context<'a>,
6060
E: std::error::Error,
6161
{
62-
self.from_string(cx, format!("{:?}", err))
62+
self.construct_from_string(cx, format!("{:?}", err))
6363
}
6464
}
6565

packages/core-bridge/src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ where
6262
{
6363
let err_str = format!("{}", err);
6464
callback_with_error(cx, callback, move |cx| {
65-
UNEXPECTED_ERROR.from_string(cx, err_str)
65+
UNEXPECTED_ERROR.construct_from_string(cx, err_str)
6666
})
6767
}
6868

packages/core-bridge/src/runtime.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ pub fn start_bridge_loop(
155155
Err(err) => {
156156
send_error(channel.clone(), callback, |cx| match err {
157157
ClientInitError::SystemInfoCallError(e) => TRANSPORT_ERROR
158-
.from_string(
158+
.construct_from_string(
159159
cx,
160160
format!("Failed to call GetSystemInfo: {}", e),
161161
),
162162
ClientInitError::TonicTransportError(e) => {
163-
TRANSPORT_ERROR.from_error(cx, e)
163+
TRANSPORT_ERROR.construct_from_error(cx, e)
164164
}
165165
ClientInitError::InvalidUri(e) => {
166166
Ok(JsError::type_error(cx, format!("{}", e))?.upcast())
@@ -214,13 +214,17 @@ pub fn start_bridge_loop(
214214
match init_worker(&core_runtime, config, client.into_inner()) {
215215
Ok(worker) => {
216216
let (tx, rx) = unbounded_channel();
217-
core_runtime.tokio_handle().spawn(start_worker_loop(worker, rx, channel.clone()));
217+
core_runtime.tokio_handle().spawn(start_worker_loop(
218+
worker,
219+
rx,
220+
channel.clone(),
221+
));
218222
send_result(channel.clone(), callback, |cx| {
219223
Ok(cx.boxed(RefCell::new(Some(WorkerHandle { sender: tx }))))
220224
});
221225
}
222226
Err(err) => send_error(channel.clone(), callback, move |cx| {
223-
UNEXPECTED_ERROR.from_error(cx, err.deref())
227+
UNEXPECTED_ERROR.construct_from_error(cx, err.deref())
224228
}),
225229
}
226230
}
@@ -233,7 +237,11 @@ pub fn start_bridge_loop(
233237
match init_replay_worker(config, Box::pin(stream)) {
234238
Ok(worker) => {
235239
let (tx, rx) = unbounded_channel();
236-
core_runtime.tokio_handle().spawn(start_worker_loop(worker, rx, channel.clone()));
240+
core_runtime.tokio_handle().spawn(start_worker_loop(
241+
worker,
242+
rx,
243+
channel.clone(),
244+
));
237245
send_result(channel.clone(), callback, |cx| {
238246
let worker =
239247
cx.boxed(RefCell::new(Some(WorkerHandle { sender: tx })));
@@ -245,7 +253,7 @@ pub fn start_bridge_loop(
245253
})
246254
}
247255
Err(err) => send_error(channel.clone(), callback, move |cx| {
248-
UNEXPECTED_ERROR.from_error(cx, err.deref())
256+
UNEXPECTED_ERROR.construct_from_error(cx, err.deref())
249257
}),
250258
};
251259
}
@@ -267,7 +275,7 @@ pub fn start_bridge_loop(
267275
Err(err) => {
268276
let err_str = format!("Failed to start ephemeral server: {}", err);
269277
send_error(channel.clone(), callback, |cx| {
270-
UNEXPECTED_ERROR.from_string(cx, err_str)
278+
UNEXPECTED_ERROR.construct_from_string(cx, err_str)
271279
});
272280
}
273281
Ok(server) => {
@@ -291,7 +299,7 @@ pub fn start_bridge_loop(
291299
guard.shutdown().await
292300
},
293301
|cx, err| {
294-
UNEXPECTED_ERROR.from_string(
302+
UNEXPECTED_ERROR.construct_from_string(
295303
cx,
296304
format!("Failed to start test server: {}", err),
297305
)
@@ -316,7 +324,7 @@ pub fn start_bridge_loop(
316324
};
317325
void_future_to_js(channel, callback, sendfut, |cx, err| {
318326
UNEXPECTED_ERROR
319-
.from_string(cx, format!("Error pushing replay history {}", err))
327+
.construct_from_string(cx, format!("Error pushing replay history {}", err))
320328
})
321329
.await
322330
});
@@ -429,7 +437,7 @@ pub fn client_close(mut cx: FunctionContext) -> JsResult<JsUndefined> {
429437
let client = cx.argument::<BoxedClient>(0)?;
430438
if client.replace(None).is_none() {
431439
ILLEGAL_STATE_ERROR
432-
.from_string(&mut cx, "Client already closed")
440+
.construct_from_string(&mut cx, "Client already closed")
433441
.and_then(|err| cx.throw(err))?;
434442
};
435443
Ok(cx.undefined())

packages/core-bridge/src/testing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ pub fn get_ephemeral_server_target(mut cx: FunctionContext) -> JsResult<JsString
3232
let target = server
3333
.borrow()
3434
.as_ref()
35-
.map(|s| cx.string(s.core_server.blocking_lock().target.to_owned()));
35+
.map(|s| cx.string(s.core_server.blocking_lock().target.as_str()));
3636
if target.is_none() {
3737
ILLEGAL_STATE_ERROR
38-
.from_string(&mut cx, "Tried to use closed test server")
38+
.construct_from_string(&mut cx, "Tried to use closed test server")
3939
.and_then(|err| cx.throw(err))?;
4040
};
4141
Ok(target.unwrap())

packages/core-bridge/src/worker.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ pub async fn start_worker_loop(
9393
callback,
9494
} => {
9595
handle_poll_workflow_activation_request(
96-
&worker, otel_span, channel, callback,
96+
worker, otel_span, channel, callback,
9797
)
9898
.await
9999
}
100100
WorkerRequest::PollActivityTask {
101101
otel_span,
102102
callback,
103103
} => {
104-
handle_poll_activity_task_request(&worker, otel_span, channel, callback)
104+
handle_poll_activity_task_request(worker, otel_span, channel, callback)
105105
.await
106106
}
107107
WorkerRequest::CompleteWorkflowActivation {
@@ -193,8 +193,8 @@ async fn handle_poll_workflow_activation_request(
193193
}
194194
Err(err) => {
195195
send_error(channel, callback, move |cx| match err {
196-
PollWfError::ShutDown => SHUTDOWN_ERROR.from_error(cx, err),
197-
PollWfError::TonicError(_) => TRANSPORT_ERROR.from_error(cx, err),
196+
PollWfError::ShutDown => SHUTDOWN_ERROR.construct_from_error(cx, err),
197+
PollWfError::TonicError(_) => TRANSPORT_ERROR.construct_from_error(cx, err),
198198
PollWfError::AutocompleteError(CompleteWfError::MalformedWorkflowCompletion {
199199
reason,
200200
..
@@ -226,8 +226,8 @@ pub async fn handle_poll_activity_task_request(
226226
}
227227
Err(err) => {
228228
send_error(channel, callback, move |cx| match err {
229-
PollActivityError::ShutDown => SHUTDOWN_ERROR.from_error(cx, err),
230-
PollActivityError::TonicError(_) => TRANSPORT_ERROR.from_error(cx, err),
229+
PollActivityError::ShutDown => SHUTDOWN_ERROR.construct_from_error(cx, err),
230+
PollActivityError::TonicError(_) => TRANSPORT_ERROR.construct_from_error(cx, err),
231231
});
232232
}
233233
}
@@ -287,7 +287,7 @@ pub fn push_history(mut cx: FunctionContext) -> JsResult<JsUndefined> {
287287
let workflow_id = cx.argument::<JsString>(1)?;
288288
let history_binary = cx.argument::<JsArrayBuffer>(2)?;
289289
let callback = cx.argument::<JsFunction>(3)?;
290-
let data = history_binary.as_slice(&mut cx);
290+
let data = history_binary.as_slice(&cx);
291291
match History::decode_length_delimited(data) {
292292
Ok(hist) => {
293293
let workflow_id = workflow_id.value(&mut cx);
@@ -373,7 +373,7 @@ pub fn worker_complete_workflow_activation(mut cx: FunctionContext) -> JsResult<
373373
}
374374
Some(worker) => {
375375
match WorkflowActivationCompletion::decode_length_delimited(
376-
completion.as_slice(&mut cx),
376+
completion.as_slice(&cx),
377377
) {
378378
Ok(completion) => {
379379
let request = WorkerRequest::CompleteWorkflowActivation {
@@ -405,7 +405,7 @@ pub fn worker_complete_activity_task(mut cx: FunctionContext) -> JsResult<JsUnde
405405
callback_with_unexpected_error(&mut cx, callback, "Tried to use closed Worker")?;
406406
}
407407
Some(worker) => {
408-
match ActivityTaskCompletion::decode_length_delimited(result.as_slice(&mut cx)) {
408+
match ActivityTaskCompletion::decode_length_delimited(result.as_slice(&cx)) {
409409
Ok(completion) => {
410410
let request = WorkerRequest::CompleteActivityTask {
411411
completion,
@@ -431,15 +431,15 @@ pub fn worker_record_activity_heartbeat(mut cx: FunctionContext) -> JsResult<JsU
431431
let heartbeat = cx.argument::<JsArrayBuffer>(1)?;
432432
match worker.borrow().as_ref() {
433433
None => UNEXPECTED_ERROR
434-
.from_string(&mut cx, "Tried to use closed Worker")
434+
.construct_from_string(&mut cx, "Tried to use closed Worker")
435435
.and_then(|err| cx.throw(err))?,
436436
Some(worker) => {
437-
match ActivityHeartbeat::decode_length_delimited(heartbeat.as_slice(&mut cx)) {
437+
match ActivityHeartbeat::decode_length_delimited(heartbeat.as_slice(&cx)) {
438438
Ok(heartbeat) => {
439439
let request = WorkerRequest::RecordActivityHeartbeat { heartbeat };
440440
if let Err(err) = worker.sender.send(request) {
441441
UNEXPECTED_ERROR
442-
.from_error(&mut cx, err)
442+
.construct_from_error(&mut cx, err)
443443
.and_then(|err| cx.throw(err))?;
444444
}
445445
}
@@ -466,7 +466,7 @@ pub fn worker_initiate_shutdown(mut cx: FunctionContext) -> JsResult<JsUndefined
466466
callback: callback.root(&mut cx),
467467
}) {
468468
UNEXPECTED_ERROR
469-
.from_error(&mut cx, err)
469+
.construct_from_error(&mut cx, err)
470470
.and_then(|err| cx.throw(err))?;
471471
};
472472
}
@@ -478,7 +478,7 @@ pub fn worker_finalize_shutdown(mut cx: FunctionContext) -> JsResult<JsUndefined
478478
let worker = cx.argument::<BoxedWorker>(0)?;
479479
if worker.replace(None).is_none() {
480480
ILLEGAL_STATE_ERROR
481-
.from_string(&mut cx, "Worker already closed")
481+
.construct_from_string(&mut cx, "Worker already closed")
482482
.and_then(|err| cx.throw(err))?;
483483
}
484484

0 commit comments

Comments
 (0)