Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
extension type support for sort_constructors_first (#4669)
Browse files Browse the repository at this point in the history
  • Loading branch information
pq authored Aug 11, 2023
1 parent facc499 commit 91ae2b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/src/rules/sort_constructors_first.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SortConstructorsFirst extends LintRule {
var visitor = _Visitor(this);
registry.addClassDeclaration(this, visitor);
registry.addEnumDeclaration(this, visitor);
registry.addExtensionTypeDeclaration(this, visitor);
}
}

Expand Down Expand Up @@ -85,4 +86,9 @@ class _Visitor extends SimpleAstVisitor<void> {
void visitEnumDeclaration(EnumDeclaration node) {
check(node.members);
}

@override
void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) {
check(node.members);
}
}
16 changes: 16 additions & 0 deletions test/rules/sort_constructors_first_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ main() {

@reflectiveTest
class SortConstructorsFirstTest extends LintRuleTest {
@override
List<String> get experiments => ['inline-class'];

@override
String get lintRule => 'sort_constructors_first';

Expand Down Expand Up @@ -48,6 +51,19 @@ abstract class A {
]);
}

test_methodBeforeConstructor_extensionType() async {
// Since the check logic is shared w/ classes and enums, one test should
// provide sufficient coverage for extension types.
await assertDiagnostics(r'''
extension type E(Object o) {
void f() {}
E.e(this.o);
}
''', [
lint(45, 1),
]);
}

test_methodBeforeConstructors() async {
await assertDiagnostics(r'''
abstract class A {
Expand Down

0 comments on commit 91ae2b6

Please sign in to comment.