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.

report.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. 'use strict';
  2. const _ = require('lodash');
  3. /** @typedef {{
  4. ruleName: string,
  5. result: import('stylelint').PostcssResult,
  6. message: string,
  7. node: import('postcss').Node & {
  8. positionBy(opts: { index?: number, word?: string }): { line: number, column: number }
  9. },
  10. index?: number,
  11. word?: string,
  12. line?: number
  13. }} Violation */
  14. /**
  15. * Report a violation.
  16. *
  17. * This function accounts for `disabledRanges` attached to the result.
  18. * That is, if the reported violation is within a disabledRange,
  19. * it is ignored. Otherwise, it is attached to the result as a
  20. * postcss warning.
  21. *
  22. * It also accounts for the rule's severity.
  23. *
  24. * You *must* pass *either* a node or a line number.
  25. * @param {Violation} violation
  26. */
  27. module.exports = function (violation) {
  28. const ruleName = violation.ruleName;
  29. const result = violation.result;
  30. const message = violation.message;
  31. const line = violation.line;
  32. const node = violation.node;
  33. const index = violation.index;
  34. const word = violation.word;
  35. result.stylelint = result.stylelint || {
  36. ruleSeverities: {},
  37. customMessages: {},
  38. };
  39. // In quiet mode, mere warnings are ignored
  40. if (result.stylelint.quiet && result.stylelint.ruleSeverities[ruleName] !== 'error') {
  41. return;
  42. }
  43. // If a line is not passed, use the node.positionBy method to get the
  44. // line number that the complaint pertains to
  45. const startLine = line || node.positionBy({ index }).line;
  46. const { ignoreDisables } = result.stylelint.config || {};
  47. if (result.stylelint.disabledRanges) {
  48. const ranges = result.stylelint.disabledRanges[ruleName] || result.stylelint.disabledRanges.all;
  49. for (const range of ranges) {
  50. if (
  51. // If the violation is within a disabledRange,
  52. // and that disabledRange's rules include this one,
  53. // do not register a warning
  54. range.start <= startLine &&
  55. (range.end === undefined || range.end >= startLine) &&
  56. (!range.rules || range.rules.includes(ruleName))
  57. ) {
  58. // Collect disabled warnings
  59. // Used to report `needlessDisables` in subsequent processing.
  60. const disabledWarnings =
  61. result.stylelint.disabledWarnings || (result.stylelint.disabledWarnings = []);
  62. disabledWarnings.push({
  63. rule: ruleName,
  64. line: startLine,
  65. });
  66. if (!ignoreDisables) {
  67. return;
  68. }
  69. break;
  70. }
  71. }
  72. }
  73. const severity = _.get(result.stylelint, ['ruleSeverities', ruleName]);
  74. if (!result.stylelint.stylelintError && severity === 'error') {
  75. result.stylelint.stylelintError = true;
  76. }
  77. /** @type {import('stylelint').StylelintWarningOptions} */
  78. const warningProperties = {
  79. severity,
  80. rule: ruleName,
  81. };
  82. if (node) {
  83. warningProperties.node = node;
  84. }
  85. if (index) {
  86. warningProperties.index = index;
  87. }
  88. if (word) {
  89. warningProperties.word = word;
  90. }
  91. const warningMessage = _.get(result.stylelint, ['customMessages', ruleName], message);
  92. result.warn(warningMessage, warningProperties);
  93. };