1
0
Fork 0

fix(docs): cover loading rules from module and path

This commit is contained in:
ssube 2019-11-03 13:05:33 -06:00 committed by Sean Sube
parent 44b1a6019e
commit 8ab6bb24d5
1 changed files with 52 additions and 19 deletions

View File

@ -4,24 +4,25 @@ Rules apply a schema fragment to a set of nodes selected from the original data.
This is a descriptive standard for rules. The enforced meta-rules for rules [are located here](../rules/salty-dog.yml). This is a descriptive standard for rules. The enforced meta-rules for rules [are located here](../rules/salty-dog.yml).
- [Rules](#Rules) - [Rules](#rules)
- [From File](#From-File) - [From File](#from-file)
- [YAML Schema](#YAML-Schema) - [YAML Schema](#yaml-schema)
- [Env Type](#Env-Type) - [Env Type](#env-type)
- [Include Type](#Include-Type) - [Include Type](#include-type)
- [Regexp Type](#Regexp-Type) - [Regexp Type](#regexp-type)
- [Stream Type](#Stream-Type) - [Stream Type](#stream-type)
- [File Name](#File-Name) - [File Name](#file-name)
- [Schema Definitions](#Schema-Definitions) - [Schema Definitions](#schema-definitions)
- [Rule Definitions](#Rule-Definitions) - [Rule Definitions](#rule-definitions)
- [Rule Name](#Rule-Name) - [Rule Name](#rule-name)
- [Rule Description](#Rule-Description) - [Rule Description](#rule-description)
- [Rule Level](#Rule-Level) - [Rule Level](#rule-level)
- [Rule Tags](#Rule-Tags) - [Rule Tags](#rule-tags)
- [Rule Selector](#Rule-Selector) - [Rule Selector](#rule-selector)
- [Rule Filter](#Rule-Filter) - [Rule Filter](#rule-filter)
- [Rule Check](#Rule-Check) - [Rule Check](#rule-check)
- [From Module](#From-Module) - [From Module](#from-module)
- [From Path](#from-path)
## From File ## From File
@ -216,4 +217,36 @@ rules:
## From Module ## From Module
**TODO:** load rules from `require`d modules Rules may be loaded from an external module. Any module that can be `require`d can be used by name,
using [normal Node `require` rules](https://nodejs.org/api/modules.html#modules_require_id).
To load a module: `--rule-module salty-dog-oot-example`
The default export from a rule module must match the schema for rule files:
```typescript
const { RuleOne, RuleTwo } = require('./rules');
module.exports = {
name: 'module-name',
definitions: {
snippet: {},
},
rules: [
new RuleOne(),
new RuleTwo(),
],
};
```
An example rule module [is available here](https://github.com/ssube/salty-dog-oot-example/).
## From Path
Rules may be loaded from a directory. Files with `.json` and `.yaml`/`.yml` extensions will be loaded,
with filenames lowercased before checking.
To load a directory: `--rule-path rules/`
Each file will be loaded as [an individual rule file](#from-file). Schema definitions and rules will
be loaded normally.