fluttercommunity / import_sorter

🎯 Automatically organize your dart imports. Maintainer: @gleich
https://pub.dev/packages/import_sorter
MIT License
174 stars 40 forks source link

Sorter violates directives_ordering lint rule when file has named imports #28

Open andrewrowe-wk opened 4 years ago

andrewrowe-wk commented 4 years ago

Describe the bug

In a file that contains relative import paths, and an absolute path to a named import, then the Dart linting rule directives_ordering fails.

To Reproduce

  1. In your analysis_options.yaml file, enable the directives_ordering option (more info here: http://dart-lang.github.io/linter/lints/directives_ordering.html)
  2. Create a file that contains the following:
    1. An absolute path to a project import
    2. An absolute path to a named project import
    3. A relative path to a project import
  3. Run the sorter
  4. You should see a linting error (I'm using VSCode)

Expected behavior

The import sorter should respect conventional dart styling guidelines.

Screenshots If applicable, add screenshots to help explain your problem.

Meta Information:

Additional context Add any other context about the problem here.

github-actions[bot] commented 4 years ago

👋 Hello! Thanks for submitting a issue 😄! @Matt-Gleich Will try to respond as soon as possible.

gleich commented 4 years ago

Hello! What version of import_sorter are you using? Please fill out the template

andrewrowe-wk commented 4 years ago

Sorry, I hit submit by accidentally ctrl+entering!

gleich commented 4 years ago

No worries!

andrewrowe-wk commented 4 years ago

Screen Shot 2020-08-04 at 3 07 18 PM

Here is a screenshot of the problem. Sorry for the obfuscation, but it's required :)

gleich commented 4 years ago

Awesome, thank you! I will debug it when I get out of work in an hour or so.

andrewrowe-wk commented 4 years ago

Hi Matt!

I think I've almost finished an implementation for this if you're up for the PR! The parsing for imports is actually pretty complicated, because, for my usecase, I leverage a lot of the import related Dart features. That being said, I've got a WIP version that conforms to 90% of the Dart language specification. Would be happy to answer any questions that you would have about it!

andrewrowe-wk commented 4 years ago

It will be 100% tested, and I will ensure that previous tests still pass.

gleich commented 4 years ago

Hey! Yeah, that would super great! Sorry about the lack of work on this, I am super busy with my internship recently.

andrewrowe-wk commented 4 years ago

No worries!

andrewrowe-wk commented 4 years ago

As an FYI, the issue was around lack of support for "multiline", as opposed to the as keyword. All details will be in PR.

gleich commented 4 years ago

@andrewrowe-wk any update on this? If need be I can start work on it

andrewrowe-wk commented 4 years ago

@Matt-Gleich Hi Matt! Yes, I've been working on it, and have a big PR I'm getting together, but I can only work on it on Fridays now, because I have other work that has come up. The change is pretty substantial, and the problem of sorting import statements is not very straightforward due to Dart the dart language specification. I ended up having to import a parser combinator library, to fully parse the import statements. The link to my branch is here if you want to take a look: https://github.com/andrewrowe-wk/import_sorter/tree/issue_28_fix_for_directive_ordering_lint_rule

gleich commented 4 years ago

Awesome! Looks pretty great so far. No rush on the timing btw, keep it up tho!

gleich commented 2 years ago

See #63