[−][src]Struct dprint_plugin_typescript::Formatter
Formatter for formatting JavaScript and TypeScript code.
Example
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![("path/to/file.ts", "const t = 5 ;")]; for (file_path, file_text) in files_to_format { let formatted_text = formatter.format_text(file_path, file_text); // ...save formatted_text here... }
Methods
impl<'a> Formatter<'a>
[src]
pub fn new(config: &'a Configuration) -> Self
[src]
Creates a new formatter from the specified configuration.
pub fn format_text(
&self,
file_path: &str,
file_text: &str
) -> Result<Option<String>, String>
[src]
&self,
file_path: &str,
file_text: &str
) -> Result<Option<String>, String>
Formats a file.
Returns the file text when the file was formatted, None
when the file had an ignore comment, and
an error when it failed to parse.
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Formatter<'a>
impl<'a> Send for Formatter<'a>
impl<'a> Sync for Formatter<'a>
impl<'a> Unpin for Formatter<'a>
impl<'a> UnwindSafe for Formatter<'a>
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, 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>,