auditEntryPointRules function
List<SeamViolation>
auditEntryPointRules(
- String root,
- List<
EntryPointRule> rules, { - required String seam,
Checks every rule in rules against the packages under root, reporting
each crossing under seam.
A declared entry point that does not exist is a violation rather than a pass: a renamed or deleted entry point must fail here, not pass by having nothing to walk.
Implementation
List<SeamViolation> auditEntryPointRules(
String root,
List<EntryPointRule> rules, {
required String seam,
}) {
final violations = <SeamViolation>[];
for (final rule in rules) {
final file = p.join(root, rule.package, rule.entryPoint);
if (!File(file).existsSync()) {
// A renamed or deleted entry point must fail here rather than pass by
// having nothing to walk.
violations.add(
SeamViolation(
seam,
'${rule.package}: declared entry point ${rule.entryPoint} does not '
'exist — the rule cannot be checked, so it is a violation.',
),
);
continue;
}
final uris = externalImportsOf(file);
for (final banned in rule.bannedUris) {
if (uris.contains(banned)) {
violations.add(
SeamViolation(
seam,
'${rule.package}/${rule.entryPoint} reaches "$banned". The package '
'is permitted; that entry point of it is not.',
),
);
}
}
final names = reachableNamesOf(file);
for (final banned in rule.banned) {
if (names.contains(banned)) {
violations.add(
SeamViolation(
seam,
'${rule.package}/${rule.entryPoint} reaches "$banned", which that '
'entry point must not link.',
),
);
}
}
for (final needed in rule.required) {
if (!names.contains(needed)) {
violations.add(
SeamViolation(
seam,
'${rule.package}/${rule.entryPoint} no longer reaches "$needed" — '
'the seam it exists to expose is gone, so the matching ban '
'elsewhere now passes vacuously.',
),
);
}
}
}
return violations;
}