Skip to content

Consider JSON Schema #96

@j9t

Description

@j9t

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 processOptions function). The schema should include type definitions, descriptions, default values, and validation rules for each option (like collapseWhitespace, removeComments, sortAttributes, sortClassName, minifyJS, minifyCSS, maxLineLength, etc.). Use JSON Schema Draft 7 format. Then update package.json to register this schema by adding a jsonSchemas array 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 minify function in src/htmlminifier.js (around line 1454) to call validateConfig(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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions