The stylelint global variable has a lint() method.
const result = await stylelint.lint(options);A string to lint.
stylelint.lint() returns a Promise that resolves with an object containing the following properties:
A string that contains the autofixed code, if the fix option is set to true. Otherwise, it is undefined.
Boolean. If true, at least one rule with an "error"-level severity registered a problem.
A JSON string that contains the formatted problems.
An array containing all the Stylelint result objects (the objects that formatters consume).
When the computeEditInfo option is enabled, a warning may include a fix property that provides information about suggested fixes:
range([number, number]) - the pair of 0-based indices in source code text to removetext(string) - the text to add
For example, to change a { opacity: 10%; } to a { opacity: 0.1; }, the edit info might look like:
Only a single edit info will be recorded for a specific region in source code. If multiple report ranges overlap, only the first will contain edit info.
stylelint.lint() does not reject the Promise when your CSS contains syntax errors.
It resolves with an object (see the returned promise) that contains information about the syntax error.
{ // "line", "column", "rule", ... "fix": { "range": [13, 16], // Indices of "10%" "text": "0.1" // Replacement text } }