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.

index.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const postcss = require('postcss');
  5. const report = require('../../utils/report');
  6. const ruleMessages = require('../../utils/ruleMessages');
  7. const validateOptions = require('../../utils/validateOptions');
  8. const ruleName = 'linebreaks';
  9. const messages = ruleMessages(ruleName, {
  10. expected: (linebreak) => `Expected linebreak to be ${linebreak}`,
  11. });
  12. function rule(actual, secondary, context) {
  13. return (root, result) => {
  14. const validOptions = validateOptions(result, ruleName, {
  15. actual,
  16. possible: ['unix', 'windows'],
  17. });
  18. if (!validOptions) {
  19. return;
  20. }
  21. const shouldHaveCR = actual === 'windows';
  22. if (context.fix) {
  23. const propertiesToUpdate = ['selector', 'raws.before', 'raws.after', 'value', 'text'];
  24. root.walk((node) => {
  25. propertiesToUpdate.forEach((property) => {
  26. const fixedData = fixData(_.get(node, property));
  27. _.set(node, property, fixedData);
  28. });
  29. });
  30. root.raws.after = fixData(root.raws.after);
  31. } else {
  32. const lines = root.source.input.css.split('\n');
  33. for (let i = 0; i < lines.length; i++) {
  34. let line = lines[i];
  35. if (i < lines.length - 1 && !line.includes('\r')) {
  36. line += '\n';
  37. }
  38. if (hasError(line)) {
  39. const lineNum = i + 1;
  40. const colNum = line.length;
  41. reportNewlineError(lineNum, colNum);
  42. }
  43. }
  44. }
  45. function hasError(dataToCheck) {
  46. const hasNewlineToVerify = /[\r\n]/.test(dataToCheck);
  47. const hasCR = hasNewlineToVerify ? /\r/.test(dataToCheck) : false;
  48. return hasNewlineToVerify && hasCR !== shouldHaveCR;
  49. }
  50. function fixData(data) {
  51. if (data) {
  52. let res = data.replace(/\r/g, '');
  53. if (shouldHaveCR) {
  54. res = res.replace(/\n/g, '\r\n');
  55. }
  56. return res;
  57. }
  58. return data;
  59. }
  60. function reportNewlineError(line, column) {
  61. // Creating a node manually helps us to point to empty lines.
  62. const node = postcss.rule({
  63. source: {
  64. start: { line, column },
  65. },
  66. });
  67. report({
  68. message: messages.expected(actual),
  69. node,
  70. result,
  71. ruleName,
  72. });
  73. }
  74. };
  75. }
  76. rule.ruleName = ruleName;
  77. rule.messages = messages;
  78. module.exports = rule;