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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // @ts-nocheck
  2. 'use strict';
  3. const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
  4. const report = require('../../utils/report');
  5. const ruleMessages = require('../../utils/ruleMessages');
  6. const styleSearch = require('style-search');
  7. const validateOptions = require('../../utils/validateOptions');
  8. const whitespaceChecker = require('../../utils/whitespaceChecker');
  9. const ruleName = 'selector-list-comma-newline-after';
  10. const messages = ruleMessages(ruleName, {
  11. expectedAfter: () => 'Expected newline after ","',
  12. expectedAfterMultiLine: () => 'Expected newline after "," in a multi-line list',
  13. rejectedAfterMultiLine: () => 'Unexpected whitespace after "," in a multi-line list',
  14. });
  15. function rule(expectation, options, context) {
  16. const checker = whitespaceChecker('newline', expectation, messages);
  17. return (root, result) => {
  18. const validOptions = validateOptions(result, ruleName, {
  19. actual: expectation,
  20. possible: ['always', 'always-multi-line', 'never-multi-line'],
  21. });
  22. if (!validOptions) {
  23. return;
  24. }
  25. root.walkRules((ruleNode) => {
  26. if (!isStandardSyntaxRule(ruleNode)) {
  27. return;
  28. }
  29. // Get raw selector so we can allow end-of-line comments, e.g.
  30. // a, /* comment */
  31. // b {}
  32. const selector = ruleNode.raws.selector ? ruleNode.raws.selector.raw : ruleNode.selector;
  33. const fixIndices = [];
  34. styleSearch(
  35. {
  36. source: selector,
  37. target: ',',
  38. functionArguments: 'skip',
  39. },
  40. (match) => {
  41. const nextChars = selector.substr(match.endIndex, selector.length - match.endIndex);
  42. // If there's a // comment, that means there has to be a newline
  43. // ending the comment so we're fine
  44. if (/^\s+\/\//.test(nextChars)) {
  45. return;
  46. }
  47. // If there are spaces and then a comment begins, look for the newline
  48. const indextoCheckAfter = /^\s+\/\*/.test(nextChars)
  49. ? selector.indexOf('*/', match.endIndex) + 1
  50. : match.startIndex;
  51. checker.afterOneOnly({
  52. source: selector,
  53. index: indextoCheckAfter,
  54. err: (m) => {
  55. if (context.fix) {
  56. fixIndices.push(indextoCheckAfter + 1);
  57. return;
  58. }
  59. report({
  60. message: m,
  61. node: ruleNode,
  62. index: match.startIndex,
  63. result,
  64. ruleName,
  65. });
  66. },
  67. });
  68. },
  69. );
  70. if (fixIndices.length) {
  71. let fixedSelector = selector;
  72. fixIndices
  73. .sort((a, b) => b - a)
  74. .forEach((index) => {
  75. const beforeSelector = fixedSelector.slice(0, index);
  76. let afterSelector = fixedSelector.slice(index);
  77. if (expectation.startsWith('always')) {
  78. afterSelector = context.newline + afterSelector;
  79. } else if (expectation.startsWith('never-multi-line')) {
  80. afterSelector = afterSelector.replace(/^\s*/, '');
  81. }
  82. fixedSelector = beforeSelector + afterSelector;
  83. });
  84. if (ruleNode.raws.selector) {
  85. ruleNode.raws.selector.raw = fixedSelector;
  86. } else {
  87. ruleNode.selector = fixedSelector;
  88. }
  89. }
  90. });
  91. };
  92. }
  93. rule.ruleName = ruleName;
  94. rule.messages = messages;
  95. module.exports = rule;