@@ -8,20 +8,18 @@ import 'package:yaml/yaml.dart';
88
99/// Loads and parses analysis options from a Dart project's YAML file.
1010class AnalysisOptionsLoader {
11- Map <String , LintOptions > _rulesCache = {};
12-
13- /// Retrieves the currently loaded lint rules.
14- Map <String , LintOptions > get rules => _rulesCache;
11+ final Map <String , Map <String , LintOptions >> _rulesCache = {};
1512
1613 /// Gets the options for a specific rule by its name.
17- LintOptions ? getRuleOptions (String ruleName) => _rulesCache[ruleName];
14+ LintOptions ? getRuleOptions (RuleContext context, String ruleName) {
15+ final yamlPath = _findNearestFileUpwards (context.allUnits.first.file.path);
16+ if (yamlPath == null ) return null ;
17+ return _rulesCache[yamlPath]? [ruleName];
18+ }
1819
1920 /// Loads lint rules from the analysis options file based
2021 /// on the provided [RuleContext] .
2122 void loadRulesFromContext (RuleContext context) {
22- if (_rulesCache.isNotEmpty) {
23- return ;
24- }
2523 if (context.allUnits.isEmpty) {
2624 return ;
2725 }
@@ -36,10 +34,14 @@ class AnalysisOptionsLoader {
3634 return ;
3735 }
3836
37+ if (_rulesCache.containsKey (yamlPath)) {
38+ return ;
39+ }
40+
3941 final file = PhysicalResourceProvider .INSTANCE .getFile (yamlPath);
4042
4143 final rules = _getRules (file);
42- _rulesCache = rules;
44+ _rulesCache[yamlPath] = rules;
4345 }
4446
4547 String ? _findNearestFileUpwards (
0 commit comments