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

End of file newline is removed #13

Closed
fappelman opened this issue Feb 22, 2020 · 4 comments
Closed

End of file newline is removed #13

fappelman opened this issue Feb 22, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@fappelman
Copy link

I have a simple example file demo.swift:

import Foundation

struct Demo {
    init() {
        // Bla
    }
}

It is important to notice that the file does end with a newline:

$ od -c demo.swift
0000000    i   m   p   o   r   t       F   o   u   n   d   a   t   i   o
0000020    n  \n  \n   s   t   r   u   c   t       D   e   m   o       {
0000040   \n                   i   n   i   t   (   )       {  \n
0000060                            /   /       B   l   a  \n
0000100        }  \n   }  \n
0000105

When I run swiftformat using the command line:

$ swiftformat --verbose --config ~/.config/swiftformat/config demo.swift
Running SwiftFormat...
Formatting demo.swift
-- no changes (cached)

SwiftFormat completed in 0.01s.
0/1 files formatted.

As you can see swiftformat is fine with this demo struct.

The next step is then to run this within VSCode. I have configured the exact same config file and would expect the same output. It is not, it removes the last line.

When I save it I get the following content with od:

$ od -c demo.swift
0000000    i   m   p   o   r   t       F   o   u   n   d   a   t   i   o
0000020    n  \n  \n   s   t   r   u   c   t       D   e   m   o       {
0000040   \n                   i   n   i   t   (   )       {  \n
0000060                            /   /       B   l   a  \n
0000100        }  \n   }
0000104

That new line should not be removed.

@fappelman
Copy link
Author

As a workaround I have enabled Insert Final Newline which restores the missing newline but that should not be the solution.

@vknabel vknabel self-assigned this Feb 22, 2020
@vknabel vknabel added the bug Something isn't working label Feb 22, 2020
@vknabel
Copy link
Owner

vknabel commented Feb 22, 2020

@fappelman Good catch! Thanks for the great report.
I will have a deeper look soon!

@vknabel
Copy link
Owner

vknabel commented Feb 23, 2020

Thanks again. Fix released as 1.3.4

Also I release a fix for vknabel/vscode-apple-swift-format@1.0.1, which had the same bug.

vknabel added a commit to vknabel/vscode-apple-swift-format that referenced this issue Feb 23, 2020
@fappelman
Copy link
Author

I did notice that the other package had the same issue. Thanks for fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants