Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
Tim van der Lippe | efb716a | 2020-12-01 12:54:04 +0000 | [diff] [blame^] | 3 | const createPartialStylelintResult = require('./createPartialStylelintResult'); |
Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 4 | |
| 5 | /** @typedef {import('stylelint').PostcssResult} PostcssResult */ |
| 6 | /** @typedef {import('postcss').NodeSource} NodeSource */ |
| 7 | /** @typedef {import('stylelint').StylelintResult} StylelintResult */ |
| 8 | |
| 9 | /** |
| 10 | * @param {import('stylelint').StylelintInternalApi} stylelint |
| 11 | * @param {PostcssResult} [postcssResult] |
| 12 | * @param {string} [filePath] |
| 13 | * @param {import('stylelint').StylelintCssSyntaxError} [cssSyntaxError] |
| 14 | * @return {Promise<StylelintResult>} |
| 15 | */ |
| 16 | module.exports = function (stylelint, postcssResult, filePath, cssSyntaxError) { |
Tim van der Lippe | efb716a | 2020-12-01 12:54:04 +0000 | [diff] [blame^] | 17 | let stylelintResult = createPartialStylelintResult(postcssResult, cssSyntaxError); |
Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 18 | |
| 19 | return stylelint.getConfigForFile(filePath).then((configForFile) => { |
| 20 | // TODO TYPES handle possible null here |
| 21 | const config = /** @type {{ config: import('stylelint').StylelintConfig, filepath: string }} */ (configForFile) |
| 22 | .config; |
Tim van der Lippe | efb716a | 2020-12-01 12:54:04 +0000 | [diff] [blame^] | 23 | const file = stylelintResult.source || (cssSyntaxError && cssSyntaxError.file); |
Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 24 | |
| 25 | if (config.resultProcessors) { |
| 26 | config.resultProcessors.forEach((resultProcessor) => { |
| 27 | // Result processors might just mutate the result object, |
| 28 | // or might return a new one |
| 29 | const returned = resultProcessor(stylelintResult, file); |
| 30 | |
| 31 | if (returned) { |
| 32 | stylelintResult = returned; |
| 33 | } |
| 34 | }); |
| 35 | } |
| 36 | |
| 37 | return stylelintResult; |
| 38 | }); |
| 39 | }; |