kanopi/drupal-sdc-validator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kanopi/drupal-sdc-validator

Composer 安装命令:

composer require kanopi/drupal-sdc-validator

包简介

CLI tool to validate Drupal Single Directory Component (.component.yml) files.

README 文档

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.yml files 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-schemas flag 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 props are valid (matches Drupal theme behavior)
  • Components with props are validated against the schema

Strict Mode (--enforce-schemas)

  • All components must have props defined (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

统计信息

  • 总下载量: 5.09k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固