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 delete newlines in one-line files #42

Closed
bartekpacia opened this issue Dec 30, 2020 · 6 comments
Closed

Don't delete newlines in one-line files #42

bartekpacia opened this issue Dec 30, 2020 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@bartekpacia
Copy link
Contributor

bartekpacia commented Dec 30, 2020

Describe the bug
In my CI, I use (or at least, I would love to use, because this very issue prevents me from doing so) dart format -l 100 --output none --set-exit-if-changed . to format my code. After that, I want to check if my imports are sorted using flutter pub run import_sorter:main --exit-if-changed. Now, it is just not possible for those two actions to complete successfully (they're mutually exclusive), and that is because import_sorter removes trailing newlines from files without any import ... statements (or at least it looks like so).

File 1
Example file that causes problems (i.e trailing newline is removed by import_sorter):

enum HomeEvent { showInfo, showDiscover, showProfile }

File 2
Example file that works fine (i.e trailing newline is not removed by import_sorter):

import 'dart:core';

enum HomeEvent { showInfo, showDiscover, showProfile }

To Reproduce

  1. Create a file with contents of file 1
  2. dart format -l 100 .
  3. The file will have 2 lines: 1 line of code and a trailing newline. That's what I want.
  4. flutter pub run import_sorter:main --no-comments
  5. Check file contents. There won't be a trailing newline at the end of the file. I don't want this.
  6. dart format -l 100 .. A trailing newline will be there again. Yay!

Expected behavior
import_sorter should not delete the trailing newline.

Useful resources

  • How to easily check if a file has a trailing newline
  • according to my experience (I'm on macOS), the easiest way to edit a file is using TextEdit.app (it does not insert a trailing newline automatically, while several other programs I've used do insert a trailing newline (e.g nano)). To open a file in with TextEdit, use open -e <file>

Meta Information:

  • Dart Version: 2.12.3
  • import_sorter Version: 4.5.0
  • Is it a Flutter project? Yes
  • What version of Flutter are you using (if flutter project): 2.0.6
@bartekpacia bartekpacia added the bug Something isn't working label Dec 30, 2020
@github-actions
Copy link

👋 Hello! Thanks for submitting a issue! @Matt-Gleich will try to respond as soon as possible.

@bartekpacia
Copy link
Contributor Author

@Matt-Gleich hey, just pinging, it's quite important for me:)

@gleich
Copy link
Member

gleich commented Mar 2, 2021

Hey @bartekpacia! Sorry for the lack of communication here, I've been pretty busy with school work and some other work. I'll look into this over the weekend and let you know what's going on here.

@gleich gleich self-assigned this Mar 6, 2021
@bartekpacia bartekpacia changed the title Don't delete newlines Don't delete newlines in one-line files May 9, 2021
@bartekpacia
Copy link
Contributor Author

@Matt-Gleich I added more info to this issue (it still persists). I'd be very happy if it got fixed, but if you don't have time, I'll be done with my exams in ~2 weeks and then I can try to make a PR to fix this:)

@gleich gleich closed this as completed in 14f60e3 May 10, 2021
gleich added a commit that referenced this issue May 10, 2021
@gleich
Copy link
Member

gleich commented May 10, 2021

Super sorry for the lack of communication here. Just released 4.5.1 which has this fix. Thank you for the updated information and the reminder :)

@bartekpacia
Copy link
Contributor Author

Thanks a lot! :D

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