pub fn format_text(&self, file_path: &PathBuf, file_text: &str) -> Result<String, String> {
        return self.run(|| {
            if has_ignore_comment(file_text, &self.config) {
                return Ok(String::from(file_text));
            }

            let parsed_source_file = parse_swc_ast(&file_path, &file_text)?;
            let print_items = parse(&parsed_source_file, &self.config);

            // println!("{}", print_items.get_as_text());

            Ok(print(print_items, PrintOptions {
                indent_width: self.config.indent_width,
                max_width: self.config.line_width,
                use_tabs: self.config.use_tabs,
                new_line_text: resolve_new_line_kind(file_text, self.config.new_line_kind),
            }))
        });

        fn has_ignore_comment(file_text: &str, config: &Configuration) -> bool {
            let mut iterator = super::utils::CharIterator::new(file_text.chars());
            iterator.skip_whitespace();
            if iterator.move_next() != Some('/') { return false; }
            match iterator.move_next() {
                Some('/') | Some('*') => {},
                _ => return false,
            }
            iterator.skip_whitespace();
            iterator.check_text(&config.ignore_file_comment_text)
        }
    }
/// Formats a file.
///
/// Returns the file text `Ok(formatted_text) or an error when it failed to parse.
Formats a file.
Returns the file text `Ok(formatted_text) or an error when it failed to parse.
Formats a file . Returns the file text ` Ok ( formatted_text ) or an error when it failed to parse .
pub fn format_text(&self, file_path: &PathBuf, file_text: &str) -> Result<String, String> {
        return self.run(|| {
            if has_ignore_comment(file_text, &self.config) {
                return Ok(String::from(file_text));
            }
            let parsed_source_file = parse_swc_ast(&file_path, &file_text)?;
            let print_items = parse(&parsed_source_file, &self.config);
            // println!("{}", print_items.get_as_text());
            Ok(print(print_items, PrintOptions {
                indent_width: self.config.indent_width,
                max_width: self.config.line_width,
                use_tabs: self.config.use_tabs,
                new_line_text: resolve_new_line_kind(file_text, self.config.new_line_kind),
            }))
        });
        fn has_ignore_comment(file_text: &str, config: &Configuration) -> bool {
            let mut iterator = super::utils::CharIterator::new(file_text.chars());
            iterator.skip_whitespace();
            if iterator.move_next() != Some('/') { return false; }
            match iterator.move_next() {
                Some('/') | Some('*') => {},
                _ => return false,
            }
            iterator.skip_whitespace();
            iterator.check_text(&config.ignore_file_comment_text)
        }
    }
pub fn format_text ( & self , file_path : & PathBuf , file_text : & str ) -> Result < String , String > { return self . run ( | | { if has_ignore_comment ( file_text , & self . config ) { return Ok ( String :: from ( file_text ) ) ; } let parsed_source_file = parse_swc_ast ( & file_path , & file_text ) ? ; let print_items = parse ( & parsed_source_file , & self . config ) ; // println!("{}", print_items.get_as_text()); Ok ( print ( print_items , PrintOptions { indent_width : self . config . indent_width , max_width : self . config . line_width , use_tabs : self . config . use_tabs , new_line_text : resolve_new_line_kind ( file_text , self . config . new_line_kind ) , } ) ) } ) ; fn has_ignore_comment ( file_text : & str , config : & Configuration ) -> bool { let mut iterator = super :: utils :: CharIterator :: new ( file_text . chars ( ) ) ; iterator . skip_whitespace ( ) ; if iterator . move_next ( ) != Some ( '/' ) { return false ; } match iterator . move_next ( ) { Some ( '/' ) | Some ( '*' ) => { } , _ => return false , } iterator . skip_whitespace ( ) ; iterator . check_text ( & config . ignore_file_comment_text ) } }
Formats a file.
Formats a file .
&self
file_path
&PathBuf
file_text
&str
&self
file_path
&PathBuf
file_text
&str