aziznal / dart-import-sorter

A vscode extension that groups and sorts imports for dart files (https://marketplace.visualstudio.com/items?itemName=aziznal.dart-import-sorter)
MIT License
14 stars 1 forks source link

Support imports having multiple lines (incl. conditionals, comments, and/or annotations) #49

Closed JCKodel closed 1 year ago

JCKodel commented 1 year ago

Before:

import 'package:kfx_dependency_injection/kfx_dependency_injection/platform_info.dart';
import 'package:mockito/annotations.dart';

// This is required:
import 'package:mockito/mockito.dart';

@GenerateNiceMocks([MockSpec<IAppSettingsRepository>(), MockSpec<IToDoRepository>()])
import "test_environment.mocks.dart";

After sorting:

import 'package:kfx_dependency_injection/kfx_dependency_injection/platform_info.dart';
import 'package:mockito/annotations.dart';

import 'package:mockito/mockito.dart';

import "test_environment.mocks.dart";

Both the comment and @GenerateNiceMocks are deleted when the sort occurs.

This package should stick // and @ lines to the same place they were before.

Or, at least, give us some option to ignore certain files, such as:

"dartImport.excludeGeneratedFiles": [
    "g.dart",
    "config.dart",
    "freezed.dart",
    "test_environment.dart"
  ],
aziznal commented 1 year ago

Hi. Thank you for your detailed feedback. I'm working on an addition that'll fix both the issues you mentioned here as well as in #48. But please bear with me because I'm sick as heck right now :mask:

So the way I plan on supporting this is to make it such that when an import is detected, any lines above it and below it which are not other imports or line breaks will also be grabbed as part of that import's raw body, but the actual sorting will only be done by using the import's body still.

I'm not 100% sure on what you mean by "ignore certain files". Can you explain that a bit more?

JCKodel commented 1 year ago

I'm not 100% sure on what you mean by "ignore certain files". Can you explain that a bit more?

The VS plugin DartImport has an option to ignore certain glob patterns, but I think this will not be useful here, so, please, ignore that bit =)

aziznal commented 1 year ago

Just made a new release. You shouldn't be encountering any more problems. Let me know if you have any issues!