pub fn format_text(
file_path: &Path,
file_extension: Option<&str>,
file_text: String,
config: &Configuration,
) -> Result<Option<String>>
Expand description
Formats a file.
Returns the file text or an error when it failed to parse.
ยงExample
use std::path::PathBuf;
use dprint_plugin_typescript::*;
use dprint_plugin_typescript::configuration::*;
// build the configuration once
let config = ConfigurationBuilder::new()
.line_width(80)
.prefer_hanging(true)
.prefer_single_line(false)
.quote_style(QuoteStyle::PreferSingle)
.next_control_flow_position(NextControlFlowPosition::SameLine)
.build();
// now format many files (it is recommended to parallelize this)
let files_to_format = vec![(PathBuf::from("path/to/file.ts"), "const t = 5 ;")];
for (file_path, file_text) in files_to_format {
let result = format_text(&file_path, None, file_text.into(), &config);
// save result here...
}