UNPKG

1.39 kBJavaScriptView Raw
1'use strict';
2
3const createPartialStylelintResult = require('./createPartialStylelintResult');
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 */
16module.exports = function (stylelint, postcssResult, filePath, cssSyntaxError) {
17 let stylelintResult = createPartialStylelintResult(postcssResult, cssSyntaxError);
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;
23 const file = stylelintResult.source || (cssSyntaxError && cssSyntaxError.file);
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};