-
-
Notifications
You must be signed in to change notification settings - Fork 6
Description
As per #95, consider JSON Schema and perhaps runtime validation.
AI prompts:
Create a JSON Schema file (schema.json) for html-minifier-next that defines all configuration options found in src/htmlminifier.js (lines 691-814 in the
processOptionsfunction). The schema should include type definitions, descriptions, default values, and validation rules for each option (likecollapseWhitespace,removeComments,sortAttributes,sortClassName,minifyJS,minifyCSS,maxLineLength, etc.). Use JSON Schema Draft 7 format. Then update package.json to register this schema by adding ajsonSchemasarray that maps the schema to common config filenames like .htmlminifierrc, .htmlminifierrc.json, and htmlminifier.config.json. This will enable IDE autocomplete, inline documentation, and validation for users writing configuration files.
Add runtime configuration validation to html-minifier-next using the existing schema.json file. Create a new module src/validate-config.js that uses the Ajv library to validate configuration objects against the schema, throwing descriptive errors when validation fails. Add ajv (^8.12.0) to package.json dependencies. Then modify the
minifyfunction in src/htmlminifier.js (around line 1454) to callvalidateConfig(options)before processing options, catching configuration errors early with clear error messages that show which options are invalid and why. The validator should handle all errors from Ajv and format them in a user-friendly way, showing the path to the invalid option and what's wrong with it.