mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
Adjust dprint configuration to be closer to prettier (#3824)
This commit is contained in:
parent
e1b3a0769a
commit
8e3bc774f7
1 changed files with 11 additions and 9 deletions
20
cli/fmt.rs
20
cli/fmt.rs
|
@ -7,9 +7,7 @@
|
||||||
//! the future it can be easily extended to provide
|
//! the future it can be easily extended to provide
|
||||||
//! the same functions as ops available in JS runtime.
|
//! the same functions as ops available in JS runtime.
|
||||||
|
|
||||||
use dprint_plugin_typescript::format_text;
|
use dprint_plugin_typescript as dprint;
|
||||||
use dprint_plugin_typescript::Configuration;
|
|
||||||
use dprint_plugin_typescript::ConfigurationBuilder;
|
|
||||||
use glob;
|
use glob;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -29,10 +27,14 @@ fn is_supported(path: &Path) -> bool {
|
||||||
&& (TYPESCRIPT.is_match(&path_str) || JAVASCRIPT.is_match(&path_str))
|
&& (TYPESCRIPT.is_match(&path_str) || JAVASCRIPT.is_match(&path_str))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_config() -> Configuration {
|
fn get_config() -> dprint::Configuration {
|
||||||
ConfigurationBuilder::new()
|
dprint::ConfigurationBuilder::new()
|
||||||
.line_width(80)
|
.line_width(80)
|
||||||
.indent_width(2)
|
.indent_width(2)
|
||||||
|
.next_control_flow_position(dprint::NextControlFlowPosition::SameLine)
|
||||||
|
.force_multi_line_parameters(true)
|
||||||
|
.force_multi_line_arguments(true)
|
||||||
|
.binary_expression_operator_position(dprint::OperatorPosition::SameLine)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,14 +50,14 @@ fn get_supported_files(paths: Vec<PathBuf>) -> Vec<PathBuf> {
|
||||||
files_to_check
|
files_to_check
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_source_files(config: Configuration, paths: Vec<PathBuf>) {
|
fn check_source_files(config: dprint::Configuration, paths: Vec<PathBuf>) {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let mut not_formatted_files = vec![];
|
let mut not_formatted_files = vec![];
|
||||||
|
|
||||||
for file_path in paths {
|
for file_path in paths {
|
||||||
let file_path_str = file_path.to_string_lossy();
|
let file_path_str = file_path.to_string_lossy();
|
||||||
let file_contents = fs::read_to_string(&file_path).unwrap();
|
let file_contents = fs::read_to_string(&file_path).unwrap();
|
||||||
match format_text(&file_path_str, &file_contents, &config) {
|
match dprint::format_text(&file_path_str, &file_contents, &config) {
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
// nothing to format, pass
|
// nothing to format, pass
|
||||||
}
|
}
|
||||||
|
@ -91,14 +93,14 @@ fn check_source_files(config: Configuration, paths: Vec<PathBuf>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_source_files(config: Configuration, paths: Vec<PathBuf>) {
|
fn format_source_files(config: dprint::Configuration, paths: Vec<PathBuf>) {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let mut not_formatted_files = vec![];
|
let mut not_formatted_files = vec![];
|
||||||
|
|
||||||
for file_path in paths {
|
for file_path in paths {
|
||||||
let file_path_str = file_path.to_string_lossy();
|
let file_path_str = file_path.to_string_lossy();
|
||||||
let file_contents = fs::read_to_string(&file_path).unwrap();
|
let file_contents = fs::read_to_string(&file_path).unwrap();
|
||||||
match format_text(&file_path_str, &file_contents, &config) {
|
match dprint::format_text(&file_path_str, &file_contents, &config) {
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
// nothing to format, pass
|
// nothing to format, pass
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue