Skip to content

Commit

Permalink
feat: Add new .deno() config.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Mar 9, 2021
1 parent 511970e commit 0fac59d
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 11 deletions.
91 changes: 83 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ panic = "abort"
wasm = ["serde_json", "dprint-core/wasm"]

[dependencies]
dprint-core = { version = "0.35.0", features = ["formatting"] }
dprint-core = { version = "0.35.2", features = ["formatting"] }
pulldown-cmark = { version = "0.8.0", default-features = false }
serde = { version = "1.0.88", features = ["derive"] }
serde_json = { version = "1.0", optional = true }
regex = "1"

[dev-dependencies]
dprint-development = "0.2.2"
dprint-development = "0.2.6"
9 changes: 8 additions & 1 deletion src/configuration/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::*;
/// .build();
/// ```
pub struct ConfigurationBuilder {
config: ConfigKeyMap,
pub(super) config: ConfigKeyMap,
global_config: Option<GlobalConfiguration>,
}

Expand Down Expand Up @@ -92,6 +92,13 @@ impl ConfigurationBuilder {
self.insert("ignoreEndDirective", value.to_string().into())
}

pub fn deno(&mut self) -> &mut Self {
self.text_wrap(TextWrap::Always)
.ignore_directive("deno-fmt-ignore")
.ignore_start_directive("deno-fmt-ignore-start")
.ignore_end_directive("deno-fmt-ignore-end")
}

#[cfg(test)]
pub(super) fn get_inner_config(&self) -> ConfigKeyMap {
self.config.clone()
Expand Down
13 changes: 13 additions & 0 deletions src/configuration/resolve_config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use dprint_core::configuration::*;
use super::builder::ConfigurationBuilder;
use super::Configuration;
use super::types::*;

Expand Down Expand Up @@ -28,6 +29,10 @@ pub fn resolve_config(config: ConfigKeyMap, global_config: &GlobalConfiguration)
let mut diagnostics = Vec::new();
let mut config = config;

if get_value(&mut config, "deno", false, &mut diagnostics) {
fill_deno_config(&mut config);
}

let resolved_config = Configuration {
line_width: get_value(&mut config, "lineWidth", global_config.line_width.unwrap_or(80), &mut diagnostics),
new_line_kind: get_value(&mut config, "newLineKind", global_config.new_line_kind.unwrap_or(DEFAULT_GLOBAL_CONFIGURATION.new_line_kind), &mut diagnostics),
Expand All @@ -51,3 +56,11 @@ pub fn resolve_config(config: ConfigKeyMap, global_config: &GlobalConfiguration)
diagnostics,
}
}

fn fill_deno_config(config: &mut ConfigKeyMap) {
for (key, value) in ConfigurationBuilder::new().deno().config.iter() {
if !config.contains_key(key) {
config.insert(key.clone(), value.clone());
}
}
}
39 changes: 39 additions & 0 deletions tests/specs/General/Deno_All.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
~~ deno: true ~~
!! should format according to deno config !!
testing this out by going very far over the line and more testing and testing testing

<!-- deno-fmt-ignore -->
testing this out by going very far over the line and more testing and testing testing

testing this out by going very far over the line and more testing and testing testing

<!-- deno-fmt-ignore-start -->

testing this out by going very far over the line and more testing and testing testing

testing this out by going very far over the line and more testing and testing testing

<!-- deno-fmt-ignore-end -->

testing this out by going very far over the line and more testing and testing testing

[expect]
testing this out by going very far over the line and more testing and testing
testing

<!-- deno-fmt-ignore -->
testing this out by going very far over the line and more testing and testing testing

testing this out by going very far over the line and more testing and testing
testing

<!-- deno-fmt-ignore-start -->

testing this out by going very far over the line and more testing and testing testing

testing this out by going very far over the line and more testing and testing testing

<!-- deno-fmt-ignore-end -->

testing this out by going very far over the line and more testing and testing
testing

0 comments on commit 0fac59d

Please sign in to comment.