Validate
The cem validate command validates your custom-elements.json file against its corresponding JSON schema and provides intelligent warnings for potentially inappropriate manifest content.
cem validate [path/to/custom-elements.json]By default, cem validate will look for a custom-elements.json file in the current directory. You can also provide a path to a different file.
Options
--verbose,-v: Show detailed information including schema version--disable: Disable specific warning rules or categories (can be used multiple times)--format: Output format, eithertext(default) orjson
How it Works
The validate command reads the schemaVersion field from your manifest and fetches the corresponding schema from https://unpkg.com/custom-elements-manifest@<version>/schema.json. Schemas are cached locally for performance.
Schema Validation
If the manifest is valid against the JSON schema, the command will exit with a 0 status code and print a success message. If the manifest is invalid, it will print detailed validation errors with contextual information and exit with a non-zero status code.
Intelligent Warnings
Beyond basic schema validation, cem validate analyzes your manifest for patterns that are technically valid but may indicate issues with your API documentation:
Lifecycle Methods
- Web Components lifecycle:
connectedCallback,disconnectedCallback,attributeChangedCallback,adoptedCallback - Lit Element lifecycle:
firstUpdated,updated,willUpdate,getUpdateComplete,performUpdate,scheduleUpdate,requestUpdate,createRenderRoot - Lit Element render method:
render(only in Lit elements) - Form-associated callbacks:
formAssociatedCallback,formDisabledCallback,formResetCallback,formStateRestoreCallback
Private Methods and Implementation Details
- Private methods: Methods starting with
_or# - Static implementation fields:
styles,shadowRootOptions,formAssociated,observedAttributes - Internal utility methods:
init,destroy,dispose,cleanup,debug,log
Superclass Attribution
- Built-in types: Warns when built-in types like
HTMLElementdon’t have"module": "global:"
Verbose Content
- Large CSS defaults: CSS properties with very long default values
Output Formats
Text Format (Default)
The default text format provides human-readable output with colors and formatting.
JSON Format
Use --format json to get machine-readable output suitable for CI/CD pipelines and tooling:
cem validate --format json custom-elements.jsonJSON output structure:
{
"valid": true,
"path": "custom-elements.json",
"schemaVersion": "2.1.1",
"errors": [
{
"id": "schema-required-property",
"module": "my-element.js",
"declaration": "class MyElement",
"message": "required property 'name' is missing",
"location": "/modules/0/declarations/0"
}
],
"warnings": [
{
"id": "lifecycle-lit-render",
"module": "my-element.js",
"declaration": "class MyElement",
"member": "method render",
"message": "render method in Lit element should not be documented in public API",
"category": "lifecycle"
}
]
}Configuration
You can disable specific warning rules using configuration or command-line flags:
Configuration File
# .cem.yaml
warnings:
disable:
# Disable entire categories
- lifecycle
- private
- implementation
# Or disable specific rules
- lifecycle-lit-render
- implementation-static-styles
- private-underscore-methodsCommand Line
# Disable entire categories
cem validate --disable lifecycle --disable private
# Disable specific rules
cem validate --disable lifecycle-lit-render --disable implementation-static-styles
# Combine with JSON output
cem validate --format json --disable lifecycleThe --disable flag can be used multiple times and will be merged with any disabled rules from your configuration file.
Available Warning Categories
lifecycle- All lifecycle method warningsprivate- Private method warnings (underscore and hash prefixed)implementation- Implementation detail warnings (static fields)superclass- Superclass attribution warningsverbose- Verbose content warningsinternal- Internal utility method warnings
Specific Warning Rule IDs
Lifecycle Rules
lifecycle-web-components- Web Components lifecycle methodslifecycle-lit-methods- Lit Element lifecycle methodslifecycle-lit-render- Lit Element render methodlifecycle-constructor- Constructor methodlifecycle-form-callbacks- Form-associated element callbacks
Private Method Rules
private-underscore-methods- Methods starting with_private-hash-methods- Methods starting with#
Implementation Detail Rules
implementation-static-styles- Static styles fieldimplementation-shadow-root-options- shadowRootOptions fieldimplementation-form-associated- formAssociated fieldimplementation-observed-attributes- observedAttributes field
Other Rules
superclass-builtin-modules- Built-in superclass module attributionverbose-css-defaults- Large CSS property defaultsinternal-utility-methods- Internal utility methods
Schema Validation Error IDs
Schema validation errors also include unique IDs for programmatic handling:
schema-required-property- Missing required propertyschema-additional-properties- Unexpected additional propertyschema-invalid-enum- Invalid enum valueschema-invalid-kind- Invalid declaration kindschema-invalid-type- Wrong data typeschema-invalid-format- Invalid format (e.g., URI, email)schema-invalid-pattern- String doesn’t match required patternschema-value-too-small- Number below minimumschema-value-too-large- Number above maximumschema-string-too-short- String shorter than minLengthschema-string-too-long- String longer than maxLengthschema-array-too-short- Array shorter than minItemsschema-array-too-long- Array longer than maxItemsschema-duplicate-items- Array contains duplicate itemsschema-validation-error- Generic validation error