Skip to content

Commit c9086af

Browse files
committed
Fix newline kind detection
1 parent b00a26a commit c9086af

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/config.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use dprint_core::configuration::NewLineKind;
22
use serde::Serialize;
3-
use stylua_lib::{CallParenType, CollapseSimpleStatement, IndentType, LineEndings, QuoteStyle};
3+
use stylua_lib::{CallParenType, CollapseSimpleStatement, IndentType, QuoteStyle};
44

55
#[derive(Serialize, Clone)]
66
#[serde(rename_all = "camelCase")]
@@ -26,13 +26,6 @@ impl From<&Configuration> for stylua_lib::Config {
2626
false => IndentType::Spaces,
2727
})
2828
.with_indent_width(conf.indent_width as usize)
29-
.with_line_endings(match conf.new_line_kind {
30-
NewLineKind::Auto | NewLineKind::LineFeed => LineEndings::Unix,
31-
NewLineKind::CarriageReturnLineFeed => LineEndings::Windows,
32-
// TODO: fix
33-
NewLineKind::System if cfg!(windows) => LineEndings::Windows,
34-
NewLineKind::System => LineEndings::Unix,
35-
})
3629
.with_quote_style(conf.quote_style)
3730
.with_call_parentheses(conf.call_parentheses)
3831
.with_collapse_simple_statement(conf.collapse_simple_statement)

src/plugin.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use dprint_core::{
77
},
88
plugins::{FormatResult, PluginInfo, SyncPluginHandler},
99
};
10-
use stylua_lib::OutputVerification;
10+
use stylua_lib::{OutputVerification, LineEndings};
1111

1212
use crate::config::Configuration;
1313

@@ -110,9 +110,18 @@ impl SyncPluginHandler<Configuration> for StyluaPluginHandler {
110110
config: &Configuration,
111111
_format_with_host: impl FnMut(&Path, String, &ConfigKeyMap) -> FormatResult,
112112
) -> FormatResult {
113+
let stylua_config = stylua_lib::Config::from(config).with_line_endings(
114+
match configuration::resolve_new_line_kind(file_text, config.new_line_kind) {
115+
"\r\n" => LineEndings::Windows,
116+
"\n" => LineEndings::Unix,
117+
// Fall back to \n in case upstream function changes
118+
_ => LineEndings::Unix,
119+
},
120+
);
121+
113122
let result = stylua_lib::format_code(
114123
file_text,
115-
stylua_lib::Config::from(config),
124+
stylua_config,
116125
None,
117126
match config.verify {
118127
true => OutputVerification::Full,

0 commit comments

Comments
 (0)