Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't do anything if the input is empty. #599

Merged
merged 1 commit into from
Aug 25, 2023

Conversation

allevato
Copy link
Member

Formatting/linting a 0 byte file should not insert or diagnose a trailing newline. This makes us consistent with clang-format's behavior even when its InsertNewlineAtEOF setting is enabled.


Behavior before:

$ echo -n 'foo()' | .build/debug/swift-format | hexdump -C
00000000  66 6f 6f 28 29 0a                                 |foo().|
00000006
$ echo -n '' | .build/debug/swift-format | hexdump -C
00000000  0a                                                |.|
00000001

Behavior after:

$ echo -n 'foo()' | .build/debug/swift-format | hexdump -C
00000000  66 6f 6f 28 29 0a                                 |foo().|
00000006
$ echo -n '' | .build/debug/swift-format | hexdump -C
<no output>

Likewise, lint mode now emits no finding for an empty file instead of previously emitting warning: [AddLines] add 1 line breaks.

Formatting/linting a 0 byte file should not insert or diagnose a
trailing newline. This makes us consistent with clang-format's
behavior even when its `InsertNewlineAtEOF` setting is enabled.

---

Behavior before:
```
$ echo -n 'foo()' | .build/debug/swift-format | hexdump -C
00000000  66 6f 6f 28 29 0a                                 |foo().|
00000006
$ echo -n '' | .build/debug/swift-format | hexdump -C
00000000  0a                                                |.|
00000001
```

Behavior after:

```
$ echo -n 'foo()' | .build/debug/swift-format | hexdump -C
00000000  66 6f 6f 28 29 0a                                 |foo().|
00000006
$ echo -n '' | .build/debug/swift-format | hexdump -C
<no output>
```

Likewise, lint mode now emits no finding for an empty file instead
of previously emitting `warning: [AddLines] add 1 line breaks`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant