forked from dart-code-checker/dart-code-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_parser.dart
40 lines (34 loc) · 1.1 KB
/
config_parser.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
part of '../avoid_banned_imports_rule.dart';
const _entriesLabel = 'entries';
const _pathsLabel = 'paths';
const _denyLabel = 'deny';
const _messageLabel = 'message';
/// Parser for rule configuration.
class _ConfigParser {
static List<_AvoidBannedImportsConfigEntry> _parseEntryConfig(
Map<String, Object> config,
) =>
(config[_entriesLabel] as Iterable<Object?>? ?? []).map((entry) {
final entryMap = entry as Map<Object?, Object?>;
return _AvoidBannedImportsConfigEntry(
paths: _parseListRegExp(entryMap[_pathsLabel]),
deny: _parseListRegExp(entryMap[_denyLabel]),
message: entryMap[_messageLabel] as String,
);
}).toList();
static List<RegExp> _parseListRegExp(Object? object) =>
(object! as List<Object?>)
.map((e) => e! as String)
.map((e) => RegExp(e))
.toList();
}
class _AvoidBannedImportsConfigEntry {
final List<RegExp> paths;
final List<RegExp> deny;
final String message;
_AvoidBannedImportsConfigEntry({
required this.paths,
required this.deny,
required this.message,
});
}