From 2e437d7fe5c8f0026a8c3d1baac2abc156f67be0 Mon Sep 17 00:00:00 2001 From: Vladyslav Kuksiuk Date: Mon, 22 Jun 2026 15:38:33 +0200 Subject: [PATCH 1/2] Fix indent cutting. --- indent/indent.go | 5 ++++- indent/indent_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/indent/indent.go b/indent/indent.go index fef2b762..d95ff4f1 100644 --- a/indent/indent.go +++ b/indent/indent.go @@ -56,13 +56,16 @@ func MaxCommonIndentation(lines []string) int { // // redundantSpaces — the number of leading spaces to remove from each line. // +// If a line is shorter than redundantSpaces, the whole line is removed. +// // Returns processed lines. func CutIndent(lines []string, redundantSpaces int) []string { linesChanged := make([]string, len(lines)) copy(linesChanged, lines) for i, line := range linesChanged { if len(line) > 0 { - linesChanged[i] = line[redundantSpaces:] + cutLength := min(redundantSpaces, len(line)) + linesChanged[i] = line[cutLength:] } } diff --git a/indent/indent_test.go b/indent/indent_test.go index f1374fa9..3a6e7ea7 100644 --- a/indent/indent_test.go +++ b/indent/indent_test.go @@ -60,4 +60,16 @@ var _ = Describe("Indent", func() { Expect(changedLines).ShouldNot(Equal(testLines)) }) + It("should cut lines shorter than the indentation", func() { + testLines := []string{" System.out.println(\"Hi\");", " ", " return;"} + + changedLines := indent.CutIndent(testLines, 8) + + Expect(changedLines).Should(Equal([]string{ + "System.out.println(\"Hi\");", + "", + "return;", + })) + }) + }) From af74874bf4b685c78d00e056ac9815ffbb9729e1 Mon Sep 17 00:00:00 2001 From: Vladyslav Kuksiuk Date: Mon, 22 Jun 2026 16:29:39 +0200 Subject: [PATCH 2/2] Improve readability. --- indent/indent_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/indent/indent_test.go b/indent/indent_test.go index 3a6e7ea7..a9bffd7e 100644 --- a/indent/indent_test.go +++ b/indent/indent_test.go @@ -61,7 +61,11 @@ var _ = Describe("Indent", func() { }) It("should cut lines shorter than the indentation", func() { - testLines := []string{" System.out.println(\"Hi\");", " ", " return;"} + testLines := []string{ + " System.out.println(\"Hi\");", + " ", + " return;", + } changedLines := indent.CutIndent(testLines, 8)