Skip to content

Commit

Permalink
Remove List options from the formatter (#5183)
Browse files Browse the repository at this point in the history
Closes #2135 

What this does:
The formatter's config is basically a snapshot of `rustfmt`'s, but our
formatter does not make use of the list tactics that `rustfmt` does.
This just removes the unused code since we handle it a different way.
  • Loading branch information
eureka-cpu authored Oct 12, 2023
1 parent bf08373 commit 0eaa61a
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 145 deletions.
6 changes: 1 addition & 5 deletions swayfmt/src/config/imports.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Configuration options related to formatting imports.
use crate::config::{lists::ListTactic, user_opts::ImportsOptions, whitespace::IndentStyle};
use crate::config::{user_opts::ImportsOptions, whitespace::IndentStyle};
use serde::{Deserialize, Serialize};

#[derive(Debug, Copy, Clone)]
Expand All @@ -10,8 +10,6 @@ pub struct Imports {
pub imports_granularity: ImportGranularity,
/// Indent of imports.
pub imports_indent: IndentStyle,
/// Item layout inside a import block.
pub imports_layout: ListTactic,
}

impl Default for Imports {
Expand All @@ -20,7 +18,6 @@ impl Default for Imports {
group_imports: GroupImports::Preserve,
imports_granularity: ImportGranularity::Preserve,
imports_indent: IndentStyle::Block,
imports_layout: ListTactic::Mixed,
}
}
}
Expand All @@ -34,7 +31,6 @@ impl Imports {
.imports_granularity
.unwrap_or(default.imports_granularity),
imports_indent: opts.imports_indent.unwrap_or(default.imports_indent),
imports_layout: opts.imports_layout.unwrap_or(default.imports_layout),
}
}
}
Expand Down
13 changes: 1 addition & 12 deletions swayfmt/src/config/items.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Configuration options related to item formatting.
use crate::{
config::{lists::ListTactic, user_opts::ItemsOptions},
config::user_opts::ItemsOptions,
constants::{DEFAULT_BLANK_LINES_LOWER_BOUND, DEFAULT_BLANK_LINES_UPPER_BOUND},
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -57,17 +57,6 @@ pub enum ItemsLayout {
Vertical,
}

impl ItemsLayout {
pub fn to_list_tactic(self, len: usize) -> ListTactic {
match self {
ItemsLayout::Compressed => ListTactic::Mixed,
ItemsLayout::Tall => ListTactic::HorizontalVertical,
ItemsLayout::Vertical if len == 1 => ListTactic::Horizontal,
ItemsLayout::Vertical => ListTactic::Vertical,
}
}
}

/// Where to put the opening brace of items (`fn`, `impl`, etc.).
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub enum ItemBraceStyle {
Expand Down
111 changes: 0 additions & 111 deletions swayfmt/src/config/lists.rs

This file was deleted.

11 changes: 2 additions & 9 deletions swayfmt/src/config/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pub use crate::error::FormatterError;
use crate::{
config::{
comments::Comments, expr::Expressions, heuristics::Heuristics, imports::Imports,
items::Items, lists::Lists, literals::Literals, ordering::Ordering, user_def::Structures,
user_opts::*, whitespace::Whitespace,
items::Items, literals::Literals, ordering::Ordering, user_def::Structures, user_opts::*,
whitespace::Whitespace,
},
constants::SWAY_FORMAT_FILE_NAME,
error::ConfigError,
Expand All @@ -20,7 +20,6 @@ pub struct Config {
pub imports: Imports,
pub ordering: Ordering,
pub items: Items,
pub lists: Lists,
pub literals: Literals,
pub expressions: Expressions,
pub heuristics: Heuristics,
Expand All @@ -36,7 +35,6 @@ pub struct ConfigOptions {
pub imports: Option<ImportsOptions>,
pub ordering: Option<OrderingOptions>,
pub items: Option<ItemsOptions>,
pub lists: Option<ListsOptions>,
pub literals: Option<LiteralsOptions>,
pub expressions: Option<ExpressionsOptions>,
pub heuristics: Option<HeuristicsOptions>,
Expand Down Expand Up @@ -69,11 +67,6 @@ impl Config {
.as_ref()
.map(Items::from_opts)
.unwrap_or_default(),
lists: opts
.lists
.as_ref()
.map(Lists::from_opts)
.unwrap_or_default(),
literals: opts
.literals
.as_ref()
Expand Down
1 change: 0 additions & 1 deletion swayfmt/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pub mod expr;
pub mod heuristics;
pub mod imports;
pub mod items;
pub mod lists;
pub mod literals;
pub mod manifest;
pub mod ordering;
Expand Down
7 changes: 0 additions & 7 deletions swayfmt/src/config/user_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::config::{
heuristics::HeuristicsPreferences,
imports::{GroupImports, ImportGranularity},
items::{ItemBraceStyle, ItemsLayout},
lists::{ListTactic, SeparatorTactic},
literals::HexLiteralCase,
user_def::FieldAlignment,
whitespace::{IndentStyle, NewlineStyle},
Expand All @@ -26,7 +25,6 @@ pub struct ImportsOptions {
pub group_imports: Option<GroupImports>,
pub imports_granularity: Option<ImportGranularity>,
pub imports_indent: Option<IndentStyle>,
pub imports_layout: Option<ListTactic>,
}
/// See parent struct [Ordering].
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
Expand All @@ -43,11 +41,6 @@ pub struct ItemsOptions {
pub blank_lines_lower_bound: Option<usize>,
pub empty_item_single_line: Option<bool>,
}
/// See parent struct [Lists].
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub struct ListsOptions {
pub trailing_comma: Option<SeparatorTactic>,
}
/// See parent struct [Literals].
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub struct LiteralsOptions {
Expand Down

0 comments on commit 0eaa61a

Please sign in to comment.