[−][src]Struct dprint_plugin_typescript::Formatter
Formatter for formatting JavaScript and TypeScript code.
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(); // create the formatter let formatter = Formatter::new(config); // now format many files (possibly 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.iter() { let result = formatter.format_text(file_path, file_text); // save result here... }
Implementations
impl Formatter
[src]
pub fn new(config: Configuration) -> Self
[src]
Creates a new formatter with the specified configuration.
pub fn format_text(
&self,
file_path: &PathBuf,
file_text: &str
) -> Result<String, String>
[src]
&self,
file_path: &PathBuf,
file_text: &str
) -> Result<String, String>
Formats a file.
Returns the file text `Ok(formatted_text) or an error when it failed to parse.
Auto Trait Implementations
impl !RefUnwindSafe for Formatter
impl Send for Formatter
impl Sync for Formatter
impl Unpin for Formatter
impl UnwindSafe for Formatter
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Erased for T
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Node for T where
T: Any + ?Sized,
T: Any + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,