Skip to content

Commit f0c616e

Browse files
committed
lint
1 parent a5d8f9d commit f0c616e

File tree

1 file changed

+42
-30
lines changed

1 file changed

+42
-30
lines changed

src/api/express.rs

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ fn register_route(scope: &mut v8::HandleScope, args: v8::FunctionCallbackArgumen
624624
// Create mock request and response objects to test function behavior
625625
let mock_req = create_mock_request(scope, method, &path);
626626
let mock_res = create_mock_response(scope);
627-
627+
628628
// Execute the function with mock objects
629629
let args = [mock_req.into(), mock_res.into()];
630630
let undefined = v8::undefined(scope);
@@ -633,7 +633,10 @@ fn register_route(scope: &mut v8::HandleScope, args: v8::FunctionCallbackArgumen
633633
extract_response_pattern(scope, mock_res, method, &path)
634634
} else {
635635
// Fallback if execution fails
636-
format!("function(req, res) {{ res.send('Default response for {} {}'); }}", method, path)
636+
format!(
637+
"function(req, res) {{ res.send('Default response for {} {}'); }}",
638+
method, path
639+
)
637640
}
638641
} else {
639642
// Fallback for functions that can't be converted
@@ -670,76 +673,76 @@ fn create_mock_request<'a>(
670673
path: &str,
671674
) -> v8::Local<'a, v8::Object> {
672675
let req_obj = v8::Object::new(scope);
673-
676+
674677
// Set method
675678
let method_key = v8::String::new(scope, "method").unwrap();
676679
let method_val = v8::String::new(scope, method).unwrap();
677680
req_obj.set(scope, method_key.into(), method_val.into());
678-
681+
679682
// Set path
680683
let path_key = v8::String::new(scope, "path").unwrap();
681684
let path_val = v8::String::new(scope, path).unwrap();
682685
req_obj.set(scope, path_key.into(), path_val.into());
683-
686+
684687
// Set url
685688
let url_key = v8::String::new(scope, "url").unwrap();
686689
req_obj.set(scope, url_key.into(), path_val.into());
687-
690+
688691
// Set empty params and query
689692
let params_key = v8::String::new(scope, "params").unwrap();
690693
let params_obj = v8::Object::new(scope);
691694
req_obj.set(scope, params_key.into(), params_obj.into());
692-
695+
693696
let query_key = v8::String::new(scope, "query").unwrap();
694697
let query_obj = v8::Object::new(scope);
695698
req_obj.set(scope, query_key.into(), query_obj.into());
696-
699+
697700
// Set empty headers
698701
let headers_key = v8::String::new(scope, "headers").unwrap();
699702
let headers_obj = v8::Object::new(scope);
700703
req_obj.set(scope, headers_key.into(), headers_obj.into());
701-
704+
702705
req_obj
703706
}
704707

705708
fn create_mock_response<'a>(scope: &mut v8::HandleScope<'a>) -> v8::Local<'a, v8::Object> {
706709
let res_obj = v8::Object::new(scope);
707-
710+
708711
// Internal state
709712
let status_key = v8::String::new(scope, "_statusCode").unwrap();
710713
let status_val = v8::Number::new(scope, 200.0);
711714
res_obj.set(scope, status_key.into(), status_val.into());
712-
715+
713716
let headers_key = v8::String::new(scope, "_headers").unwrap();
714717
let headers_obj = v8::Object::new(scope);
715718
res_obj.set(scope, headers_key.into(), headers_obj.into());
716-
719+
717720
let body_key = v8::String::new(scope, "_body").unwrap();
718721
let body_val = v8::String::new(scope, "").unwrap();
719722
res_obj.set(scope, body_key.into(), body_val.into());
720-
723+
721724
let finished_key = v8::String::new(scope, "_finished").unwrap();
722725
let finished_val = v8::Boolean::new(scope, false);
723726
res_obj.set(scope, finished_key.into(), finished_val.into());
724-
727+
725728
// Response method - status
726729
let status_method_key = v8::String::new(scope, "status").unwrap();
727730
let status_method_template = v8::FunctionTemplate::new(scope, mock_res_status);
728731
let status_method = status_method_template.get_function(scope).unwrap();
729732
res_obj.set(scope, status_method_key.into(), status_method.into());
730-
733+
731734
// Response method - send
732735
let send_key = v8::String::new(scope, "send").unwrap();
733736
let send_template = v8::FunctionTemplate::new(scope, mock_res_send);
734737
let send_method = send_template.get_function(scope).unwrap();
735738
res_obj.set(scope, send_key.into(), send_method.into());
736-
739+
737740
// Response method - json
738741
let json_key = v8::String::new(scope, "json").unwrap();
739742
let json_template = v8::FunctionTemplate::new(scope, mock_res_json);
740743
let json_method = json_template.get_function(scope).unwrap();
741744
res_obj.set(scope, json_key.into(), json_method.into());
742-
745+
743746
res_obj
744747
}
745748

@@ -765,7 +768,7 @@ fn mock_res_send(
765768
if args.length() > 0 {
766769
let this = args.this();
767770
let data = args.get(0);
768-
771+
769772
// Set content-type to text/html if not set
770773
let headers_key = v8::String::new(scope, "_headers").unwrap();
771774
if let Some(headers_val) = this.get(scope, headers_key.into()) {
@@ -777,12 +780,12 @@ fn mock_res_send(
777780
}
778781
}
779782
}
780-
783+
781784
// Set body
782785
let body_key = v8::String::new(scope, "_body").unwrap();
783786
let data_str = data.to_string(scope).unwrap();
784787
this.set(scope, body_key.into(), data_str.into());
785-
788+
786789
// Mark as finished
787790
let finished_key = v8::String::new(scope, "_finished").unwrap();
788791
let finished_val = v8::Boolean::new(scope, true);
@@ -799,7 +802,7 @@ fn mock_res_json(
799802
if args.length() > 0 {
800803
let this = args.this();
801804
let data = args.get(0);
802-
805+
803806
// Set content-type to application/json
804807
let headers_key = v8::String::new(scope, "_headers").unwrap();
805808
if let Some(headers_val) = this.get(scope, headers_key.into()) {
@@ -809,7 +812,7 @@ fn mock_res_json(
809812
headers_obj.set(scope, ct_key.into(), ct_val.into());
810813
}
811814
}
812-
815+
813816
// Convert data to JSON string and set as body
814817
let body_key = v8::String::new(scope, "_body").unwrap();
815818
let json_key = v8::String::new(scope, "JSON").unwrap();
@@ -821,7 +824,7 @@ fn mock_res_json(
821824
let stringify_fn = v8::Local::<v8::Function>::try_from(stringify_fn).unwrap();
822825
let json_str = stringify_fn.call(scope, json_obj.into(), &[data]).unwrap();
823826
this.set(scope, body_key.into(), json_str.into());
824-
827+
825828
// Mark as finished
826829
let finished_key = v8::String::new(scope, "_finished").unwrap();
827830
let finished_val = v8::Boolean::new(scope, true);
@@ -841,7 +844,7 @@ fn extract_response_pattern(
841844
if let Some(body_val) = mock_res.get(scope, body_key.into()) {
842845
let body_str = body_val.to_string(scope).unwrap();
843846
let body = body_str.to_rust_string_lossy(scope);
844-
847+
845848
// Get content-type to determine response method
846849
let headers_key = v8::String::new(scope, "_headers").unwrap();
847850
if let Some(headers_val) = mock_res.get(scope, headers_key.into()) {
@@ -850,26 +853,35 @@ fn extract_response_pattern(
850853
if let Some(ct_val) = headers_obj.get(scope, ct_key.into()) {
851854
let ct_str = ct_val.to_string(scope).unwrap();
852855
let content_type = ct_str.to_rust_string_lossy(scope);
853-
856+
854857
if content_type.contains("application/json") {
855858
// User called res.json()
856859
return format!("function(req, res) {{ res.json({}); }}", body);
857860
} else {
858861
// User called res.send() or similar
859-
return format!("function(req, res) {{ res.send('{}'); }}", body.replace("'", "\\'"));
862+
return format!(
863+
"function(req, res) {{ res.send('{}'); }}",
864+
body.replace("'", "\\'")
865+
);
860866
}
861867
}
862868
}
863869
}
864-
870+
865871
// Default to send if we have a body but no content-type
866872
if !body.is_empty() {
867-
return format!("function(req, res) {{ res.send('{}'); }}", body.replace("'", "\\'"));
873+
return format!(
874+
"function(req, res) {{ res.send('{}'); }}",
875+
body.replace("'", "\\'")
876+
);
868877
}
869878
}
870-
879+
871880
// Fallback if we couldn't extract anything meaningful
872-
format!("function(req, res) {{ res.send('Response from {} {}'); }}", method, path)
881+
format!(
882+
"function(req, res) {{ res.send('Response from {} {}'); }}",
883+
method, path
884+
)
873885
}
874886

875887
fn parse_route_pattern(path: &str) -> (String, Vec<String>) {

0 commit comments

Comments
 (0)