Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Unified Diff: lib/src/backend/metadata.dart

Issue 1491383003: Disallow non-hyphenated-identifier tag names. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/src/backend/platform_selector/scanner.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/backend/metadata.dart
diff --git a/lib/src/backend/metadata.dart b/lib/src/backend/metadata.dart
index 0a45aead2a34dff689cbcc1655619f6c93e8d9ea..76681a303c9dd48b3c2ec126ceed10553321e765 100644
--- a/lib/src/backend/metadata.dart
+++ b/lib/src/backend/metadata.dart
@@ -118,7 +118,11 @@ class Metadata {
onPlatform = onPlatform == null
? const {}
: new UnmodifiableMapView(onPlatform),
- tags = tags == null ? new Set() : new UnmodifiableSetView(tags.toSet());
+ tags = tags == null
+ ? new Set()
+ : new UnmodifiableSetView(tags.toSet()) {
+ _validateTags();
+ }
/// Creates a new Metadata, but with fields parsed from caller-friendly values
/// where applicable.
@@ -139,6 +143,8 @@ class Metadata {
throw new ArgumentError(
'"skip" must be a String or a bool, was "$skip".');
}
+
+ _validateTags();
}
/// Deserializes the result of [Metadata.serialize] into a new [Metadata].
@@ -164,6 +170,22 @@ class Metadata {
new Duration(microseconds: serialized['duration']));
}
+ /// Throws an [ArgumentError] if any tags in [tags] aren't hyphenated
+ /// identifiers.
+ void _validateTags() {
+ var invalidTags = tags
+ .where((tag) => !tag.contains(anchoredHyphenatedIdentifier))
+ .map((tag) => '"$tag"')
+ .toList();
+
+ if (invalidTags.isEmpty) return;
+
+ throw new ArgumentError(
+ "Invalid ${pluralize('tag', invalidTags.length)} "
+ "${toSentence(invalidTags)}. Tags must be (optionally hyphenated) "
+ "Dart identifiers.");
+ }
+
/// Return a new [Metadata] that merges [this] with [other].
///
/// If the two [Metadata]s have conflicting properties, [other] wins.
« no previous file with comments | « no previous file | lib/src/backend/platform_selector/scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698