dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.3k stars 1.59k forks source link

"Optimize Imports" should handle comments properly #26728

Open enyo opened 8 years ago

enyo commented 8 years ago

When you have multiple imports in dart, with comments, and then trigger "Optimize Imports", the comments are put below all imports. So you end up with a list of comments at the end of all imports which is less than ideal.

This happens with comments in a separate line as well as comments at the end of the line.

So this:

import 'foo.dart'; // comment

// comment
import 'bar.dart';

results in:

import 'bar.dart';
import 'foo.dart';
// comment
// comment

I would expect:

// comment
import 'bar.dart';
import 'foo.dart'; // comment

This is important, because when working with polymer elements, you need to use // ignore: UNUSED_IMPORT when importing a polymer element.

bwilkerson commented 8 years ago

@scheglov

lrhn commented 8 years ago

I believe imports can have annotations, which should be retained. I guess comments should be considered as annotations (except that you can also have a comment after the import).

pq commented 6 years ago

This is still an issue and a real hassle for the linter, where, for example, we ignore implementation_imports liberally.

https://github.com/dart-lang/linter/blob/d1f4dc88e74039e6a8d83121d2bee7355f1adedf/lib/src/rules/unnecessary_this.dart#L9

It's made even worse if you optimize imports on save. ☹️

bwilkerson commented 6 years ago

I really want this one to get fixed; I just never manage to find the time for it.

... we ignore implementation_imports liberally.

That needs to be fixed! There shouldn't be any need for importing from src once we've gotten the new public API figured out.

pq commented 6 years ago

That needs to be fixed! There shouldn't be any need for importing from src once we've gotten the new public API figured out.

👍

https://github.com/dart-lang/sdk/issues/57731 to track.