Tighten XCUI schema consistency rules
This commit is contained in:
@@ -569,6 +569,10 @@ bool BuildSchemaAttributeDefinition(
|
||||
Containers::Array<UIDocumentDiagnostic>& diagnostics,
|
||||
Containers::String& inOutErrorMessage) {
|
||||
bool valid = true;
|
||||
bool hasExplicitDocumentKind = false;
|
||||
bool hasExplicitRestrictDocumentKind = false;
|
||||
bool hasExplicitAllowedValues = false;
|
||||
|
||||
if (!node.children.Empty()) {
|
||||
AppendDiagnostic(
|
||||
sourcePath,
|
||||
@@ -640,6 +644,7 @@ bool BuildSchemaAttributeDefinition(
|
||||
const UIDocumentAttribute* documentKindAttribute =
|
||||
FindAttributeByName(node, "documentKind", "kind");
|
||||
if (documentKindAttribute != nullptr && !documentKindAttribute->value.Trim().Empty()) {
|
||||
hasExplicitDocumentKind = true;
|
||||
if (!TryParseDocumentKindValueExtended(documentKindAttribute->value, outDefinition.documentKind)) {
|
||||
AppendDiagnostic(
|
||||
sourcePath,
|
||||
@@ -653,11 +658,23 @@ bool BuildSchemaAttributeDefinition(
|
||||
valid = false;
|
||||
} else if (outDefinition.valueType == UISchemaValueType::Document) {
|
||||
outDefinition.restrictDocumentKind = true;
|
||||
} else {
|
||||
AppendDiagnostic(
|
||||
sourcePath,
|
||||
diagnostics,
|
||||
inOutErrorMessage,
|
||||
UIDocumentDiagnosticSeverity::Error,
|
||||
node.location,
|
||||
Containers::String("Schema attribute '") +
|
||||
outDefinition.name +
|
||||
"' can only declare 'documentKind' for 'document' value types.");
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (const UIDocumentAttribute* restrictDocumentKindAttribute = FindAttributeByName(node, "restrictDocumentKind");
|
||||
restrictDocumentKindAttribute != nullptr && !restrictDocumentKindAttribute->value.Trim().Empty()) {
|
||||
hasExplicitRestrictDocumentKind = true;
|
||||
if (!TryParseBooleanValueExtended(
|
||||
restrictDocumentKindAttribute->value,
|
||||
outDefinition.restrictDocumentKind)) {
|
||||
@@ -671,14 +688,39 @@ bool BuildSchemaAttributeDefinition(
|
||||
restrictDocumentKindAttribute->value +
|
||||
"' for schema attribute 'restrictDocumentKind'.");
|
||||
valid = false;
|
||||
} else if (outDefinition.valueType != UISchemaValueType::Document) {
|
||||
AppendDiagnostic(
|
||||
sourcePath,
|
||||
diagnostics,
|
||||
inOutErrorMessage,
|
||||
UIDocumentDiagnosticSeverity::Error,
|
||||
node.location,
|
||||
Containers::String("Schema attribute '") +
|
||||
outDefinition.name +
|
||||
"' can only declare 'restrictDocumentKind' for 'document' value types.");
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (const UIDocumentAttribute* allowedValuesAttribute = FindAttributeByName(node, "allowedValues", "values");
|
||||
allowedValuesAttribute != nullptr) {
|
||||
hasExplicitAllowedValues = true;
|
||||
outDefinition.allowedValues = ParseAllowedValueList(allowedValuesAttribute->value);
|
||||
}
|
||||
|
||||
if (hasExplicitAllowedValues && outDefinition.valueType != UISchemaValueType::Enum) {
|
||||
AppendDiagnostic(
|
||||
sourcePath,
|
||||
diagnostics,
|
||||
inOutErrorMessage,
|
||||
UIDocumentDiagnosticSeverity::Error,
|
||||
node.location,
|
||||
Containers::String("Schema attribute '") +
|
||||
outDefinition.name +
|
||||
"' can only declare 'allowedValues' for 'enum' value types.");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (outDefinition.valueType == UISchemaValueType::Enum && outDefinition.allowedValues.Empty()) {
|
||||
AppendDiagnostic(
|
||||
sourcePath,
|
||||
@@ -692,6 +734,21 @@ bool BuildSchemaAttributeDefinition(
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (outDefinition.valueType == UISchemaValueType::Document &&
|
||||
outDefinition.restrictDocumentKind &&
|
||||
!hasExplicitDocumentKind) {
|
||||
AppendDiagnostic(
|
||||
sourcePath,
|
||||
diagnostics,
|
||||
inOutErrorMessage,
|
||||
UIDocumentDiagnosticSeverity::Error,
|
||||
node.location,
|
||||
Containers::String("Schema attribute '") +
|
||||
outDefinition.name +
|
||||
"' must declare 'documentKind' when 'restrictDocumentKind' is true.");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user