|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
| 5 | +import 'package:analyzer/dart/analysis/features.dart'; |
5 | 6 | import 'package:analyzer/dart/analysis/results.dart'; |
6 | 7 | import 'package:analyzer/dart/ast/ast.dart'; |
7 | 8 | import 'package:analyzer/dart/ast/token.dart'; |
@@ -247,6 +248,9 @@ abstract class LinterContext { |
247 | 248 |
|
248 | 249 | TypeSystem get typeSystem; |
249 | 250 |
|
| 251 | + /// Whether the given [feature] is enabled in this linter context. |
| 252 | + bool isFeatureEnabled(Feature feature); |
| 253 | + |
250 | 254 | static bool _isInLibDir(String? filePath, WorkspacePackage? package) { |
251 | 255 | if (package == null) return false; |
252 | 256 | if (filePath == null) return false; |
@@ -298,6 +302,12 @@ final class LinterContextWithParsedResults implements LinterContext { |
298 | 302 | throw UnsupportedError( |
299 | 303 | 'LinterContext with parsed results does not include a TypeSystem', |
300 | 304 | ); |
| 305 | + |
| 306 | + @override |
| 307 | + bool isFeatureEnabled(Feature feature) => |
| 308 | + throw UnsupportedError( |
| 309 | + 'LinterContext with parsed results does not include a LibraryElement', |
| 310 | + ); |
301 | 311 | } |
302 | 312 |
|
303 | 313 | /// A [LinterContext] for a library, resolved into [ResolvedUnitResult]s. |
@@ -347,6 +357,10 @@ final class LinterContextWithResolvedResults implements LinterContext { |
347 | 357 | @override |
348 | 358 | LibraryElement get libraryElement2 => |
349 | 359 | definingUnit.unit.declaredFragment!.element; |
| 360 | + |
| 361 | + @override |
| 362 | + bool isFeatureEnabled(Feature feature) => |
| 363 | + libraryElement2.featureSet.isEnabled(feature); |
350 | 364 | } |
351 | 365 |
|
352 | 366 | /// Provides access to information needed by lint rules that is not available |
|
0 commit comments