Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion indent/indent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
}
}

Expand Down
16 changes: 16 additions & 0 deletions indent/indent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,20 @@ 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;",
}))
})

})
Loading