Skip to content

bhsd-harry/stylelint-browserify

Repository files navigation

Stylelint-browserify

npm version License Codacy Badge

API

The stylelint global variable has a lint() method.

const result = await stylelint.lint(options);

Options

config

A configuration object.

code

A string to lint.

The returned promise

stylelint.lint() returns a Promise that resolves with an object containing the following properties:

code

A string that contains the autofixed code, if the fix option is set to true. Otherwise, it is undefined.

errored

Boolean. If true, at least one rule with an "error"-level severity registered a problem.

report

A JSON string that contains the formatted problems.

results

An array containing all the Stylelint result objects (the objects that formatters consume).

Edit info

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 remove
  • text (string) - the text to add

For example, to change a { opacity: 10%; } to a { opacity: 0.1; }, the edit info might look like:

{
  // "line", "column", "rule", ...
  "fix": {
    "range": [13, 16], // Indices of "10%"
    "text": "0.1" // Replacement text
  }
}

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.

Syntax errors

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.

About

Stylelint in browser

Topics

Resources

License

Stars

Watchers

Forks