11use std:: path:: { Path , PathBuf } ;
22use std:: sync:: Arc ;
33
4+ use anyhow:: Result ;
45use deno_ast:: MediaType ;
56use dprint_core:: configuration:: * ;
67use dprint_development:: * ;
78use dprint_plugin_typescript:: configuration:: * ;
89use dprint_plugin_typescript:: * ;
910
10- fn external_formatter ( media_type : MediaType , text : String , config : & Configuration ) -> Option < String > {
11+ fn external_formatter ( media_type : MediaType , text : String , config : & Configuration ) -> Result < Option < String > > {
1112 match media_type {
1213 MediaType :: Css => format_embedded_css ( & text, config) ,
1314 MediaType :: Html => format_html ( & text, config) ,
@@ -16,7 +17,7 @@ fn external_formatter(media_type: MediaType, text: String, config: &Configuratio
1617 }
1718}
1819
19- fn format_embedded_css ( text : & str , config : & Configuration ) -> Option < String > {
20+ fn format_embedded_css ( text : & str , config : & Configuration ) -> Result < Option < String > > {
2021 use malva:: config;
2122 let options = config:: FormatOptions {
2223 layout : config:: LayoutOptions {
@@ -27,9 +28,7 @@ fn format_embedded_css(text: &str, config: &Configuration) -> Option<String> {
2728 } ;
2829 // Wraps the text in a css block of `a { ... }`
2930 // to make it valid css (scss)
30- let Ok ( text) = malva:: format_text ( & format ! ( "a{{\n {}\n }}" , text) , malva:: Syntax :: Scss , & options) else {
31- return None ;
32- } ;
31+ let text = malva:: format_text ( & format ! ( "a{{\n {}\n }}" , text) , malva:: Syntax :: Scss , & options) ?;
3332 let mut buf = vec ! [ ] ;
3433 for ( i, l) in text. lines ( ) . enumerate ( ) {
3534 // skip the first line (a {)
@@ -47,10 +46,10 @@ fn format_embedded_css(text: &str, config: &Configuration) -> Option<String> {
4746 }
4847 buf. push ( chars. as_str ( ) ) ;
4948 }
50- Some ( buf. join ( "\n " ) . to_string ( ) )
49+ Ok ( Some ( buf. join ( "\n " ) . to_string ( ) ) )
5150}
5251
53- fn format_html ( text : & str , config : & Configuration ) -> Option < String > {
52+ fn format_html ( text : & str , config : & Configuration ) -> Result < Option < String > > {
5453 use markup_fmt:: config;
5554 let options = config:: FormatOptions {
5655 layout : config:: LayoutOptions {
@@ -59,19 +58,17 @@ fn format_html(text: &str, config: &Configuration) -> Option<String> {
5958 } ,
6059 ..Default :: default ( )
6160 } ;
62- let Ok ( text) = markup_fmt:: format_text ( text, markup_fmt:: Language :: Html , & options, |code, _| {
61+ let text = markup_fmt:: format_text ( text, markup_fmt:: Language :: Html , & options, |code, _| {
6362 Ok :: < _ , std:: convert:: Infallible > ( code. into ( ) )
64- } ) else {
65- return None ;
66- } ;
67- Some ( text. to_string ( ) )
63+ } ) ?;
64+ Ok ( Some ( text. to_string ( ) ) )
6865}
6966
70- fn format_sql ( text : & str , config : & Configuration ) -> Option < String > {
67+ fn format_sql ( text : & str , config : & Configuration ) -> Result < Option < String > > {
7168 let options = dprint_plugin_sql:: configuration:: ConfigurationBuilder :: new ( )
7269 . indent_width ( config. indent_width )
7370 . build ( ) ;
74- dprint_plugin_sql:: format_text ( Path :: new ( "_path.sql" ) , text, & options) . ok ( ) . flatten ( )
71+ dprint_plugin_sql:: format_text ( Path :: new ( "_path.sql" ) , text, & options)
7572}
7673
7774fn main ( ) {
0 commit comments