This repository was archived by the owner on Nov 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -94,9 +94,20 @@ class Validator extends SimpleAstVisitor<void> {
94
94
if (name != null && Identifier .isPrivateName (name.lexeme)) {
95
95
return ;
96
96
}
97
+
97
98
// Enum constructors are effectively private so don't visit their params.
98
99
if (node.parent is EnumDeclaration ) return ;
99
100
101
+ // Select modified class types are also effectively private.
102
+ var enclosingElement = node.declaredElement? .enclosingElement;
103
+ if (enclosingElement is ClassElement ) {
104
+ if (enclosingElement.isSealed) return ;
105
+ if (enclosingElement.isAbstract) {
106
+ if (enclosingElement.isInterface) return ;
107
+ if (enclosingElement.isFinal) return ;
108
+ }
109
+ }
110
+
100
111
node.parameters.accept (this );
101
112
}
102
113
Original file line number Diff line number Diff line change @@ -18,6 +18,30 @@ class LibraryPrivateTypesInPublicApiEnumTest extends LintRuleTest {
18
18
@override
19
19
String get lintRule => 'library_private_types_in_public_api' ;
20
20
21
+ test_abstractFinal_constructorParams () async {
22
+ await assertNoDiagnostics (r'''
23
+ class _O {
24
+ const _O();
25
+ }
26
+
27
+ abstract final class E {
28
+ E(_O o);
29
+ }
30
+ ''' );
31
+ }
32
+
33
+ test_abstractInterface_constructorParams () async {
34
+ await assertNoDiagnostics (r'''
35
+ class _O {
36
+ const _O();
37
+ }
38
+
39
+ abstract interface class E {
40
+ E(_O o);
41
+ }
42
+ ''' );
43
+ }
44
+
21
45
test_enum () async {
22
46
await assertDiagnostics (r'''
23
47
class _O {}
@@ -44,6 +68,18 @@ enum E {
44
68
a(_O());
45
69
const E(_O o);
46
70
}
71
+ ''' );
72
+ }
73
+
74
+ test_sealed_constructorParams () async {
75
+ await assertNoDiagnostics (r'''
76
+ class _O {
77
+ const _O();
78
+ }
79
+
80
+ sealed class E {
81
+ E(_O o);
82
+ }
47
83
''' );
48
84
}
49
85
}
You can’t perform that action at this time.
0 commit comments