Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

createPartialStylelintResult.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. 'use strict';
  2. const _ = require('lodash');
  3. /** @typedef {import('stylelint').PostcssResult} PostcssResult */
  4. /** @typedef {import('postcss').NodeSource} NodeSource */
  5. /** @typedef {import('stylelint').StylelintResult} StylelintResult */
  6. /**
  7. * @param {PostcssResult} [postcssResult]
  8. * @param {import('stylelint').StylelintCssSyntaxError} [cssSyntaxError]
  9. * @return {StylelintResult}
  10. */
  11. module.exports = function (postcssResult, cssSyntaxError) {
  12. /** @type {StylelintResult} */
  13. let stylelintResult;
  14. /** @type {string | undefined} */
  15. let source;
  16. if (postcssResult && postcssResult.root) {
  17. if (postcssResult.root.source) {
  18. source = postcssResult.root.source.input.file;
  19. if (!source && 'id' in postcssResult.root.source.input) {
  20. source = postcssResult.root.source.input.id;
  21. }
  22. }
  23. // Strip out deprecation warnings from the messages
  24. const deprecationMessages = _.remove(postcssResult.messages, {
  25. stylelintType: 'deprecation',
  26. });
  27. const deprecations = deprecationMessages.map((deprecationMessage) => {
  28. return {
  29. text: deprecationMessage.text,
  30. reference: deprecationMessage.stylelintReference,
  31. };
  32. });
  33. // Also strip out invalid options
  34. const invalidOptionMessages = _.remove(postcssResult.messages, {
  35. stylelintType: 'invalidOption',
  36. });
  37. const invalidOptionWarnings = invalidOptionMessages.map((invalidOptionMessage) => {
  38. return {
  39. text: invalidOptionMessage.text,
  40. };
  41. });
  42. const parseErrors = _.remove(postcssResult.messages, {
  43. stylelintType: 'parseError',
  44. });
  45. // This defines the stylelint result object that formatters receive
  46. stylelintResult = {
  47. source,
  48. deprecations,
  49. invalidOptionWarnings,
  50. // TODO TYPES check which types are valid? postcss? stylelint?
  51. /* eslint-disable-next-line object-shorthand */
  52. parseErrors: /** @type {any} */ (parseErrors),
  53. errored: postcssResult.stylelint.stylelintError,
  54. warnings: postcssResult.messages.map((message) => {
  55. return {
  56. line: message.line,
  57. column: message.column,
  58. rule: message.rule,
  59. severity: message.severity,
  60. text: message.text,
  61. };
  62. }),
  63. ignored: postcssResult.stylelint.ignored,
  64. _postcssResult: postcssResult,
  65. };
  66. } else if (cssSyntaxError) {
  67. if (cssSyntaxError.name !== 'CssSyntaxError') {
  68. throw cssSyntaxError;
  69. }
  70. stylelintResult = {
  71. source: cssSyntaxError.file || '<input css 1>',
  72. deprecations: [],
  73. invalidOptionWarnings: [],
  74. parseErrors: [],
  75. errored: true,
  76. warnings: [
  77. {
  78. line: cssSyntaxError.line,
  79. column: cssSyntaxError.column,
  80. rule: cssSyntaxError.name,
  81. severity: 'error',
  82. text: `${cssSyntaxError.reason} (${cssSyntaxError.name})`,
  83. },
  84. ],
  85. };
  86. } else {
  87. throw new Error(
  88. 'createPartialStylelintResult must be called with either postcssResult or CssSyntaxError',
  89. );
  90. }
  91. return stylelintResult;
  92. };