UNPKG

1.23 kBJavaScriptView Raw
1'use strict';
2
3const createPartialStylelintResult = require('./createPartialStylelintResult');
4
5/** @typedef {import('stylelint').PostcssResult} PostcssResult */
6/** @typedef {import('stylelint').LintResult} StylelintResult */
7
8/**
9 * @param {import('stylelint').InternalApi} stylelint
10 * @param {PostcssResult} [postcssResult]
11 * @param {string} [filePath]
12 * @param {import('stylelint').CssSyntaxError} [cssSyntaxError]
13 * @return {Promise<StylelintResult>}
14 */
15module.exports = async function createStylelintResult(
16 stylelint,
17 postcssResult,
18 filePath,
19 cssSyntaxError,
20) {
21 let stylelintResult = createPartialStylelintResult(postcssResult, cssSyntaxError);
22
23 const configForFile = await stylelint.getConfigForFile(filePath, filePath);
24
25 const config = configForFile === null ? {} : configForFile.config;
26 const file = stylelintResult.source || (cssSyntaxError && cssSyntaxError.file);
27
28 if (config.resultProcessors) {
29 for (const resultProcessor of config.resultProcessors) {
30 // Result processors might just mutate the result object,
31 // or might return a new one
32 const returned = resultProcessor(stylelintResult, file);
33
34 if (returned) {
35 stylelintResult = returned;
36 }
37 }
38 }
39
40 return stylelintResult;
41};