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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // @ts-nocheck
  2. 'use strict';
  3. const findFontFamily = require('../../utils/findFontFamily');
  4. const isStandardSyntaxValue = require('../../utils/isStandardSyntaxValue');
  5. const isVariable = require('../../utils/isVariable');
  6. const keywordSets = require('../../reference/keywordSets');
  7. const report = require('../../utils/report');
  8. const ruleMessages = require('../../utils/ruleMessages');
  9. const validateOptions = require('../../utils/validateOptions');
  10. const ruleName = 'font-family-name-quotes';
  11. const messages = ruleMessages(ruleName, {
  12. expected: (family) => `Expected quotes around "${family}"`,
  13. rejected: (family) => `Unexpected quotes around "${family}"`,
  14. });
  15. function isSystemFontKeyword(font) {
  16. if (font.startsWith('-apple-')) {
  17. return true;
  18. }
  19. if (font === 'BlinkMacSystemFont') {
  20. return true;
  21. }
  22. return false;
  23. }
  24. // "To avoid mistakes in escaping, it is recommended to quote font family names
  25. // that contain white space, digits, or punctuation characters other than hyphens"
  26. // (https://www.w3.org/TR/CSS2/fonts.html#font-family-prop)
  27. function quotesRecommended(family) {
  28. return !/^[-a-zA-Z]+$/.test(family);
  29. }
  30. // Quotes are required if the family is not a valid CSS identifier
  31. // (regexes from https://mathiasbynens.be/notes/unquoted-font-family)
  32. function quotesRequired(family) {
  33. return family.split(/\s+/).some((word) => {
  34. return /^(-?\d|--)/.test(word) || !/^[-_a-zA-Z0-9\u{00A0}-\u{10FFFF}]+$/u.test(word);
  35. });
  36. }
  37. function rule(expectation) {
  38. return (root, result) => {
  39. const validOptions = validateOptions(result, ruleName, {
  40. actual: expectation,
  41. possible: ['always-where-required', 'always-where-recommended', 'always-unless-keyword'],
  42. });
  43. if (!validOptions) {
  44. return;
  45. }
  46. root.walkDecls(/^font(-family)?$/i, (decl) => {
  47. const fontFamilies = findFontFamily(decl.value);
  48. if (fontFamilies.length === 0) {
  49. return;
  50. }
  51. fontFamilies.forEach((fontFamilyNode) => {
  52. let rawFamily = fontFamilyNode.value;
  53. if (fontFamilyNode.quote) {
  54. rawFamily = fontFamilyNode.quote + rawFamily + fontFamilyNode.quote;
  55. }
  56. checkFamilyName(rawFamily, decl);
  57. });
  58. });
  59. function checkFamilyName(rawFamily, decl) {
  60. if (!isStandardSyntaxValue(rawFamily)) {
  61. return;
  62. }
  63. if (isVariable(rawFamily)) {
  64. return;
  65. }
  66. const hasQuotes = rawFamily.startsWith("'") || rawFamily.startsWith('"');
  67. // Clean the family of its quotes
  68. const family = rawFamily.replace(/^['"]|['"]$/g, '');
  69. // Disallow quotes around (case-insensitive) keywords
  70. // and system font keywords in all cases
  71. if (keywordSets.fontFamilyKeywords.has(family.toLowerCase()) || isSystemFontKeyword(family)) {
  72. if (hasQuotes) {
  73. return complain(messages.rejected(family), family, decl);
  74. }
  75. return;
  76. }
  77. const required = quotesRequired(family);
  78. const recommended = quotesRecommended(family);
  79. switch (expectation) {
  80. case 'always-unless-keyword':
  81. if (!hasQuotes) {
  82. return complain(messages.expected(family), family, decl);
  83. }
  84. return;
  85. case 'always-where-recommended':
  86. if (!recommended && hasQuotes) {
  87. return complain(messages.rejected(family), family, decl);
  88. }
  89. if (recommended && !hasQuotes) {
  90. return complain(messages.expected(family), family, decl);
  91. }
  92. return;
  93. case 'always-where-required':
  94. if (!required && hasQuotes) {
  95. return complain(messages.rejected(family), family, decl);
  96. }
  97. if (required && !hasQuotes) {
  98. return complain(messages.expected(family), family, decl);
  99. }
  100. }
  101. }
  102. function complain(message, family, decl) {
  103. report({
  104. result,
  105. ruleName,
  106. message,
  107. node: decl,
  108. word: family,
  109. });
  110. }
  111. };
  112. }
  113. rule.ruleName = ruleName;
  114. rule.messages = messages;
  115. module.exports = rule;