-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix directives_ordering to sort '/' absolute paths first
Basically the code change just falls back to the behavior prior to commit aed089e45c35221ce2b82f3757132031f0344b8b when a leading slash is encountered. Fixes https://github.com/dart-lang/linter/issues/4869 Change-Id: I61fc7915f44f043f591ea439d40d4016fc8b3d27 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350861 Commit-Queue: Oleh Prypin <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
- Loading branch information
Showing
4 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:linter/src/rules/directives_ordering.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group(compareDirectives, () { | ||
void checkImportGroup(List<String> correctlyOrderedImports) { | ||
for (int i = 0; i < correctlyOrderedImports.length; i++) { | ||
var a = correctlyOrderedImports[i]; | ||
expect(compareDirectives(a, a), 0, | ||
reason: '"$a" sorts the same as itself'); | ||
|
||
for (int j = i + 1; j < correctlyOrderedImports.length; j++) { | ||
var b = correctlyOrderedImports[j]; | ||
expect(compareDirectives(a, b), lessThan(0), | ||
reason: '"$a" sorts before "$b"'); | ||
expect(compareDirectives(b, a), greaterThan(0), | ||
reason: '"$b" sorts after "$a"'); | ||
} | ||
} | ||
} | ||
|
||
test('dart: imports', () { | ||
checkImportGroup(const [ | ||
'dart:aaa', | ||
'dart:bbb', | ||
]); | ||
}); | ||
|
||
test('package: imports', () { | ||
checkImportGroup(const [ | ||
'package:aa/bb.dart', | ||
'package:aaa/aaa.dart', | ||
'package:aaa/ccc.dart', | ||
'package:bbb/bbb.dart', | ||
]); | ||
}); | ||
|
||
test('relative imports', () { | ||
checkImportGroup(const [ | ||
'/foo5.dart', | ||
'../../foo4.dart', | ||
'../foo2/a.dart', | ||
'../foo3.dart', | ||
'./foo2.dart', | ||
'a.dart', | ||
'aaa/aaa.dart', | ||
'bbb/bbb.dart', | ||
'foo1.dart', | ||
]); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters