Skip to content

Commit

Permalink
Reduce casts in false_secrets parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasfj committed Nov 30, 2023
1 parent 3d4a298 commit ffc2f2b
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions lib/src/pubspec_parse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,33 +178,35 @@ abstract class PubspecBase {
/// ignored when trying to detect possible leaks of secrets during
/// package publication.
List<String> get falseSecrets {
if (_falseSecrets == null) {
final falseSecrets = <String>[];

// Throws a [PubspecException]
void falseSecretsError(SourceSpan span) => _error(
'"false_secrets" field must be a list of git-ignore style patterns',
span,
);

final falseSecretsNode = fields.nodes['false_secrets'];
if (falseSecretsNode != null) {
if (falseSecretsNode is YamlList) {
for (final node in falseSecretsNode.nodes) {
final value = node.value;
if (value is! String) {
falseSecretsError(node.span);
}
falseSecrets.add(value as String);
}
} else {
falseSecretsError(falseSecretsNode.span);
}
}
var falseSecrets = _falseSecrets;
if (falseSecrets != null) {
return falseSecrets;
}
falseSecrets = <String>[];

_falseSecrets = List.unmodifiable(falseSecrets);
// Throws a [PubspecException]
Never falseSecretsError(SourceSpan span) => _error(
'"false_secrets" field must be a list of git-ignore style patterns',
span,
);

final falseSecretsNode = fields.nodes['false_secrets'];
if (falseSecretsNode == null) {
return _falseSecrets = List.unmodifiable(falseSecrets);
}
if (falseSecretsNode is! YamlList) {
falseSecretsError(falseSecretsNode.span);
}
return _falseSecrets!;

for (final node in falseSecretsNode.nodes) {
final value = node.value;
if (value is! String) {
falseSecretsError(node.span);
}
falseSecrets.add(value);
}

return _falseSecrets = List.unmodifiable(falseSecrets);
}

List<String>? _falseSecrets;
Expand Down

0 comments on commit ffc2f2b

Please sign in to comment.