Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document fix and output behaviour for Node.js API usage #5971

Merged
merged 9 commits into from
Mar 17, 2022
23 changes: 22 additions & 1 deletion docs/user-guide/usage/node-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ Boolean. If `true`, at least one rule with an "error"-level severity registered

### `output`

A string displaying the formatted problems (using the default formatter or whichever you passed).
A string that contains either the:

- formatted problems (using the default formatter or whichever you passed)
- or the autofixed code, if the `fix` option is set to `true`

### `postcssResults`

Expand Down Expand Up @@ -172,6 +175,24 @@ stylelint

Note that the customSyntax option also accepts a string. [Refer to the options documentation for details](./options.md#customsyntax).

### Example F

Using a string and the `fix` option:

```js
stylelint
.lint({
code: "a { color: pink; }",
config: { rules: { "hue-degree-notation": "angle" } },
fix: true
})
.then(function () {
/* .. */
});
```

The autofixed code will be available as the value of the `output` property in the returned object.

## Resolving the effective config for a file

If you want to find out what exact configuration will be used for a file without actually linting it, you can use the `resolveConfig()` function. Given a file path, it will return a Promise that resolves with the effective configuration object:
Expand Down
4 changes: 3 additions & 1 deletion docs/user-guide/usage/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ CLI flag: `--fix`

Automatically fix, where possible, problems reported by rules.

For CSS with standard syntax, Stylelint uses [postcss-safe-parser](https://github.com/postcss/postcss-safe-parser) to fix syntax errors.
For CSS with standard syntax, Stylelint uses postcss-safe-parser to fix syntax errors.
jlarmstrongiv marked this conversation as resolved.
Show resolved Hide resolved

When using the Node.js API, the autofixed code is available as the value of the output property in the returned object.
jlarmstrongiv marked this conversation as resolved.
Show resolved Hide resolved

If a source contains a:

Expand Down