[][src]Struct dprint_plugin_typescript::Formatter

pub struct Formatter { /* fields omitted */ }

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...
}

Methods

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]

Formats a file.

Returns the file text `Ok(formatted_text) or an error when it failed to parse.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[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]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.