in activities.py [0:0]
def validate_item(self, data: CommentedMap, key: str):
item = data[key]
if not isinstance(item, dict):
self.log_error(f"Item '{key}' must be a dictionary.", key)
return
# Validate required fields
if 'issue' not in item:
self.log_error("Missing required 'issue' key.", key)
elif not isinstance(item['issue'], int):
self.log_error(f"'issue' must be an integer, got {item['issue']}.", key)
elif item['issue'] >= 1110:
# Legacy item key restriction for issue numbers >= 1110
for legacy_key in ['position', 'venues']:
if legacy_key in item:
if self.fix:
del item[legacy_key]
else:
self.log_error(f"Legacy key '{legacy_key}' is not allowed for issue numbers >= 1110.", key)
# Validate literal block fields
for field in ['description', 'rationale']:
self.validate_literal_block(data, key, field)
# Optional fields validation
if 'id' in item and (not isinstance(item['id'], str) or ' ' in item['id']):
self.log_error(f"'id' must be a string without whitespace, got {item['id']}.", key)
if 'bug' in item and item['bug'] not in [None, '']:
if not isinstance(item['bug'], str) or not item['bug'].startswith("https://bugzilla.mozilla.org/show_bug.cgi?id="):
self.log_error(f"'bug' must be a URL starting with 'https://bugzilla.mozilla.org/show_bug.cgi?id=', got {item['bug']}.", key)
if 'caniuse' in item and item['caniuse'] not in [None, '']:
if not isinstance(item['caniuse'], str) or not item['caniuse'].startswith("https://caniuse.com/"):
self.log_error(f"'caniuse' must be a URL starting with 'https://caniuse.com/', got {item['caniuse']}.", key)
if 'mdn' in item and item['mdn'] not in [None, '']:
if not isinstance(item['mdn'], str) or not item['mdn'].startswith("https://developer.mozilla.org/en-US/"):
self.log_error(f"'mdn' must be a URL starting with 'https://developer.mozilla.org/en-US/', got {item['mdn']}.", key)
if 'position' in item and item['position'] not in {"positive", "neutral", "negative", "defer", "under consideration"}:
self.log_error(f"'position' must be one of the allowed values, got {item['position']}.", key)
if 'url' in item and not item['url'].startswith("https://"):
self.log_error(f"'url' must start with 'https://', got {item['url']}.", key)
if 'venues' in item:
allowed_venues = {"WHATWG", "W3C", "W3C CG", "IETF", "Ecma", "Unicode", "Proposal", "Other"}
if not isinstance(item['venues'], list) or not set(item['venues']).issubset(allowed_venues):
self.log_error(f"'venues' must be a list with allowed values, got {item['venues']}.", key)