Documentation
¶
Overview ¶
Package module reads an author's module and checks it as the module format says: its layout and the version of the format it names, each file against the schema of its part, and the format rules of each part, between parts and of the whole module — the tiers of the skill graph, the templates with every instance and solver, and the leak check of the texts a learner sees before solving among them (format/README.md, sections 2 and 4–24). A breach names the ID of its rule and its place. The CLI's check and build call it, and module-registry from stage 4 (architecture 3.6).
The epic of code brings it part by part (R16). It holds so far the folder of a module as an fs.FS, by the layout of section 10 and the rules module.*; the format version of section 2 and manifest.format-version; the YAML rules of section 4 on each file of a part, by internal/yaml (R22); and each file of a part against the schema of its part, by internal/schema, with a breach of a schema named by its keyword and place as section 8 names it (R23).
Index ¶
Examples ¶
Constants ¶
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 the check holds, by the part a breach of each is reported in (format/README.md, sections 10 and 11).
const FormatVersion = "0.3"
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 (format/README.md, section 2; R23). While the format is v0, it is the one version the library reads.
Variables ¶
This section is empty.
Functions ¶
func ReadsFormat ¶
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 (format/README.md, section 2).
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 (format/README.md, section 8).
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 (format/README.md, section 8); 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 (format/README.md, sections 4 and 8).
type Report ¶
type Report struct {
Breaches []Breach
}
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.
func Check ¶
Check reads the module whose folder is the root of fsys and checks it by the format version FormatVersion: its layout, and each file of a part by the YAML rules and against the schema of its part (format/README.md, sections 4, 5, 10 and 11). 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.
Example ¶
report, err := Check(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 ¶
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 (format/README.md, sections 8 and 9): by the YAML rules and against the schema of the part, and 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.