From b6679fa6e3fb5d4efd55bf3e1e526d2b96d43d0b Mon Sep 17 00:00:00 2001 From: Kevin Amado Date: Fri, 28 Jan 2022 00:08:27 -0500 Subject: [PATCH] feat: trim end of whitespace lines --- default.nix | 4 +--- flake.nix | 14 +++++++------- src/rules/string.rs | 12 +++++++----- tests/cases/string/out | 12 ++++++------ 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/default.nix b/default.nix index 0c39827..d57658d 100644 --- a/default.nix +++ b/default.nix @@ -10,6 +10,4 @@ let }; flake = import flakeCompatSrc { src = ./.; }; in -flake - .defaultNix - .defaultPackage +flake.defaultNix.defaultPackage diff --git a/flake.nix b/flake.nix index 0437a51..ef29276 100644 --- a/flake.nix +++ b/flake.nix @@ -46,7 +46,7 @@ packages = [ nixpkgs.cargo-tarpaulin nixpkgs.rustup ]; shellHook = '' - rustup toolchain install nightly + rustup toolchain install nightly ''; }; packages = { @@ -58,15 +58,15 @@ builtins.toFile "builder.sh" '' - source $stdenv/setup + source $stdenv/setup - cp -rT $nixpkgs $out - chmod -R +w $out + cp -rT $nixpkgs $out + chmod -R +w $out - alejandra $out + alejandra $out - git diff --no-index $nixpkgs $out > $diff || true - ''; + git diff --no-index $nixpkgs $out > $diff || true + ''; buildInputs = [ inputs.self.defaultPackage.${ system } nixpkgs.git ]; nixpkgs = inputs.nixpkgs.sourceInfo.outPath; NIX_BUILD_CORES = 0; diff --git a/src/rules/string.rs b/src/rules/string.rs index 606f5fb..54794f9 100644 --- a/src/rules/string.rs +++ b/src/rules/string.rs @@ -91,11 +91,13 @@ pub fn rule( .collect(); if portions.len() == 1 { - steps.push_back(crate::builder::Step::Pad); - steps.push_back(crate::builder::Step::Token( - rnix::SyntaxKind::TOKEN_STRING_CONTENT, - portions[0].to_string(), - )); + if portions[0].len() > 0 || index + 1 == lines.len() { + steps.push_back(crate::builder::Step::Pad); + steps.push_back(crate::builder::Step::Token( + rnix::SyntaxKind::TOKEN_STRING_CONTENT, + portions[0].to_string(), + )); + } } else { steps.push_back(crate::builder::Step::Pad); for (index, portion) in portions.iter().enumerate() { diff --git a/tests/cases/string/out b/tests/cases/string/out index 4a71346..5633549 100644 --- a/tests/cases/string/out +++ b/tests/cases/string/out @@ -16,14 +16,14 @@ '' ${ "" }'' ### '' ${ "" } - + '' ### '' a '' ### '' a - + '' ### '' a @@ -32,7 +32,7 @@ '' a '' ### - '' + '' a ${ "" } b @@ -41,10 +41,10 @@ e '' ### - '' + '' '' ### - '' + '' declare -a makefiles=(./*.mak) sed -i -f ${ makefile-sed } "''${makefiles[@]}" ### assign Makefile variables eagerly & change backticks to `$(shell …)` @@ -53,7 +53,7 @@ "''${makefiles[@]}" '' ### - '' + '' [${ mkSectionName sectName }] '' ###