Sdk: "Optimize Imports" should handle comments properly

Created on 20 Jun 2016  路  5Comments  路  Source: dart-lang/sdk

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.

P2 analyzer-quick-fix area-analyzer type-bug

Most helpful comment

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.

All 5 comments

@scheglov

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).

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. 鈽癸笍

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.

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/linter/issues/1053 to track.

Was this page helpful?
0 / 5 - 0 ratings