Repository: dprint/dprint (language: rust)

Issue:
newLineKind system formats "LF" on windows
Version: 0.42.5

I downloaded windows installer from https://github.com/dprint/dprint/releases/download/0.42.5/dprint-x86_64-pc-windows-msvc-installer.exe

Regardless of execution via PS or CMD, files are formated with "LF" line ending when using `{"newLineKind": "system"}`. 
Files are formatted with correct line ending, if I change configuration to `{"newLineKind": "crlf"}`

We have both Windows & Mac users and git checks out the files with system line endings. So after formatting on windows, each file is marked as changed because of the line-ending.

Maybe the windows version is build with wrong target configuration?


Discussion / hints:

Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index c2394384e..2fb453b08 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -717,7 +717,7 @@ dependencies = [
 
 [[package]]
 name = "dprint-core"
-version = "0.63.3"
+version = "0.64.0"
 dependencies = [
  "anyhow",
  "async-trait",
diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml
index 218809098..7de72c729 100644
--- a/crates/core/Cargo.toml
+++ b/crates/core/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "dprint-core"
-version = "0.63.3"
+version = "0.64.0"
 authors = ["David Sherret <dsherret@gmail.com>"]
 edition = "2021"
 homepage = "https://github.com/dprint/dprint/tree/main/crates/core"
diff --git a/crates/core/src/configuration.rs b/crates/core/src/configuration.rs
index 581dbcb8f..099b6dbac 100644
--- a/crates/core/src/configuration.rs
+++ b/crates/core/src/configuration.rs
@@ -38,7 +38,7 @@ macro_rules! generate_str_to_from {
 }
 
 #[derive(Clone, PartialEq, Eq, Debug, Copy, Serialize, Deserialize, Hash)]
-pub enum NewLineKind {
+pub enum RawNewLineKind {
   /// Decide which newline kind to use based on the last newline in the file.
   #[serde(rename = "auto")]
   Auto,
@@ -54,13 +54,28 @@ pub enum NewLineKind {
 }
 
 generate_str_to_from![
-  NewLineKind,
+  RawNewLineKind,
   [Auto, "auto"],
   [LineFeed, "lf"],
   [CarriageReturnLineFeed, "crlf"],
   [System, "system"]
 ];
 
+#[derive(Clone, PartialEq, Eq, Debug, Copy, Serialize, Deserialize, Hash)]
+pub enum NewLineKind {
+  /// Decide which newline kind to use based on the last newline in the file.
+  #[serde(rename = "auto")]
+  Auto,
+  /// Use slash n new lines.
+  #[serde(rename = "lf")]
+  LineFeed,
+  /// Use slash r slash n new lines.
+  #[serde(rename = "crlf")]
+  CarriageReturnLineFeed,
+}
+
+generate_str_to_from![NewLineKind, [Auto, "auto"], [LineFeed, "lf"], [CarriageReturnLineFeed, "crlf"]];
+
 /// Represents a problem within the configuration.
 #[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug)]
 #[serde(rename_all = "camelCase")]
@@ -291,11 +306,24 @@ where
 pub fn resolve_global_config(config: &mut ConfigKeyMap) -> ResolveConfigurationResult<GlobalConfiguration> {
   let mut diagnostics = Vec::new();
 
+  let raw_new_line_kind = get_nullable_value::<RawNewLineKind>(config, "newLineKind", &mut diagnostics);
+
   let resolved_config = GlobalConfiguration {
     line_width: get_nullable_value(config, "lineWidth", &mut diagnostics),
     use_tabs: get_nullable_value(config, "useTabs", &mut diagnostics),
     indent_width: get_nullable_value(config, "indentWidth", &mut diagnostics),
-    new_line_kind: get_nullable_value(config, "newLineKind", &mut diagnostics),
+    new_line_kind: raw_new_line_kind.map(|kind| match kind {
+      RawNewLineKind::Auto => NewLineKind::Auto,
+      RawNewLineKind::LineFeed => NewLineKind::LineFeed,
+      RawNewLineKind::CarriageReturnLineFeed => NewLineKind::CarriageReturnLineFeed,
+      RawNewLineKind::System => {
+        if cfg!(windows) {
+          NewLineKind::CarriageReturnLineFeed
+        } else {
+          NewLineKind::LineFeed
+        }
+      }
+    }),
   };
 
   ResolveConfigurationResult {
@@ -384,13 +412,6 @@ pub fn resolve_new_line_kind(file_text: &str, new_line_kind: NewLineKind) -> &'s
 
       "\n"
     }
-    NewLineKind::System => {
-      if cfg!(windows) {
-        "\r\n"
-      } else {
-        "\n"
-      }
-    }
   }
 }
 
diff --git a/crates/dprint/Cargo.toml b/crates/dprint/Cargo.toml
index 44bf5ac15..89f4caec6 100644
--- a/crates/dprint/Cargo.toml
+++ b/crates/dprint/Cargo.toml
@@ -18,7 +18,7 @@ console_static_text = "0.7.1"
 # don't upgrade to 0.26 https://github.com/crossterm-rs/crossterm/issues/752
 crossterm = "0.25.0" # manually retest everything when bumping this crate
 dirs = "4.0.0"
-dprint-core = { path = "../core", version = "0.63.3", features = ["process", "wasm"] }
+dprint-core = { path = "../core", version = "0.64.0", features = ["process", "wasm"] }
 dunce = "1.0.3"
 fs3 = "0.5.0"
 ignore = "0.4.20"
diff --git a/crates/dprint/src/configuration/get_global_config.rs b/crates/dprint/src/configuration/get_global_config.rs
index 270e9e973..82ff45562 100644
--- a/crates/dprint/src/configuration/get_global_config.rs
+++ b/crates/dprint/src/configuration/get_global_config.rs
@@ -88,6 +88,26 @@ mod tests {
     );
   }
 
+  #[test]
+  fn should_get_global_for_system_new_line_kind() {
+    let mut config_map = ConfigMap::new();
+    config_map.insert(String::from("newLineKind"), ConfigMapValue::from_str("system"));
+    assert_result(
+      config_map,
+      GlobalConfiguration {
+        line_width: None,
+        use_tabs: None,
+        indent_width: None,
+        new_line_kind: Some(if cfg!(windows) {
+          NewLineKind::CarriageReturnLineFeed
+        } else {
+          NewLineKind::LineFeed
+        }),
+      },
+      &[],
+    );
+  }
+
   #[test]
   fn should_diagnostic_on_unexpected_object_properties() {
     let mut config_map = ConfigMap::new();


Test patch: