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 {
250250 @override
251251 bool isExactly (Element element) {
252252 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+ }
253258
254- return elementLibraryIdentifier != null &&
255- elementLibraryIdentifier.startsWith ('package:$_packageName /' );
259+ return elementLibraryIdentifier.startsWith ('package:$_packageName /' );
256260 }
257261
258262 @override
Original file line number Diff line number Diff line change @@ -121,6 +121,62 @@ environment:
121121 false ,
122122 );
123123 });
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+ });
124180 });
125181}
126182
You can’t perform that action at this time.
0 commit comments