This repository has been archived on 2020-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
2020-11-01 22:46:04 +00:00

1.1 KiB
Raw Permalink Blame History

Writing processors

Processors are functions that hook into stylelints pipeline, modifying code on its way into stylelint and modifying results on their way out.

Their use is discouraged favor of PostCSS syntaxes.

Processor modules are functions that accept an options object and return an object with the following the functions, which hook into the processing of each file:

  • code: A function that accepts two arguments, the files code and the files path, and returns a string for stylelint to lint.
  • result: A function that accepts two arguments, the files stylelint result object and the files path, and either mutates the result object (returning nothing) or returns a new one.
// my-processor.js
module.exports = function (options) {
  return {
    code: function (input, filepath) {
      // ...
      return transformedCode;
    },
    result: function (stylelintResult, filepath) {
      // ...
      return transformedResult;
    }
  };
};

Processor options must be JSON-friendly because users will need to include them in .stylelintrc files.