Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed May 14, 2024
1 parent cfdee89 commit 9b11c35
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ export default {

Additional configuration may be added in the future. For now, `rules` is the only useful key.

### Rules
### Rules (`rules`)

All rules are optional.

#### `elm`

The `elm` rule specifies what elements are allowed in the SVG. It should be an object or an array of objects where:
Rules at `elm` specify what elements are allowed in the SVG. It should be an object or an array of objects where:

- The keys are the element CSS selectors. See [_Selecting elements_ on cheerio's documentation][selecting-elements-cheerio].
- The values are either:
Expand Down Expand Up @@ -140,7 +140,7 @@ export default {

#### `attr`

The `attr` rule specifies what attributes are allowed on elements. It should be an object or an array of objects where the keys must be either:
Rules at `attr` specify the attributes that are allowed on elements. It should be an object or an array of objects where the keys must be either:

- `"rule::selector"`: The value must be the CSS selector of the element to which the rule applies. See [_Selecting elements_ on cheerio's documentation][selecting-elements-cheerio].
- `"rule::whitelist"`: If enabled, extra attributes beyond of the ones defined in additional keys are not allowed on the element. The value must be a boolean.
Expand Down Expand Up @@ -187,18 +187,18 @@ export default {

#### `valid`

The `valid` rule specifies if the SVG is valid or not. It should be a boolean to enable or disable the rule.
The `valid` rule is used to check that the SVG is valid using [`XMLValidator` of fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser/blob/HEAD/docs/v4/4.XMLValidator.md). It should be a boolean to enable or disable the rule.

#### Custom rules (`custom`)

Custom rules can be specified by an array of functions. Each function should have the signature `(reporter, $, ast, { filename }) => void`, where:

- `reporter` is the object that will be used to report the errors.
- `$` is the cheerio object of the SVG.
- `ast` is the abstract syntax tree of the SVG.
- `filepath` is the full path of the file being linted.
- `$` is the [cheerio object](https://cheerio.js.org/docs/api/classes/Cheerio) of the SVG.
- `ast` is the abstract syntax tree of the SVG generated by [htmlparser2](https://feedic.com/htmlparser2/).
- `filepath` is the absolute path of the file being linted.

You can set `reporter.name` to define the name of the rule shown by the output when an error is found. You can call `repoter.error(message)` to report an error.
You can use the setter of `reporter.name` to define the name of the rule shown by the output when errors are found. You can call `repoter.error(message)` to report an error.

##### Example

Expand Down Expand Up @@ -234,7 +234,7 @@ External rules can be specified by their package name and rule name, separated b
import("package-of-the-rule/rule-name.js");
```

So you need to export the rule function from the file `rule-name.js` in the package `package-of-the-rule` as default to expose it.
The rule function must be exported from the file `rule-name.js` in the package `package-of-the-rule` as the default export to expose it.

##### Example

Expand Down

0 comments on commit 9b11c35

Please sign in to comment.