Skip to content

Commit 0176e25

Browse files
hudochenkovdavidtheclark
authored andcommitted
Improving docs about autofixing (stylelint#2517)
* Add fix parameters description to rule testers docs * Add a note about disabling autofixing for plugin authors * Update plugins.md
1 parent 2c63003 commit 0176e25

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Diff for: docs/developer-guide/plugins.md

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Your plugin's rule name must be namespaced, e.g. `your-namespace/your-rule-name`
3434

3535
In order for your plugin rule to work with the [standard configuration format](../user-guide/configuration.md#rules), `ruleFunction` should accept 2 arguments: the primary option and, optionally, a secondary options object.
3636

37+
If your plugin rule supports [autofixing](rules.md#adding-autofixing), then `ruleFunction` should also accept a third argument: context. Also, it's highly recommended to support the `disableFix` option in your secondary options object. Within the rule, don't perform autofixing if the user has passed a `disableFix` option for your rule.
38+
3739
`ruleFunction` should return a function that is essentially a little [PostCSS plugin](https://github.com/postcss/postcss/blob/master/docs/writing-a-plugin.md): it takes 2 arguments: the PostCSS Root (the parsed AST), and the PostCSS LazyResult. You'll have to [learn about the PostCSS API](https://github.com/postcss/postcss/blob/master/docs/api.md).
3840

3941
### Asynchronous rules

Diff for: docs/developer-guide/rule-testers.md

+2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ Required properties:
4242
- `column` {number}: *Optional but recommended.* The expected column number of the violation. If this is left out, the column won't be checked.
4343
- `description` {string}: *Optional.* A description of the case.
4444
- `only` {boolean}: If `true`, run only this test case.
45+
- `fixed` {string}: *Required if test schema has `fix` enabled.* Result of autofixing against `code` property.
4546

4647
Optional properties:
4748

4849
- `syntax` {"css"|"less"|"scss"|"sugarss"}: Defaults to `"css"`. Other settings use special parsers.
4950
- `skipBasicChecks` {boolean}: Defaults to `false`. If `true`, a few rudimentary checks (that should almost always be included) will not be performed. You can check those out in `lib/testUtils/basicChecks.js`.
5051
- `preceedingPlugins` {array}: An array of PostCSS plugins that should be run before the CSS is tested.
52+
- `fix` {boolean}: Defaults to `false`. If `true`, every `reject` test-case will be tested for autofixing functionality. *Required if rule has autofixing.*
5153

5254
## Creating a rule tester
5355

0 commit comments

Comments
 (0)