1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::path::Path;
use dprint_core::formatting::*;
use dprint_core::configuration::{resolve_new_line_kind};
use super::parsing::parse;
use super::swc::parse_swc_ast;
use super::configuration::Configuration;
pub fn format_text(file_path: &Path, file_text: &str, config: &Configuration) -> Result<String, String> {
if super::utils::file_text_has_ignore_comment(file_text, &config.ignore_file_comment_text) {
return Ok(String::from(file_text));
}
let parsed_source_file = parse_swc_ast(file_path, file_text)?;
return Ok(dprint_core::formatting::format(|| {
let print_items = parse(&parsed_source_file, config);
print_items
}, PrintOptions {
indent_width: config.indent_width,
max_width: config.line_width,
use_tabs: config.use_tabs,
new_line_text: resolve_new_line_kind(file_text, config.new_line_kind),
}));
}