Linter: Lint for import "sort order".

Created on 13 Feb 2015  路  13Comments  路  Source: dart-lang/linter

Migrated from dartbug/20244:

What steps will clearly show the issue / need for enhancement?

  1. Run dartfmt -t on attached foo.dart
  2. Observe that imports are not in order.

What is the current output?

import 'package:a_star/a_star_2d.dart';
import 'package:zx/zx.dart';
import 'dart:convert';
import 'dart:async';
import 'package:a_star/a_star.dart';

void main() {
}

What would you like to see instead?

import 'dart:convert';
import 'dart:async';
import 'package:a_star/a_star.dart';
import 'package:a_star/a_star_2d.dart';
import 'package:zx/zx.dart';

void main() {
}

The request, as it stands, is for a transformation supplied by dartfmt. Since dart_style is not in the business of non-WS affecting changes, this feels like linter territory. To start I think we want a lint; ultimately there will be an associated quick fix.

enhancement lint request style

Most helpful comment

any further plans on this?

All 13 comments

Hopefully we can get this in the style guide too: https://github.com/dart-lang/www.dartlang.org/issues/635

Yes please. And thanks for the link @seaneagan. I was just looking for it myself! :)

Yes please! The linter should complain if:

  • imports are not correctly grouped into dart:, package: and relative imports
  • groups are not separated by a blank line
  • imports are not sorted alphabetically within groups

any further plans on this?

any further plans on this?

Sorry. Haven't gotten to it but it's definitely a good idea and doable. Added to a new tracking milestone NEXT.馃憤

I think that with this week's contributions we can close this.

Hi,

Sorry to get this one out after so long, but I don't think dartfmt does sort the import, right?
Should this ticket be re-opened?

Regards,

Rapha毛l

@rdehouss: I think what you're after was implemented in directives_ordering. Let us know if that works for you!

Hi @pq, no, I was coming from https://github.com/dart-lang/sdk/issues/20244 looking for a solution like https://github.com/timothycrosley/isort to sort automatically the import so that I don't have to fix each lint issues manually. But I understand that I'm now in the linter project and left dartfmt, sorry

Ah. Got it. What we need here minimally is a quickfix for directives_ordering (as noted in https://github.com/dart-lang/linter/issues/1374) and ideally support in something like dartfix so that there's more of a CLI for bulk application of the fix.

/fyi @bwilkerson

The implementation of the quick fix should be largely the same as the implementation of the edit.organizeDirectives request. It should be fairly easy to refactor the code to make it reusable for both purposes.

Cool. I was looking at this recently. I created an issue and will take a look (unless @bwilkerson you already are!)

No, I'm not looking at it.

Was this page helpful?
0 / 5 - 0 ratings