Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultDist() []byte
- func DefaultScript() []byte
- func EnableDist(require *require.RequireModule) error
- func LoadModules(runtime *goja.Runtime, registry *noderequire.Registry, ...) (*noderequire.RequireModule, error)
- type AfterModule
- type BeforeModule
- type Config
- type Enable
- type EvaluateError
- type LogrusPrinter
- type Option
- func WithAfterModule(after AfterModule) Option
- func WithBeforeModule(before BeforeModule) Option
- func WithDist(dist []byte) Option
- func WithFS(fs fs.FS) Option
- func WithLogrus(logger *logrus.Logger) Option
- func WithScript(script []byte) Option
- func WithWorkingDirectory(workingDirectory string) Option
- type Output
- type Rule
Constants ¶
const DistName = "./dist/built.js"
DistName used to import built.js e.g. with `var spectral = require('./dist/built.js');`
Variables ¶
var ErrAfterModule = errors.New("failed to run AfterModule hook")
ErrAfterModule if the AfterModule call failed
var ErrBeforeModule = errors.New("failed to run BeforeModule hook")
ErrBeforeModule if the BeforeModule call failed
var ErrPromiseRejected = errors.New("promise rejected")
ErrPromiseRejected when the JS promise is rejected
var ErrUnknownReturn = errors.New("unknown return")
ErrUnknownReturn when the result of the operation is not a string type
var Licenses embed.FS
Licenses includes the built.js.LICENSE.txt and oss-licenses.json file produced by Webpack for the dist
Functions ¶
func DefaultDist ¶
func DefaultDist() []byte
DefaultDist returning the transpiled source with the library
func DefaultScript ¶
func DefaultScript() []byte
DefaultScript returns the default script that evaluates the DefaultDist
func EnableDist ¶
func EnableDist(require *require.RequireModule) error
func LoadModules ¶
func LoadModules(runtime *goja.Runtime, registry *noderequire.Registry, beforeModule BeforeModule, afterModule AfterModule) (*noderequire.RequireModule, error)
LoadModules replacing NodeJS functionality required by Dist
Types ¶
type AfterModule ¶
type AfterModule = func(name string, runtime *goja.Runtime, registry *noderequire.Registry, requireModule *noderequire.RequireModule) error
AfterModule is evaluated after any module is enabled and can be used to change the current runtime state
type BeforeModule ¶
type BeforeModule = func(enable Enable, runtime *goja.Runtime, registry *noderequire.Registry, requireModule *noderequire.RequireModule) (func(runtime *goja.Runtime, registry *noderequire.Registry, requireModule *noderequire.RequireModule), error)
BeforeModule is evaluated before any module is enabled and can be used to change e.g. the Loader. If a non-nil Enable.Fn is returned, it is used instead of the provided Enable
func DefaultBeforeModule ¶
func DefaultBeforeModule(currentWorkingDirectory string, fileSystem fs.FS, printer console.Printer) BeforeModule
DefaultBeforeModule implementation of BeforeModule is constructed using a curried function containing the working directory and a possibly virtual filesystem
type Config ¶
type Config struct {
// Dist is the source JS file exporting
// 1) function: formatOutput
// 2) promise: lint output using global variables lintDocuments and lintRuleset
//
// See the index.js for more details
Dist []byte
// Script that evaluates the Dist, i.e. by the default
// by using the output of the lint promise and wrapping
// it in a formatOutput promise
Script []byte
// FS to use when loading document(s) and ruleset. If set, when a file is loaded (e.g. an OpenAPI document or
// a ruleset) it is first searched in the FS *without* the WorkingDirectory reference. If the file is not found
// in the FS, continue the search relative to the WorkingDirectory. This mechanism allows to bundle static files
// (e.g. rulesets) and also have a runtime component.
FS fs.FS
// Printer used for console output
Printer console.Printer
// WorkingDirectory, defaults to os.Getcwd() if ""
WorkingDirectory string
// BeforeModule hook to customize behavior before (or instead of) enabling a module
BeforeModule BeforeModule
// AfterModule hook to customize runtime or registry state
AfterModule AfterModule
}
Config to instantiate the runner
type Enable ¶
type Enable struct {
// Name of the Module to Enable
Name string
// Fn to Enable Module
Fn func(runtime *goja.Runtime, registry *noderequire.Registry, requireModule *noderequire.RequireModule)
}
Enable module with Name
type EvaluateError ¶
type EvaluateError struct {
Err error
}
EvaluateError translates various failure cases in an easier to understand format
func (EvaluateError) Error ¶
func (e EvaluateError) Error() string
Error implementation of EvaluateError
type LogrusPrinter ¶
type LogrusPrinter struct {
// contains filtered or unexported fields
}
LogrusPrinter is an adapter from logrus.Logger to console.Printer
type Option ¶
Option that can be supplied to modify the Config
func WithAfterModule ¶
func WithAfterModule(after AfterModule) Option
WithAfterModule sets the Config.AfterModule
func WithBeforeModule ¶
func WithBeforeModule(before BeforeModule) Option
WithBeforeModule sets the Config.BeforeModule
func WithDist ¶
WithDist sets the Config.Dist to a custom supplied value. This can be useful for using a specific version of the source and/or bundling it on your own.
func WithFS ¶
WithFS sets the Config.FS to load documents and rulesets from. This can be useful when using e.g. embed.FS as a means to bundle specs/rulesets.
func WithLogrus ¶
WithLogrus uses a logrus.Logger (or if nil, the global logrus.Logger) for console output produced by goja
func WithScript ¶
WithScript sets the Config.Script to a custom value
func WithWorkingDirectory ¶
WithWorkingDirectory sets the working directory used to load system files (e.g. .spectral.yaml)
type Rule ¶
type Rule struct {
Source string `json:"source"`
Code string `json:"code"`
Path []string `json:"path"`
Message string `json:"message"`
Severity int `json:"severity"`
Range struct {
Start struct {
Line int `json:"line"`
Character int `json:"character"`
} `json:"start"`
End struct {
Line int `json:"line"`
Character int `json:"character"`
} `json:"end"`
}
}
Rule is an instance of a failure during Lint