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.

reportDisables.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict';
  2. const _ = require('lodash');
  3. /** @typedef {import('stylelint').RangeType} RangeType */
  4. /** @typedef {import('stylelint').DisableReportRange} DisabledRange */
  5. /**
  6. * Returns a report describing which `results` (if any) contain disabled ranges
  7. * for rules that disallow disables via `reportDisables: true`.
  8. *
  9. * @param {import('stylelint').StylelintResult[]} results
  10. */
  11. module.exports = function (results) {
  12. results.forEach((result) => {
  13. // File with `CssSyntaxError` don't have `_postcssResult`s.
  14. if (!result._postcssResult) {
  15. return;
  16. }
  17. /** @type {{[ruleName: string]: Array<RangeType>}} */
  18. const rangeData = result._postcssResult.stylelint.disabledRanges;
  19. if (!rangeData) return;
  20. const config = result._postcssResult.stylelint.config;
  21. // If no rules actually disallow disables, don't bother looking for ranges
  22. // that correspond to disabled rules.
  23. if (!Object.values(_.get(config, 'rules', {})).some(reportDisablesForRule)) {
  24. return [];
  25. }
  26. Object.keys(rangeData).forEach((rule) => {
  27. rangeData[rule].forEach((range) => {
  28. if (!reportDisablesForRule(_.get(config, ['rules', rule], []))) return;
  29. // If the comment doesn't have a location, we can't report a useful error.
  30. // In practice we expect all comments to have locations, though.
  31. if (!range.comment.source || !range.comment.source.start) return;
  32. result.warnings.push({
  33. text: `Rule "${rule}" may not be disabled`,
  34. rule: 'reportDisables',
  35. line: range.comment.source.start.line,
  36. column: range.comment.source.start.column,
  37. severity: 'error',
  38. });
  39. });
  40. });
  41. });
  42. };
  43. /**
  44. * @param {[any, object]|null} options
  45. * @return {boolean}
  46. */
  47. function reportDisablesForRule(options) {
  48. if (!options) return false;
  49. return _.get(options[1], 'reportDisables', false);
  50. }