go: cuelang.org/go/tools/trim Index | Files

package trim

import "cuelang.org/go/tools/trim"

Package trim removes definitions that may be inferred from templates.

A field, struct, or list is removed if it is implied by a constraint, such as from an optional field matching a required field, a list type value, a comprehension or any other implied content. It will modify the files in place.

Limitations

Removal is on a best effort basis. Some caveats: - Fields in implied content may refer to fields within the struct in which

they are included, but are only resolved on a best-effort basis.

- Disjunctions that contain structs in implied content cannot be used to

remove fields.

- There is currently no verification step: manual verification is required.

Examples:

light: [string]: {
	room:          string
	brightnessOff: *0.0 | >=0 & <=100.0
	brightnessOn:  *100.0 | >=0 & <=100.0
}

light: ceiling50: {
	room:          "MasterBedroom"
	brightnessOff: 0.0    // this line
	brightnessOn:  100.0  // and this line will be removed
}

Results in:

light: [string]: {
	room:          string
	brightnessOff: *0.0 | >=0 & <=100.0
	brightnessOn:  *100.0 | >=0 & <=100.0
}

light: ceiling50: {
	room: "MasterBedroom"
}

Index

Package Files

trim.go

func Files Uses

func Files(files []*ast.File, inst *cue.Instance, cfg *Config) error

Files trims fields in the given files that can be implied from other fields, as can be derived from the evaluated values in inst. Trimming is done on a best-effort basis and only when the removed field is clearly implied by another field, rather than equal sibling fields.

type Config Uses

type Config struct {
    Trace bool
}

Config configures trim options.

type Runtime Uses

type Runtime = cue.Runtime

Package trim imports 8 packages (graph) and is imported by 2 packages. Updated 2020-09-28. Refresh now. Tools for package owners.