Skip to content

Commit ca08701

Browse files
feat(SolidLintRule): add parameter parsing
refactor: use Map<String, Object?> instead of LintOptions as the enabled field is implicitly true for all rules that the analyzer processes remove RuleConfig as it is no longer needed
1 parent 73d09a5 commit ca08701

5 files changed

Lines changed: 63 additions & 328 deletions

File tree

lib/src/common/parameter_parser/analysis_options_loader.dart

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:analyzer/analysis_rule/rule_context.dart';
22
import 'package:analyzer/file_system/file_system.dart';
33
import 'package:analyzer/file_system/physical_file_system.dart';
44
import 'package:solid_lints/src/common/parameter_parser/cached_package_rules.dart';
5-
import 'package:solid_lints/src/common/parameter_parser/lint_options.dart';
65
import 'package:yaml/yaml.dart';
76

87
/// Loads and parses analysis options from a Dart project's YAML file.
@@ -16,7 +15,7 @@ class AnalysisOptionsLoader {
1615
resourceProvider ?? PhysicalResourceProvider.INSTANCE;
1716

1817
/// Gets the options for a specific rule by its name.
19-
LintOptions? getRuleOptions(RuleContext context, String ruleName) {
18+
Map<String, Object?>? getRuleOptions(RuleContext context, String ruleName) {
2019
final packageRootPath = context.package?.root.path;
2120
if (packageRootPath == null) return null;
2221

@@ -26,16 +25,16 @@ class AnalysisOptionsLoader {
2625
return _rulesCache[yamlPath]?.rules[ruleName];
2726
}
2827

29-
/// Loads lint rules from the analysis options file based
30-
/// on the provided [RuleContext].
31-
void loadRulesFromContext(RuleContext context) {
28+
/// Loads lint rules from the analysis options file for all rules
29+
/// using the provided [RuleContext].
30+
void loadRulesOptionsFromContext(RuleContext context) {
3231
final packageRootPath = context.package?.root.path;
3332
if (packageRootPath == null) return;
3433

35-
_loadRulesIfNewer(packageRootPath);
34+
_loadRulesOptionsIfNewer(packageRootPath);
3635
}
3736

38-
void _loadRulesIfNewer(String rootPath) {
37+
void _loadRulesOptionsIfNewer(String rootPath) {
3938
final yamlPath = _findNearestAnalysisOptionsFilePath(rootPath);
4039
if (yamlPath == null) return;
4140

@@ -74,7 +73,7 @@ class AnalysisOptionsLoader {
7473
return null;
7574
}
7675

77-
Map<String, LintOptions> _getRules(File? analysisOptionsFile) {
76+
Map<String, Map<String, Object?>> _getRules(File? analysisOptionsFile) {
7877
if (analysisOptionsFile == null || !analysisOptionsFile.exists) {
7978
return {};
8079
}
@@ -87,29 +86,19 @@ class AnalysisOptionsLoader {
8786
return {};
8887
}
8988

90-
if (yaml is! Map) return {};
91-
92-
final rules = <String, LintOptions>{};
93-
9489
if (yaml
9590
case {'plugins': {'solid_lints': {'diagnostics': final diagnostics?}}}
9691
when diagnostics is Map) {
97-
for (final MapEntry(:key, :value) in diagnostics.entries) {
98-
if (key is! String) continue;
99-
100-
final ruleName = key;
101-
102-
if (value is bool) {
103-
rules[ruleName] = LintOptions.empty(enabled: value);
104-
} else if (value is Map) {
105-
rules[ruleName] = LintOptions.fromYaml(
106-
Map<String, Object?>.from(value),
107-
enabled: true,
108-
);
109-
}
110-
}
92+
return Map.fromEntries(
93+
diagnostics.entries.where((e) => e.key is String && e.value is Map).map(
94+
(e) => MapEntry(
95+
e.key as String,
96+
Map<String, Object?>.from(e.value as Map),
97+
),
98+
),
99+
);
111100
}
112101

113-
return rules;
102+
return {};
114103
}
115104
}

lib/src/common/parameter_parser/lint_options.dart

Lines changed: 0 additions & 232 deletions
This file was deleted.

lib/src/models/rule_config.dart

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)