Skip to content

Commit e7b7722

Browse files
authored
Fix indentation parsing (#830)
Inline snapshot testing attempts to figure out the indentation width of a file by finding the first line with whitespace and grabbing the prefix of whitespace. While this works fine if you trim whitespace from whitespace-only lines, it breaks if you do not, because a line of the form: ``` " \n" ``` Will currently match in its entirety and incorporate the newline into the indentation. This PR fixes this by picking the first indented line that contains non-whitespace characters, instead.
1 parent 8e68404 commit e7b7722

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ public struct InlineSnapshotSyntaxDescriptor: Hashable {
388388
self.wasRecording = snapshots.first?.wasRecording ?? isRecording
389389
self.indent = String(
390390
sourceLocationConverter.sourceLines
391-
.first(where: { $0.first?.isWhitespace == true && $0 != "\n" })?
392-
.prefix(while: { $0.isWhitespace })
391+
.first { $0.first?.isWhitespace == true && $0.contains { !$0.isWhitespace } }?
392+
.prefix { $0.isWhitespace }
393393
?? " "
394394
)
395395
self.snapshots = snapshots

0 commit comments

Comments
 (0)