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

Remove unnecessary import assist should take empty lines into consideration #56761

Open
FMorschel opened this issue Sep 20, 2024 · 6 comments
Open
Labels
analyzer-quick-fix area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P4 type-enhancement A request for a change that isn't a bug

Comments

@FMorschel
Copy link
Contributor

FMorschel commented Sep 20, 2024

The Remove unnecessary import (unused as well) assist should take empty lines into consideration.

Since the auto import takes that into account to separate package imports from local imports (etc) by adding a line in between, this should also remove them as well. Also, I would expect that the last import being removed would remove all lines until the next thing written on the file:

// Empty line - can't leave it empty here because the empty line gets trimmed
import 'a.dart';

void main() {}

Today when running that assist/quick-fix:

// Empty line - can't leave it empty here because the empty lines get trimmed

void main() {}

I would expect at least the second line to be removed here.

PS: I noticed this inside the SDK when deving a new assist, I had a dart import and then when removing it I was left with the copyright lines at the top and two new empty lines between them and the package imports.


// CC: @DanTup

@dart-github-bot
Copy link
Collaborator

Summary: The "Remove unnecessary import" assist should remove empty lines after the last import is removed, ensuring consistency with auto-import behavior and preventing unnecessary empty lines in the code.

@dart-github-bot dart-github-bot added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-enhancement A request for a change that isn't a bug labels Sep 20, 2024
@lrhn lrhn removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Sep 21, 2024
@srawlins
Copy link
Member

Can you explain what you mean by "the markdown removes it"?

@FMorschel
Copy link
Contributor Author

Can you explain what you mean by "the markdown removes it"?

If I leave empty lines at the start of the markdown they get trimmed.

@srawlins
Copy link
Member

I don't understand what markdown. I don't see any markdown text, nor reference to a markdown tool.

@FMorschel
Copy link
Contributor Author

FMorschel commented Sep 27, 2024

Sorry, adding a code block like the above using ` is a markdown feature. This is what I meant by "markdown".

Leaving empty lines at the start of a code block is not possible because they get trimmed. The point of the comment was to show "There should be one more empty line here" but that wasn't possible since they were getting trimmed.

I can update the description. I'm just not sure if they get trimmed by default or by GH, but in this case, it doesn't matter, I don't think.


Edit

Edited the description for more clarity. Nice catch @srawlins!

@srawlins
Copy link
Member

srawlins commented Sep 27, 2024

Ahhhhhhh, my mind is open. Thank you @FMorschel I know what you mean. (I have had this problem trying to put single backticks in single backticks in GitHub markdown comment boxes.) Everything makes sense to me now; I get the request. 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-quick-fix area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P4 type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants