validate

package
v0.9.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Copyright © 2025 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const DefaultLengthThreshold = 200

Default value length threshold for warnings (applies to all default values)

Variables

This section is empty.

Functions

func GetSchema added in v0.5.0

func GetSchema(version string) ([]byte, error)

GetSchema returns the JSON schema for a given version, using embedded schemas and falling back to fetching from external sources if needed

func PrintValidationResult

func PrintValidationResult(manifestPath string, result *ValidationResult, options DisplayOptions) error

PrintValidationResult prints the validation result with appropriate formatting

Types

type Context

type Context struct {
	Type          string // "module", "declaration", "member", "property"
	ModuleIndex   int
	DeclIndex     int
	MemberIndex   int
	PropertyIndex int
	PropertyType  string // "attributes", "events", etc.
}

Context represents the parsing context for validation issues

func ParseContext

func ParseContext(location string) Context

ParseContext extracts context information from a JSON path

type DisplayOptions

type DisplayOptions struct {
	Verbose bool
	Format  string
}

type ErrorIDRegistry

type ErrorIDRegistry struct {
	// contains filtered or unexported fields
}

ErrorIDRegistry provides centralized error ID assignment

func NewErrorIDRegistry

func NewErrorIDRegistry() *ErrorIDRegistry

NewErrorIDRegistry creates a new error ID registry

func (*ErrorIDRegistry) AssignID

func (r *ErrorIDRegistry) AssignID(message, location string) string

AssignID assigns an appropriate error ID based on the message and location

type ErrorProcessor

type ErrorProcessor struct {
	// contains filtered or unexported fields
}

ErrorProcessor handles the parsing and processing of validation errors

func NewErrorProcessor

func NewErrorProcessor(navigator *ManifestNavigator) *ErrorProcessor

NewErrorProcessor creates a new error processor

func (*ErrorProcessor) ProcessValidationError

func (p *ErrorProcessor) ProcessValidationError(cause *jsonschema.ValidationError, location string) ValidationError

ProcessValidationError processes a JSON schema validation error into structured errors

type GroupedIssues

type GroupedIssues struct {
	Module      string
	Declaration string
	Issues      []ValidationError
}

type GroupedWarnings

type GroupedWarnings struct {
	Module      string
	Declaration string
	Warnings    []ValidationWarning
}

type ImplementationDetailsRule

type ImplementationDetailsRule struct{}

ImplementationDetailsRule checks for implementation details in public API

func (*ImplementationDetailsRule) Category

func (r *ImplementationDetailsRule) Category() string

func (*ImplementationDetailsRule) Check

func (*ImplementationDetailsRule) ID

type InternalMethodsRule

type InternalMethodsRule struct{}

InternalMethodsRule checks for internal utility methods

func (*InternalMethodsRule) Category

func (r *InternalMethodsRule) Category() string

func (*InternalMethodsRule) Check

func (*InternalMethodsRule) ID

func (r *InternalMethodsRule) ID() string

type LifecycleMethodsRule

type LifecycleMethodsRule struct{}

LifecycleMethodsRule checks for documented lifecycle methods

func (*LifecycleMethodsRule) Category

func (r *LifecycleMethodsRule) Category() string

func (*LifecycleMethodsRule) Check

func (*LifecycleMethodsRule) ID

func (r *LifecycleMethodsRule) ID() string

type ManifestNavigator

type ManifestNavigator struct {
	// contains filtered or unexported fields
}

ManifestNavigator provides type-safe navigation through manifest data

func NewManifestNavigator

func NewManifestNavigator(manifest map[string]any) *ManifestNavigator

NewManifestNavigator creates a new navigator for the given manifest

func (*ManifestNavigator) BuildContextualNames

func (n *ManifestNavigator) BuildContextualNames(ctx Context) (module, declaration, member, property string)

BuildContextualNames builds human-readable names for validation issues

func (*ManifestNavigator) DeclMemberAtIndex added in v0.2.16

func (n *ManifestNavigator) DeclMemberAtIndex(moduleIndex, declIndex, memberIndex int) (RawMember, bool)

DeclMemberAtIndex returns the member at the given indices

func (*ManifestNavigator) DeclPropertyAtIndex added in v0.2.16

func (n *ManifestNavigator) DeclPropertyAtIndex(moduleIndex, declIndex, propIndex int, propType string) (RawProperty, bool)

DeclPropertyAtIndex returns the property at the given indices for the specified property type

func (*ManifestNavigator) ModuleAtIndex added in v0.2.16

func (n *ManifestNavigator) ModuleAtIndex(index int) (RawModule, bool)

ModuleAtIndex returns the module at the given index

func (*ManifestNavigator) ModuleDeclarationAtIndex added in v0.2.16

func (n *ManifestNavigator) ModuleDeclarationAtIndex(moduleIndex, declIndex int) (RawDeclaration, bool)

ModuleDeclarationAtIndex returns the declaration at the given module and declaration indices

type PrivateMethodsRule

type PrivateMethodsRule struct{}

PrivateMethodsRule checks for private methods

func (*PrivateMethodsRule) Category

func (r *PrivateMethodsRule) Category() string

func (*PrivateMethodsRule) Check

func (*PrivateMethodsRule) ID

func (r *PrivateMethodsRule) ID() string

type RawDeclaration

type RawDeclaration map[string]any

func (RawDeclaration) Attributes added in v0.2.16

func (d RawDeclaration) Attributes() ([]RawProperty, bool)

func (RawDeclaration) CSSParts added in v0.2.16

func (d RawDeclaration) CSSParts() ([]RawProperty, bool)

func (RawDeclaration) CSSProperties added in v0.2.16

func (d RawDeclaration) CSSProperties() ([]RawProperty, bool)

func (RawDeclaration) CSSStates added in v0.2.16

func (d RawDeclaration) CSSStates() ([]RawProperty, bool)

func (RawDeclaration) Demos added in v0.9.5

func (d RawDeclaration) Demos() ([]RawDemo, bool)

func (RawDeclaration) Description added in v0.9.5

func (d RawDeclaration) Description() string

func (RawDeclaration) Events added in v0.2.16

func (d RawDeclaration) Events() ([]RawProperty, bool)

func (RawDeclaration) IsCustomElement added in v0.9.5

func (d RawDeclaration) IsCustomElement() bool

func (RawDeclaration) Kind added in v0.2.16

func (d RawDeclaration) Kind() string

func (RawDeclaration) Members added in v0.2.16

func (d RawDeclaration) Members() ([]RawMember, bool)

func (RawDeclaration) Name added in v0.2.16

func (d RawDeclaration) Name() string

func (RawDeclaration) Slots added in v0.2.16

func (d RawDeclaration) Slots() ([]RawProperty, bool)

func (RawDeclaration) Summary added in v0.9.5

func (d RawDeclaration) Summary() string

func (RawDeclaration) Superclass added in v0.2.16

func (d RawDeclaration) Superclass() (RawSuperclass, bool)

func (RawDeclaration) TagName added in v0.9.5

func (d RawDeclaration) TagName() string

type RawDemo added in v0.9.5

type RawDemo map[string]any

func (RawDemo) Description added in v0.9.5

func (d RawDemo) Description() string

func (RawDemo) URL added in v0.9.5

func (d RawDemo) URL() string

type RawManifest

type RawManifest map[string]any

Raw types represent the untyped JSON manifest data

func (RawManifest) Modules added in v0.2.16

func (m RawManifest) Modules() ([]RawModule, bool)

type RawMember

type RawMember map[string]any

func (RawMember) Default added in v0.2.16

func (m RawMember) Default() string

func (RawMember) Description added in v0.9.5

func (m RawMember) Description() string

func (RawMember) IsStatic

func (m RawMember) IsStatic() bool

func (RawMember) Kind added in v0.2.16

func (m RawMember) Kind() string

func (RawMember) Name added in v0.2.16

func (m RawMember) Name() string

func (RawMember) Privacy added in v0.2.16

func (m RawMember) Privacy() string

func (RawMember) Type added in v0.9.5

func (m RawMember) Type() string

type RawModule

type RawModule map[string]any

func (RawModule) Declarations added in v0.2.16

func (m RawModule) Declarations() ([]RawDeclaration, bool)

func (RawModule) Path added in v0.2.16

func (m RawModule) Path() string

type RawProperty

type RawProperty map[string]any

func (RawProperty) Default added in v0.2.16

func (p RawProperty) Default() string

func (RawProperty) Description added in v0.9.5

func (p RawProperty) Description() string

func (RawProperty) Name added in v0.2.16

func (p RawProperty) Name() string

func (RawProperty) Type added in v0.9.5

func (p RawProperty) Type() string

type RawSuperclass

type RawSuperclass map[string]any

func (RawSuperclass) Module added in v0.2.16

func (s RawSuperclass) Module() string

func (RawSuperclass) Name added in v0.2.16

func (s RawSuperclass) Name() string

func (RawSuperclass) Package added in v0.9.1

func (s RawSuperclass) Package() string

type SuperclassRule

type SuperclassRule struct{}

SuperclassRule checks for superclass attribution warnings

func (*SuperclassRule) Category

func (r *SuperclassRule) Category() string

func (*SuperclassRule) Check

func (*SuperclassRule) ID

func (r *SuperclassRule) ID() string

type ValidationError

type ValidationError struct {
	ID          string `json:"id"` // Unique identifier for this error type
	Module      string `json:"module,omitempty"`
	Declaration string `json:"declaration,omitempty"`
	Member      string `json:"member,omitempty"`
	Property    string `json:"property,omitempty"`
	Message     string `json:"message"`
	Location    string `json:"location,omitempty"`
	Index       int    `json:"index,omitempty"` // For array items
}

type ValidationOptions

type ValidationOptions struct {
	IncludeWarnings bool
	DisabledRules   []string
}

type ValidationPipeline

type ValidationPipeline struct {
	// contains filtered or unexported fields
}

ValidationPipeline orchestrates the validation process

func NewValidationPipeline

func NewValidationPipeline(manifestData []byte) (*ValidationPipeline, error)

NewValidationPipeline creates a new validation pipeline

func (*ValidationPipeline) Validate

Validate performs the complete validation process

type ValidationResult

type ValidationResult struct {
	IsValid       bool                `json:"valid"`
	Path          string              `json:"path,omitempty"`
	SchemaVersion string              `json:"schemaVersion,omitempty"`
	Errors        []ValidationError   `json:"errors"`
	Warnings      []ValidationWarning `json:"warnings"`
}

func Validate

func Validate(manifestPath string, options ValidationOptions) (*ValidationResult, error)

Validate validates a custom-elements.json manifest

type ValidationWarning

type ValidationWarning struct {
	ID          string `json:"id"` // Unique identifier for this warning rule
	Module      string `json:"module,omitempty"`
	Declaration string `json:"declaration,omitempty"`
	Member      string `json:"member,omitempty"`
	Property    string `json:"property,omitempty"`
	Message     string `json:"message"`
	Category    string `json:"category"` // "lifecycle", "private", "verbose", etc.
}

type VerboseDefaultsRule

type VerboseDefaultsRule struct{}

VerboseDefaultsRule checks for overly verbose default values in all property types

func (*VerboseDefaultsRule) Category

func (r *VerboseDefaultsRule) Category() string

func (*VerboseDefaultsRule) Check

func (*VerboseDefaultsRule) ID

func (r *VerboseDefaultsRule) ID() string

type WarningContext

type WarningContext struct {
	Navigator    *ManifestNavigator
	Module       RawModule
	Declaration  RawDeclaration
	Member       RawMember
	Property     RawProperty
	ModulePath   string
	DeclName     string
	DeclKind     string
	IsLitElement bool
}

WarningContext provides context for warning rule evaluation

type WarningProcessor

type WarningProcessor struct {
	// contains filtered or unexported fields
}

WarningProcessor processes warnings using registered rules

func NewWarningProcessor

func NewWarningProcessor() *WarningProcessor

NewWarningProcessor creates a new warning processor with default rules

func (*WarningProcessor) ProcessWarnings

func (p *WarningProcessor) ProcessWarnings(navigator *ManifestNavigator) []ValidationWarning

ProcessWarnings processes all warnings for a manifest

func (*WarningProcessor) RegisterRule

func (p *WarningProcessor) RegisterRule(rule WarningRule)

RegisterRule adds a warning rule to the processor

type WarningRule

type WarningRule interface {
	Check(ctx *WarningContext) []ValidationWarning
	ID() string
	Category() string
}

WarningRule interface for all warning rules

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL