Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added flag `--no-ignore-vcs` to continue formatting files listed in a `.gitignore` file, instead of skipping over them ([#895](https://github.com/JohnnyMorganz/StyLua/issues/895))
- Support `call_parentheses = Input` in editorconfig ([#1057](https://github.com/JohnnyMorganz/StyLua/pull/1057))

## [2.3.1] - 2025-11-01

Expand Down
125 changes: 57 additions & 68 deletions src/editorconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ property_choice! {
(Always, "always"),
(NoSingleString, "nosinglestring"),
(NoSingleTable, "nosingletable"),
(None, "none")
(None, "none"),
(Input, "input")
}

property_choice! {
Expand Down Expand Up @@ -90,91 +91,71 @@ property_choice! {
// Override StyLua config with EditorConfig properties
fn load(mut config: Config, properties: &Properties) -> Config {
if let Ok(end_of_line) = properties.get::<EndOfLine>() {
match end_of_line {
EndOfLine::Cr | EndOfLine::Lf => config.line_endings = LineEndings::Unix,
EndOfLine::CrLf => config.line_endings = LineEndings::Windows,
}
config.line_endings = match end_of_line {
EndOfLine::Cr | EndOfLine::Lf => LineEndings::Unix,
EndOfLine::CrLf => LineEndings::Windows,
};
}
if let Ok(indent_size) = properties.get::<IndentSize>() {
match indent_size {
IndentSize::Value(indent_width) => config.indent_width = indent_width,
IndentSize::UseTabWidth => {
if let Ok(TabWidth::Value(indent_width)) = properties.get::<TabWidth>() {
config.indent_width = indent_width
}
}
}
config.indent_width = match indent_size {
IndentSize::Value(indent_width) => indent_width,
IndentSize::UseTabWidth => match properties.get::<TabWidth>() {
Ok(TabWidth::Value(tab_width)) => tab_width,
_ => config.indent_width,
},
};
}
if let Ok(indent_style) = properties.get::<IndentStyle>() {
match indent_style {
IndentStyle::Tabs => config.indent_type = IndentType::Tabs,
IndentStyle::Spaces => config.indent_type = IndentType::Spaces,
}
config.indent_type = match indent_style {
IndentStyle::Tabs => IndentType::Tabs,
IndentStyle::Spaces => IndentType::Spaces,
};
}
if let Ok(max_line_length) = properties.get::<MaxLineLen>() {
match max_line_length {
MaxLineLen::Value(column_width) => config.column_width = column_width,
MaxLineLen::Off => config.column_width = usize::MAX,
}
config.column_width = match max_line_length {
MaxLineLen::Value(column_width) => column_width,
MaxLineLen::Off => usize::MAX,
};
}
if let Ok(quote_type) = properties.get::<QuoteTypeChoice>() {
match quote_type {
QuoteTypeChoice::Double => config.quote_style = QuoteStyle::AutoPreferDouble,
QuoteTypeChoice::Single => config.quote_style = QuoteStyle::AutoPreferSingle,
QuoteTypeChoice::Auto => (),
}
config.quote_style = match quote_type {
QuoteTypeChoice::Double => QuoteStyle::AutoPreferDouble,
QuoteTypeChoice::Single => QuoteStyle::AutoPreferSingle,
QuoteTypeChoice::Auto => config.quote_style,
};
}
if let Ok(call_parentheses) = properties.get::<CallParenthesesChoice>() {
match call_parentheses {
CallParenthesesChoice::Always => config.call_parentheses = CallParenType::Always,
CallParenthesesChoice::NoSingleString => {
config.call_parentheses = CallParenType::NoSingleString
}
CallParenthesesChoice::NoSingleTable => {
config.call_parentheses = CallParenType::NoSingleTable
}
CallParenthesesChoice::None => config.call_parentheses = CallParenType::None,
}
config.call_parentheses = match call_parentheses {
CallParenthesesChoice::Always => CallParenType::Always,
CallParenthesesChoice::NoSingleString => CallParenType::NoSingleString,
CallParenthesesChoice::NoSingleTable => CallParenType::NoSingleTable,
CallParenthesesChoice::None => CallParenType::None,
CallParenthesesChoice::Input => CallParenType::Input,
};
}
if let Ok(space_after_function_names) = properties.get::<SpaceAfterFunctionNamesChoice>() {
match space_after_function_names {
SpaceAfterFunctionNamesChoice::Always => {
config.space_after_function_names = SpaceAfterFunctionNames::Always
}
SpaceAfterFunctionNamesChoice::Definitions => {
config.space_after_function_names = SpaceAfterFunctionNames::Definitions
}
SpaceAfterFunctionNamesChoice::Calls => {
config.space_after_function_names = SpaceAfterFunctionNames::Calls
}
SpaceAfterFunctionNamesChoice::Never => {
config.space_after_function_names = SpaceAfterFunctionNames::Never
}
}
config.space_after_function_names = match space_after_function_names {
SpaceAfterFunctionNamesChoice::Always => SpaceAfterFunctionNames::Always,
SpaceAfterFunctionNamesChoice::Definitions => SpaceAfterFunctionNames::Definitions,
SpaceAfterFunctionNamesChoice::Calls => SpaceAfterFunctionNames::Calls,
SpaceAfterFunctionNamesChoice::Never => SpaceAfterFunctionNames::Never,
};
}
if let Ok(collapse_simple_statement) = properties.get::<CollapseSimpleStatementChoice>() {
match collapse_simple_statement {
CollapseSimpleStatementChoice::Never => {
config.collapse_simple_statement = CollapseSimpleStatement::Never
}
CollapseSimpleStatementChoice::FunctionOnly => {
config.collapse_simple_statement = CollapseSimpleStatement::FunctionOnly
}
config.collapse_simple_statement = match collapse_simple_statement {
CollapseSimpleStatementChoice::Never => CollapseSimpleStatement::Never,
CollapseSimpleStatementChoice::FunctionOnly => CollapseSimpleStatement::FunctionOnly,
CollapseSimpleStatementChoice::ConditionalOnly => {
config.collapse_simple_statement = CollapseSimpleStatement::ConditionalOnly
CollapseSimpleStatement::ConditionalOnly
}
CollapseSimpleStatementChoice::Always => {
config.collapse_simple_statement = CollapseSimpleStatement::Always
}
}
CollapseSimpleStatementChoice::Always => CollapseSimpleStatement::Always,
};
}
if let Ok(sort_requires) = properties.get::<SortRequiresChoice>() {
match sort_requires {
SortRequiresChoice::True => config.sort_requires = SortRequiresConfig { enabled: true },
SortRequiresChoice::False => {
config.sort_requires = SortRequiresConfig { enabled: false }
}
}
config.sort_requires = match sort_requires {
SortRequiresChoice::True => SortRequiresConfig { enabled: true },
SortRequiresChoice::False => SortRequiresConfig { enabled: false },
};
}

config
Expand Down Expand Up @@ -333,6 +314,14 @@ mod tests {
assert_eq!(config.call_parentheses, CallParenType::None);
}

#[test]
fn test_call_parentheses_input() {
let mut properties = Properties::new();
properties.insert_raw_for_key("call_parentheses", "Input");
let config = Config::from(&properties);
assert_eq!(config.call_parentheses, CallParenType::Input);
}

#[test]
fn test_space_after_function_names_always() {
let mut properties = Properties::new();
Expand Down
Loading