worker.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. /** @typedef {import('stylelint')} Stylelint */
  3. /** @typedef {import("stylelint").LinterOptions} StylelintOptions */
  4. /** @typedef {import('./options').Options} Options */
  5. Object.assign(module.exports, {
  6. lintFiles,
  7. setup
  8. });
  9. /** @type {Stylelint} */
  10. let stylelint;
  11. /** @type {Partial<StylelintOptions>} */
  12. let linterOptions;
  13. /**
  14. * @param {Options} options
  15. * @param {Partial<StylelintOptions>} stylelintOptions
  16. */
  17. function setup(options, stylelintOptions) {
  18. stylelint = require(options.stylelintPath || 'stylelint');
  19. linterOptions = stylelintOptions;
  20. return stylelint;
  21. }
  22. /**
  23. * @param {string | string[]} files
  24. */
  25. async function lintFiles(files) {
  26. const {
  27. results
  28. } = await stylelint.lint({ ...linterOptions,
  29. files
  30. }); // Reset result to work with worker
  31. return results.map(result => {
  32. return {
  33. source: result.source,
  34. errored: result.errored,
  35. ignored: result.ignored,
  36. warnings: result.warnings,
  37. deprecations: result.deprecations,
  38. invalidOptionWarnings: result.invalidOptionWarnings
  39. };
  40. });
  41. }