From 7e692f2251961233cb8912ac9e07e2b5f8e20b67 Mon Sep 17 00:00:00 2001 From: Kevin Amado Date: Wed, 9 Feb 2022 21:20:40 -0500 Subject: [PATCH] feat: remove max-width --- src/builder.rs | 6 ++---- src/cli.rs | 8 -------- src/config.rs | 19 +++++-------------- src/main.rs | 7 +------ tests/cases/assert/in | 3 ++- tests/cases/attr_set/in | 7 ++++++- tests/cases/bin_op/in | 3 ++- tests/cases/inherit/in | 6 ++++-- tests/cases/lambda/in | 3 ++- tests/cases/or_default/in | 3 ++- tests/cases/select/in | 3 ++- tests/cases/string/out | 4 +--- tests/cases/with/in | 3 ++- 13 files changed, 31 insertions(+), 44 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index e129dfb..639a341 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -296,6 +296,7 @@ pub fn fits_in_single_line( build_ctx: &crate::builder::BuildCtx, node: rnix::SyntaxElement, ) -> bool { + let line = build_ctx.pos_new.line; let maybe_green_node = build( &build_ctx.config.with_layout(crate::config::Layout::Wide), node, @@ -304,10 +305,7 @@ pub fn fits_in_single_line( ); match maybe_green_node { - Some(finished) => { - build_ctx.pos_new.column + finished.to_string().chars().count() - <= build_ctx.config.max_width() - } + Some(_) => build_ctx.pos_new.line == line, None => false, } } diff --git a/src/cli.rs b/src/cli.rs index 2ed264f..aa00452 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -8,14 +8,6 @@ pub fn parse(args: Vec) -> clap::ArgMatches { .short('d') .takes_value(false), ) - .arg( - clap::Arg::new("max-width") - .default_value("80") - .help("How many characters per line to allow.") - .long("max-width") - .takes_value(true) - .value_name("CHARS"), - ) .arg( clap::Arg::new("paths") .help("Files or directories, or none to format stdin.") diff --git a/src/config.rs b/src/config.rs index 326be5a..10205b3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,14 +6,13 @@ pub enum Layout { #[derive(Clone)] pub struct Config { - debug: bool, - layout: Layout, - max_width: usize, + debug: bool, + layout: Layout, } impl Config { pub fn new() -> Config { - Config { debug: false, layout: Layout::Tall, max_width: 80 } + Config { debug: false, layout: Layout::Tall } } pub fn debug(&self) -> bool { @@ -24,19 +23,11 @@ impl Config { &self.layout } - pub fn max_width(&self) -> usize { - self.max_width - } - pub fn with_debug(&self, debug: bool) -> Config { - Config { debug, layout: self.layout.clone(), max_width: self.max_width } + Config { debug, layout: self.layout.clone() } } pub fn with_layout(&self, layout: Layout) -> Config { - Config { debug: self.debug, layout, max_width: self.max_width } - } - - pub fn with_max_width(&self, max_width: usize) -> Config { - Config { debug: self.debug, layout: self.layout.clone(), max_width } + Config { debug: self.debug, layout } } } diff --git a/src/main.rs b/src/main.rs index c3bbb1c..f03dfda 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,12 +5,7 @@ fn main() -> std::io::Result<()> { let matches = alejandra::cli::parse(std::env::args().collect()); let debug: bool = matches.is_present("debug"); - let max_width: usize = - matches.value_of("max-width").unwrap().parse().unwrap(); - - let config = alejandra::config::Config::new() - .with_debug(debug) - .with_max_width(max_width); + let config = alejandra::config::Config::new().with_debug(debug); match matches.values_of("paths") { Some(paths) => { diff --git a/tests/cases/assert/in b/tests/cases/assert/in index eb9708d..1e8d1f3 100644 --- a/tests/cases/assert/in +++ b/tests/cases/assert/in @@ -4,5 +4,6 @@ (assert /*a*/ b; c) (assert /*a*/ b; /*b*/ c) ( assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc ) - ( assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc ) + ( assert b; + cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc ) ] diff --git a/tests/cases/attr_set/in b/tests/cases/attr_set/in index 8b55224..2af0248 100644 --- a/tests/cases/attr_set/in +++ b/tests/cases/attr_set/in @@ -19,7 +19,12 @@ rec /*a*/ { /*b*/ c=1; } rec /*a*/ { /*b*/ c=1; /*d*/ } - {a=rec {a={a=rec {a={a=rec {a={a=rec {a={a=rec {a={};};};};};};};};};};} + { + a=rec { + a={ + a=rec { + a={ + a=rec {a={a=rec {a={a=rec {a={};};};};};};};};};};} rec { diff --git a/tests/cases/bin_op/in b/tests/cases/bin_op/in index 61a9cb9..a74a5fe 100644 --- a/tests/cases/bin_op/in +++ b/tests/cases/bin_op/in @@ -5,5 +5,6 @@ (1/**/+/**/1) (1/**/+/**/(1/**/+/**/(1/**/+/**/1))) ( 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 ) - ( 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) + ( 1 + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) ] diff --git a/tests/cases/inherit/in b/tests/cases/inherit/in index b0c31d5..3e924ed 100644 --- a/tests/cases/inherit/in +++ b/tests/cases/inherit/in @@ -1,6 +1,8 @@ [ - { inherit aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; } - { inherit aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; } + { + inherit aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; } + { inherit + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; } { inherit b d ; } { inherit b d /*e*/ ; } { inherit b /*c*/ d ; } diff --git a/tests/cases/lambda/in b/tests/cases/lambda/in index c467519..bff1206 100644 --- a/tests/cases/lambda/in +++ b/tests/cases/lambda/in @@ -9,6 +9,7 @@ ( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ) - ( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ) + ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ) ({ pkgs ? import ./.. { }, locationsXml }: null) ] diff --git a/tests/cases/or_default/in b/tests/cases/or_default/in index b75e390..aa4d7f1 100644 --- a/tests/cases/or_default/in +++ b/tests/cases/or_default/in @@ -5,5 +5,6 @@ (a/**/?/**/a) (a/**/?/**/(a/**/?/**/(a/**/?/**/a))) ( a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ) - ( a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a) + ( a ? a + ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a) ] diff --git a/tests/cases/select/in b/tests/cases/select/in index 8ffc381..c66751e 100644 --- a/tests/cases/select/in +++ b/tests/cases/select/in @@ -4,5 +4,6 @@ (a/**/. a) (a/**/./**/a) ( a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a ) - ( a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a ) + ( a.a + .a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a ) ] diff --git a/tests/cases/string/out b/tests/cases/string/out index 4c6f927..c858487 100644 --- a/tests/cases/string/out +++ b/tests/cases/string/out @@ -58,9 +58,7 @@ [${mkSectionName sectName}] '' ### - ''-couch_ini ${cfg.package}/etc/default.ini ${configFile} ${ - pkgs.writeText "couchdb-extra.ini" cfg.extraConfig - } ${cfg.configFile}'' + ''-couch_ini ${cfg.package}/etc/default.ini ${configFile} ${pkgs.writeText "couchdb-extra.ini" cfg.extraConfig} ${cfg.configFile}'' ### ''exec i3-input -F "mark %s" -l 1 -P 'Mark: ' '' ### diff --git a/tests/cases/with/in b/tests/cases/with/in index 1a36adf..922aa33 100644 --- a/tests/cases/with/in +++ b/tests/cases/with/in @@ -4,5 +4,6 @@ (with /*a*/ b; c) (with /*a*/ b; /*b*/ c) ( with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc ) - ( with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc ) + ( with b; + cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc ) ]