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

Lint for import "sort order". #57172

Closed
pq opened this issue Feb 13, 2015 · 13 comments
Closed

Lint for import "sort order". #57172

pq opened this issue Feb 13, 2015 · 13 comments
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-lint-request type-enhancement A request for a change that isn't a bug

Comments

@pq
Copy link
Member

pq commented Feb 13, 2015

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.

@seaneagan
Copy link

Hopefully we can get this in the style guide too: dart-archive/www.dartlang.org#635

@pq
Copy link
Member Author

pq commented Feb 13, 2015

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

@pq pq added the type-enhancement A request for a change that isn't a bug label Feb 15, 2015
@harryterkelsen
Copy link
Contributor

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

@trentgrover-wf
Copy link

any further plans on this?

@pq
Copy link
Member Author

pq commented Sep 22, 2016

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

@alexeieleusis
Copy link
Contributor

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

@rdehouss
Copy link

rdehouss commented Apr 1, 2020

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

@pq
Copy link
Member Author

pq commented Apr 1, 2020

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

@rdehouss
Copy link

Hi @pq, no, I was coming from #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

@pq
Copy link
Member Author

pq commented Apr 13, 2020

Ah. Got it. What we need here minimally is a quickfix for directives_ordering (as noted in #57878) and ideally support in something like dartfix so that there's more of a CLI for bulk application of the fix.

/fyi @bwilkerson

@bwilkerson
Copy link
Member

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.

@pq
Copy link
Member Author

pq commented Apr 13, 2020

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

@bwilkerson
Copy link
Member

No, I'm not looking at it.

@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-lint-request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

9 participants