module

package
v0.3.16 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 26 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package module reads an author's module and checks it as the module format says: its layout and the format version it names, each file by the YAML rules and against the schema of its part, and the format rules within each part, between parts and of the whole module — the tiers of the skill graph, the templates with every instance and solver, the leak check of the texts a learner sees before solving, and the page of a workbook. A breach names the ID of its rule and its place, and a warning of a report refuses nothing (R50). The CLI's check and build call it, and module-registry from stage 4.

Check runs the solvers of a module's templates one on each CPU, with the caller's context, and CheckModule gives the numbers of their instances to the build of a package, so that each solver runs once (R38).

Index

Examples

Constants

View Source
const (
	RuleManifest      = "module.manifest"
	RuleLayout        = "module.layout"
	RuleFileIDs       = "module.file-ids"
	RuleMedia         = "module.media"
	RuleLicense       = "module.license"
	RulePlainText     = "module.plain-text"
	RuleFormatVersion = "manifest.format-version"
)

The rules of a module's folder and of its format version, as a breach names them in Rule.

View Source
const (
	RuleTaskChoiceKey           = "task.choice-key"
	RuleTaskChoiceOptions       = "task.choice-options"
	RuleTaskFractionKey         = "task.fraction-key"
	RuleTaskTrapValues          = "task.trap-values"
	RuleTaskPredicateExpression = "task.predicate-expression"
)

The rules of a task that the check of an answer slot sees itself (R27, R28).

View Source
const (
	RuleTaskNoLeaks   = "task.no-leaks"
	RuleLessonNoLeaks = "lesson.no-leaks"
)

The IDs of the rules of the leak check on the texts of a module (R30).

View Source
const (
	RuleManifestDependencies  = "manifest.dependencies"
	RuleManifestBands         = "manifest.bands"
	RuleManifestRungTemplates = "manifest.rung-templates"
	RuleSkillGraphAcyclic     = "skill-graph.acyclic"
	RuleSkillGraphKnownSkills = "skill-graph.known-skills"
	RuleSkillGraphRetiredIDs  = "skill-graph.retired-ids"
	RuleSkillGraphOwnAnchors  = "skill-graph.own-anchors"
	RuleTrapsKnownSkills      = "traps.known-skills"
	RuleTaskKnownTraps        = "task.known-traps"
	RuleTaskKnownTechniques   = "task.known-techniques"
)

The IDs of the rules of the manifest, the skill graph and the catalogs, named by the part a breach of each is reported in (R25).

View Source
const (
	RuleTaskKnownSkills     = "task.known-skills"
	RuleTaskSkillRoles      = "task.skill-roles"
	RuleTaskOwnAnchors      = "task.own-anchors"
	RuleTaskKnownBand       = "task.known-band"
	RuleTaskKnownPictures   = "task.known-pictures"
	RuleTaskAgeCategories   = "task.age-categories"
	RuleTaskZones           = "task.zones"
	RuleTaskAssessability   = "task.assessability"
	RuleLessonKnownSkills   = "lesson.known-skills"
	RuleLessonKnownTasks    = "lesson.known-tasks"
	RuleLessonTaskSkills    = "lesson.task-skills"
	RuleLessonKnownPictures = "lesson.known-pictures"
	RuleLessonAreas         = "lesson.areas"
	RuleLessonAgeCategories = "lesson.age-categories"
	RuleLessonOrder         = "lesson.order"
)

The IDs of the rules of a task and of a lesson that need no check kind, no leak check and no template (R26).

View Source
const (
	RuleTaskTemplateNames       = template.RuleNames
	RuleTaskTemplateExpressions = template.RuleExpressions
	RuleTaskPlaceholders        = template.RulePlaceholders
	RuleTaskTemplateInstances   = template.RuleInstances
	RuleTaskTemplateSolver      = template.RuleSolver
	RuleTaskInstances           = "task.instances"
)

The IDs of the rules of templates: those that a template breaks by itself, which package template reads, and task.instances, which holds each of its instances to the schema of a task (R32, R33).

View Source
const (
	RuleTaskWorkbookPage   = "task.workbook-page"
	RuleLessonExampleFills = "lesson.example-fills"
	RuleLessonWorkbookPage = "lesson.workbook-page"
)

The IDs of the rules of a workbook's page and of a worked example on a workbook (R52).

View Source
const FormatVersion = "0.4"

FormatVersion is the version of the module format that this library reads: the version of the schemas that internal/schema holds, a copy of those of spec.Format, and of the test vectors (R23). While the format is v0, it is the one version the library reads (R22, R52).

Variables

This section is empty.

Functions

func NewerFormat added in v0.1.22

func NewerFormat(v string) bool

NewerFormat says whether v, a format version MAJOR.MINOR, is newer than FormatVersion: by its major number, then its minor, each by its value, so that 0.10 is newer than 0.9. A v that is no version MAJOR.MINOR is newer than none. The build of the module index reads a previous index by it (R35).

func ReadsFormat

func ReadsFormat(v string) bool

ReadsFormat says whether the library reads a module written in the format version v, as a manifest names it in module_format_version: while the format is v0, only FormatVersion.

func Tiers added in v0.1.12

Tiers gives the tier of each skill of a skill graph: tier 1 for a skill with no prerequisite among the module's skills, and one tier above the highest of its prerequisites among them for every other, so that an anchor skill counts for none. The package holds them in its canonical view, as skill_tiers. A graph whose prerequisites name a skill that it does not have, or run in a cycle, has no tiers: it breaks skill-graph.known-skills or skill-graph.acyclic, and Tiers gives an error.

Types

type Breach

type Breach struct {
	Rule string
	// The keyword of JSON Schema 2020-12 that fails, such as required or pattern, when the breach is
	// of the schema; its place is then Pointer, where the schema holding the keyword applies, as an
	// example of the format names it (R23).
	Keyword string
	// The file or folder from the module's folder, with / between names, as the folder lists them;
	// "." for the module's folder itself, as fs.FS names it, and empty for the file that CheckFile
	// checks, which has no path.
	Path string
	// The place in the file, line and column from 1: in a file of a part as yaml.Breach counts them,
	// and in LICENSE and NOTICE with every line ended by LF alone. 0 when the breach is of the file
	// as a whole or of a value in it.
	Line, Column int
	// The value in the file that breaks the rule, as a JSON Pointer in URI fragment form, such as
	// #/module_format_version; empty when the breach is of no value.
	Pointer string
	Message string
}

A Breach is one reason a module is refused: a rule it breaks; or, when Rule is empty, a keyword of the schema of its part that a file fails, which Keyword names; or, when both are empty, a file of a part that is not YAML 1.2.2, which the format refuses without an ID.

func (Breach) String

func (b Breach) String() string

type Report

type Report struct {
	Breaches []Breach
	Warnings []Warning
}

A Report is what the check of a module finds: every breach, in the order of their places — the path, then the line and column, then the value, member by member, with an element of an array by its index —, and at one place in the order of their rules and keywords, so that it does not depend on the order in which the folder lists its files. A report with no breach accepts the module. Its warnings, in the order of their places, refuse nothing: a module with warnings and no breach is accepted (R50). Check gives them and CheckFile none, since a warning has no test vectors.

func Check

func Check(ctx context.Context, fsys fs.FS) (Report, error)

Check reads the module whose folder is the root of fsys and checks it by the format version FormatVersion: its layout, each file of a part by the YAML rules and against the schema of its part, and the files that both accept by the rules of the parts. A manifest that names a version the library does not read gives a report of that breach alone, since the rest of the module is written by rules the library does not know. The error is for a folder or file that could not be read, and then there is no report.

The solvers of the module's templates run with ctx, one on each CPU that the process may use at once, runtime.GOMAXPROCS(0), and the report holds their breaches in the order of their places, as it holds every other (R38). Once ctx is done the check stops, and its error is that of ctx.

Example
report, err := Check(context.Background(), fstest.MapFS{
	"Manifest.yaml": {Data: []byte(manifest)},
	"LICENSE":       {Data: []byte("The text of the license.\r\n")},
})
if err != nil {
	panic(err)
}
fmt.Println(report)
Output:
.: module.manifest: the folder holds no file manifest.yaml
LICENSE:1:25: module.plain-text: holds a carriage return: every line ends with LF alone
Manifest.yaml: module.layout: stands at no path of the layout of a module

func CheckFile

func CheckFile(part string, data []byte) (Report, error)

CheckFile checks a file of a part on its own, as an example of the part and a test vector of a part's rule in a file are checked: by the YAML rules and against the schema of the part, and, when both accept it, by the rules within its part; a manifest first by the format version it names, which, when the library does not read it, is the report's only breach, as in Check. Its breaches have no path. part is the term of a part of the layout, such as manifest or task; any other is an error.

func CheckModule added in v0.1.25

func CheckModule(ctx context.Context, fsys fs.FS) (Report, map[string][]formatv0.Numbers, error)

CheckModule is Check, and gives besides the numbers of the instances of each template of a module that breaks no rule, by the local ID of its task, in the order of the template's counter with the results of its solver, as the canonical view holds them; none when the module has no template or is refused. The build of a package takes them, so that a solver runs once for the check and the package together (R38).

func (Report) String

func (r Report) String() string

type Warning added in v0.2.6

type Warning struct {
	Path    string
	Pointer string
	Message string
}

A Warning is what a text of the module asks of its author, though the format refuses nothing for it: a text of the whole module that holds a number — a rung template, a trap's advice, a technique, a solving step (R57 spec). A warning is no rule: it has no ID and no test vectors, and changes no report's verdict (R50). Path is the file from the module's folder, with / between names, and Pointer the place of the text in it.

func (Warning) String added in v0.2.6

func (w Warning) String() string

Jump to

Keyboard shortcuts

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