Skip to content

Commit

Permalink
Document approach to using private utils (#7052)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeddy3 committed Jul 6, 2023
1 parent 616d469 commit cefd267
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
11 changes: 3 additions & 8 deletions docs/developer-guide/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ We recommend your custom rules adhere to our [rule conventions](rules.md) for:
- tests
- docs
- metadata
- construct-specific parsers

## The anatomy of a plugin

Expand Down Expand Up @@ -216,6 +217,8 @@ Alternatively, if you don't want to use Jest you'll find more testing tool in [A

Stylelint exposes some useful utilities.

You're also welcome to copy any of the [internal utils](https://github.com/stylelint/stylelint/tree/main/lib/utils) into your plugin. You should not `require` or `import` them directly, as they are not part of the public API and may change or be removed without warning.

### `stylelint.utils.report`

Adds problems from your plugin to the list of problems that Stylelint will report to the user.
Expand Down Expand Up @@ -311,14 +314,6 @@ module.exports = stylelint.createPlugin(ruleName, (expectation) => {

If your plugin can accept an array as its primary option, you must designate this by setting the property `primaryOptionArray = true` on your rule function. For more information, check out the ["Working on rules"](rules.md) doc.

## External helper modules

In addition to the standard parsers mentioned in the ["Working on rules"](rules.md) doc, there are other external modules used within Stylelint that we recommend using. These include:

- [postcss-resolve-nested-selector](https://github.com/davidtheclark/postcss-resolve-nested-selector): given a (nested) selector in a PostCSS AST, return an array of resolved selectors.

Have a look through [Stylelint's internal utils](https://github.com/stylelint/stylelint/tree/main/lib/utils) and if you come across one that you need in your plugin, then please consider helping us extract it into an external module.

## Peer dependencies

You should express, within the `peerDependencies` key (and **not** within the `dependencies` key) of your plugin's `package.json`, what version(s) of Stylelint your plugin can be used with. This is to ensure that different versions of Stylelint are not unexpectedly installed.
Expand Down
1 change: 1 addition & 0 deletions docs/developer-guide/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Use `node.raws` instead of `node.raw()` when accessing raw strings from the [Pos

Depending on the rule, we also recommend using:

- [media-query-list-parser](https://www.npmjs.com/package/@csstools/media-query-list-parser)
- [postcss-value-parser](https://github.com/TrySound/postcss-value-parser)
- [postcss-selector-parser](https://github.com/postcss/postcss-selector-parser)

Expand Down

0 comments on commit cefd267

Please sign in to comment.