kanopi / drupal-sdc-validator
CLI tool to validate Drupal Single Directory Component (.component.yml) files.
Installs: 158
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/kanopi/drupal-sdc-validator
Requires
- php: >=8.1
- justinrainbow/json-schema: ^5.2 || ^6.0
- symfony/yaml: ^6.0 || ^7.0
README
A CLI tool to validate Drupal Single Directory Component (SDC) .component.yml files for structure and schema compliance.
This validator helps you ensure your SDC metadata files follow the Drupal core schema, and reports any missing fields, invalid structures, or schema violations.
๐ Features
- โ
Validates
.component.ymlfiles recursively in any path - โ
Validates against Drupal core's
metadata-full.schema.json - โ Checks for name collisions between props and slots
- โ Validates non-string property types
- โ Supports class/interface type validation (like Drupal core)
- โ
Optional
--enforce-schemasflag for strict validation - โ
JSON Schema validation via
justinrainbow/json-schema - โ
Works as a Composer-installed CLI tool (
vendor/bin/validate-sdc) - โ Caches remote schema for 24 hours for faster re-runs
- โ Error messages match Drupal core's ComponentValidator format
๐งฉ Installation
composer require --dev kanopi/drupal-sdc-validator
๐ Usage
Basic Usage
Validate components in one or more directories:
# Single directory vendor/bin/validate-sdc web/themes/custom/your_theme/components # Multiple directories vendor/bin/validate-sdc web/themes/custom/theme1/components web/modules/custom/module1/components
Enforce Schema Validation
Use the --enforce-schemas flag to require schema definitions (similar to Drupal modules):
vendor/bin/validate-sdc web/modules/custom/your_module/components --enforce-schemas
This will fail validation if any component is missing a props schema definition.
Validation Modes
Default (Lenient Mode)
- Components without
propsare valid (matches Drupal theme behavior) - Components with
propsare validated against the schema
Strict Mode (--enforce-schemas)
- All components must have
propsdefined (matches Drupal module behavior) - Use this for module components or when you want strict validation
Example Output
web/themes/custom/mytheme/components/button/button.component.yml has validation errors:
โข The component "button" declared [variant] both as a prop and as a slot. Make sure to use different names.
โข [props.properties.size.type] The property type must be a string.
============================================================
โ Validation failed!
Total files checked: 15
Files with errors: 1
๐ Validation Rules
This validator implements the same validation logic as Drupal core's ComponentValidator:
Name Collision Detection
Checks that props and slots don't share the same names.
Non-String Type Validation
Ensures all property types are declared as strings (not integers, booleans, etc.).
Class/Interface Type Support
Validates custom class/interface types exist in the codebase (e.g., Drupal\Core\Url).
Schema Enforcement
With --enforce-schemas, requires all components to have prop schemas defined.
Empty Properties Handling
Properly handles empty properties: {} declarations.
๐งช Integration with Your Project
Add Composer Scripts
Once installed, add these scripts to your project's composer.json for easy access:
{
"scripts": {
"validate-sdc": [
"@php vendor/bin/validate-sdc web/themes/custom"
],
"validate-sdc-enforce": [
"@php vendor/bin/validate-sdc web/themes/custom --enforce-schemas"
]
}
}
Then run:
# Lenient mode (themes) composer validate-sdc # Strict mode (modules) composer validate-sdc-enforce
Note: Using @php ensures exit codes are properly propagated, making validation failures fail CI/CD pipelines.
๐ License
MIT