From d9a089d7deae349b5c1a57f39a14b49fb5fef283 Mon Sep 17 00:00:00 2001 From: Joel Berger Date: Sat, 20 Jun 2020 12:01:00 -0500 Subject: [PATCH] Don't ignore non-trivial lines with no indentation When using the removeIndentation setting globally and including whole files, I notice that an odd thing happens. All code that is indented is outdented by one level! On investigation, this is caused by ignoring lines that begin without whitespace when computing the indentation level to consider the base. With this modified regex you still get the same result, ie a string of leading whitespace, however a line without leading whitespace still matches and the length of that result is 0. The trivial case of an entirely blank line is also handled by including a zero-width forward lookahead assertion that some non-whitespace character must occur after the leading optional indentation in order for that line to be included in the match. --- sampler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sampler.js b/sampler.js index 3aad871..c0c43d4 100644 --- a/sampler.js +++ b/sampler.js @@ -145,7 +145,7 @@ // and remove it from all lines. var removeIndentationFromLines = function(code) { var indent, indentPattern; - var indentMatch = code.match(/^[ \t]+/mg); + var indentMatch = code.match(/^[ \t]*(?=\S)/mg); if (indentMatch) { indent = indentMatch.reduce( function(previousValue, currentValue) {