Skip to content

DartFixKind.ORGANIZE_IMPORTS disagrees with LintNames.directives_ordering #43927

Open
@kevmoo

Description

@kevmoo

tl;dr

LintNames.directives_ordering (which I agree with) prefers code like this

import 'travis.dart';
import 'travis/lib.dart';

DartFixKind.ORGANIZE_IMPORTS orders code like this:

import 'travis/lib.dart';
import 'travis.dart';

I hacked up the test which I would like to pass. 😄

diff --git a/pkg/analysis_server/test/src/services/correction/fix/organize_imports_test.dart b/pkg/analysis_server/test/src/services/correction/fix/organize_imports_test.dart
index 868dbabae2f..a8d90b20c97 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/organize_imports_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/organize_imports_test.dart
@@ -4,6 +4,7 @@

 import 'package:analysis_server/src/services/correction/fix.dart';
 import 'package:analysis_server/src/services/linter/lint_names.dart';
+import 'package:analyzer/src/error/codes.dart';
 import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';

@@ -40,4 +41,24 @@ import 'dart:io';
 void main(Stream<String> args) { }
 ''');
   }
+
+  Future<void> test_organizeImports2() async {
+    await resolveTestUnit('''
+import 'travis/lib.dart';
+
+import 'travis.dart';
+
+void main(Stream<String> args) { }
+''');
+    await assertHasFix(
+      '''
+import 'travis.dart';
+import 'travis/lib.dart';
+
+void main(Stream<String> args) { }
+''',
+      errorFilter: (input) =>
+          input.errorCode != CompileTimeErrorCode.URI_DOES_NOT_EXIST,
+    );
+  }
 }

CC @jwren @scheglov

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)devexp-bulk-fixtype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions