createStylelintResult.js 1.2 KB

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