-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve formatting array with only comments
- Loading branch information
Showing
5 changed files
with
145 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::path::PathBuf; | ||
use std::sync::Arc; | ||
|
||
use dprint_core::configuration::*; | ||
use dprint_development::*; | ||
use dprint_plugin_toml::configuration::resolve_config; | ||
use dprint_plugin_toml::*; | ||
|
||
fn main() { | ||
let global_config = GlobalConfiguration::default(); | ||
|
||
run_specs( | ||
&PathBuf::from("./tests/specs"), | ||
&ParseSpecOptions { | ||
default_file_name: "file.toml", | ||
}, | ||
&RunSpecsOptions { | ||
fix_failures: false, | ||
format_twice: true, | ||
}, | ||
{ | ||
let global_config = global_config.clone(); | ||
Arc::new(move |file_path, file_text, spec_config| { | ||
let spec_config: ConfigKeyMap = serde_json::from_value(spec_config.clone().into()).unwrap(); | ||
let config_result = resolve_config(spec_config, &global_config); | ||
ensure_no_diagnostics(&config_result.diagnostics); | ||
|
||
format_text(file_path, &file_text, &config_result.config) | ||
}) | ||
}, | ||
Arc::new(move |_file_path, _file_text, _spec_config| { | ||
#[cfg(feature = "tracing")] | ||
{ | ||
let spec_config: ConfigKeyMap = serde_json::from_value(_spec_config.clone().into()).unwrap(); | ||
let config_result = resolve_config(spec_config, &global_config); | ||
ensure_no_diagnostics(&config_result.diagnostics); | ||
return serde_json::to_string(&trace_file(_file_path, _file_text, &config_result.config)).unwrap(); | ||
} | ||
|
||
#[cfg(not(feature = "tracing"))] | ||
panic!("\n====\nPlease run with `cargo test --features tracing` to get trace output\n====\n") | ||
}), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
== should not add blank line at start of array with only comments == | ||
disallowed-types = [ | ||
# some comment | ||
# { path = "std::sync::Arc", reason = "use crate::sync::MaybeArc instead" }, | ||
|
||
# next comment | ||
] | ||
|
||
[expect] | ||
disallowed-types = [ | ||
# some comment | ||
# { path = "std::sync::Arc", reason = "use crate::sync::MaybeArc instead" }, | ||
|
||
# next comment | ||
] | ||
|
||
== should format with nodes == | ||
disallowed-types = [ | ||
# some comment | ||
# { path = "std::sync::Arc", reason = "use crate::sync::MaybeArc instead" }, | ||
|
||
# next comment | ||
"test" | ||
] | ||
|
||
[expect] | ||
disallowed-types = [ | ||
# some comment | ||
# { path = "std::sync::Arc", reason = "use crate::sync::MaybeArc instead" }, | ||
|
||
# next comment | ||
"test", | ||
] | ||
|
||
== comment first line == | ||
disallowed-types = [ # comment | ||
"test", | ||
] | ||
|
||
[expect] | ||
disallowed-types = [ # comment | ||
"test", | ||
] | ||
|
||
== comment first line no elements == | ||
disallowed-types = [ # comment | ||
] | ||
|
||
[expect] | ||
disallowed-types = [ # comment | ||
] | ||
|
||
== empty == | ||
value = [ | ||
] | ||
|
||
[expect] | ||
value = [] | ||
|
||
== one element == | ||
value = [ | ||
"value" | ||
] | ||
|
||
[expect] | ||
value = [ | ||
"value", | ||
] | ||
|
||
== one comment == | ||
value = [ | ||
# comment | ||
] | ||
|
||
[expect] | ||
value = [ | ||
# comment | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters