Skip to content

✅ ValidateStrict

Validates whether composer.json is valid in strict mode. Equivalent to running composer validate --strict.

When to use

Use this when committing code, releasing a tag, or in a CI pipeline to ensure composer.json follows best practices (e.g. field order, required fields). Strict mode is stricter than the regular Validate; any deviation returns a non-zero exit code.

Signature

go
func (c *Composer) ValidateStrict() (string, error)

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return valuestringRaw output of the validation command
Second return valueerrorReturned when validation fails (including when deviations are found)

Example

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.New(composer.DefaultOptions())
	if err != nil {
		log.Fatalf("init failed: %v", err)
	}

	output, err := comp.ValidateStrict()
	if err != nil {
		log.Fatalf("strict validation failed: %v\noutput: %s", err, output)
	}
	fmt.Println("composer.json passed strict validation")
}

Advanced

  • For regular validation, use Validate() (returns only error).
  • For structured results (distinguishing errors / warnings), use ValidateStructured.
  • To only validate the JSON schema, use ValidateSchema.
  • To combine multiple options, use ValidateWithOptions(options).

Released under the MIT License