File tree Expand file tree Collapse file tree 2 files changed +62
-2
lines changed
packages/custom_lint_core Expand file tree Collapse file tree 2 files changed +62
-2
lines changed Original file line number Diff line number Diff line change @@ -250,9 +250,13 @@ class _PackageChecker extends TypeChecker {
250
250
@override
251
251
bool isExactly (Element element) {
252
252
final elementLibraryIdentifier = element.library? .identifier;
253
+ if (elementLibraryIdentifier == null ) return false ;
254
+
255
+ if (_packageName.startsWith ('dart:' )) {
256
+ return elementLibraryIdentifier == _packageName || elementLibraryIdentifier.startsWith ('$_packageName /' );
257
+ }
253
258
254
- return elementLibraryIdentifier != null &&
255
- elementLibraryIdentifier.startsWith ('package:$_packageName /' );
259
+ return elementLibraryIdentifier.startsWith ('package:$_packageName /' );
256
260
}
257
261
258
262
@override
Original file line number Diff line number Diff line change @@ -121,6 +121,62 @@ environment:
121
121
false ,
122
122
);
123
123
});
124
+
125
+ test ('matches a type from a built-in dart: package' , () async {
126
+ final file = writeToTemporaryFile ('''
127
+ import 'dart:io';
128
+
129
+ int a;
130
+ File? x;
131
+ ''' );
132
+
133
+ final unit = await resolveFile2 (path: file.path);
134
+ unit as ResolvedUnitResult ;
135
+
136
+ const checker = TypeChecker .fromPackage ('dart:core' );
137
+ const checker2 = TypeChecker .fromPackage ('dart:io' );
138
+ const checker3 = TypeChecker .fromPackage ('some_package' );
139
+
140
+ expect (
141
+ checker.isExactlyType (
142
+ (unit.unit.declarations.first as TopLevelVariableDeclaration )
143
+ .variables
144
+ .type!
145
+ .type! ,
146
+ ),
147
+ true ,
148
+ );
149
+
150
+ expect (
151
+ checker.isExactlyType (
152
+ (unit.unit.declarations[1 ] as TopLevelVariableDeclaration )
153
+ .variables
154
+ .type!
155
+ .type! ,
156
+ ),
157
+ false ,
158
+ );
159
+
160
+ expect (
161
+ checker2.isExactlyType (
162
+ (unit.unit.declarations[1 ] as TopLevelVariableDeclaration )
163
+ .variables
164
+ .type!
165
+ .type! ,
166
+ ),
167
+ true ,
168
+ );
169
+
170
+ expect (
171
+ checker3.isExactlyType (
172
+ (unit.unit.declarations.first as TopLevelVariableDeclaration )
173
+ .variables
174
+ .type!
175
+ .type! ,
176
+ ),
177
+ false ,
178
+ );
179
+ });
124
180
});
125
181
}
126
182
You can’t perform that action at this time.
0 commit comments