3 Processors are functions that hook into stylelint's pipeline, modifying code on its way into stylelint and modifying results on their way out.
5 *Processors can only be used with the CLI and the Node API, not with the PostCSS plugin.*
7 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:
9 - **code**: A function that accepts two arguments, the file's code and the file's path, and returns a string for stylelint to lint.
10 - **result**: A function that accepts two arguments, the file's stylelint result object and the file's path, and either mutates the result object (returning nothing) or returns a new one.
14 module.exports = function(options) {
16 code: function(input, filepath) {
18 return transformedCode;
20 result: function(stylelintResult, filepath) {
22 return transformedResult;
28 Processors can enable stylelint to lint the CSS within non-stylesheet files. For example, let's say you want to lint the CSS within `<style>` tags in HTML. If you just feed stylelint your HTML code, you'll run into problems, because PostCSS does not parse HTML by default. Instead, you can create a processor that does the following:
30 - In the `code` processor function, extract CSS from the `<style>` tags in the HTML code. Return a CSS string containing all that extracted CSS, which is what stylelint will inspect.
31 - Build a sourcemap while performing the extraction, so warning positions can be tailored to match the original source HTML.
32 - In the `result` processor function, modify the line/column position of each warning using your sourcemap.
34 *Processor options must be JSON-friendly*, because users will need to include them in `.stylelintrc` files.
38 - Use the `stylelint-processor` keyword within your `package.json`.
39 - Once your processor is published, please send us a Pull Request to add your processor to [the list](../user-guide/processors.md).