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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // @ts-nocheck
  2. 'use strict';
  3. const atRuleParamIndex = require('../../utils/atRuleParamIndex');
  4. const functionArgumentsSearch = require('../../utils/functionArgumentsSearch');
  5. const isStandardSyntaxUrl = require('../../utils/isStandardSyntaxUrl');
  6. const optionsMatches = require('../../utils/optionsMatches');
  7. const report = require('../../utils/report');
  8. const ruleMessages = require('../../utils/ruleMessages');
  9. const validateOptions = require('../../utils/validateOptions');
  10. const ruleName = 'function-url-quotes';
  11. const messages = ruleMessages(ruleName, {
  12. expected: () => 'Expected quotes',
  13. rejected: () => 'Unexpected quotes',
  14. });
  15. function rule(expectation, options) {
  16. return (root, result) => {
  17. const validOptions = validateOptions(
  18. result,
  19. ruleName,
  20. {
  21. actual: expectation,
  22. possible: ['always', 'never'],
  23. },
  24. {
  25. actual: options,
  26. possible: {
  27. except: ['empty'],
  28. },
  29. optional: true,
  30. },
  31. );
  32. if (!validOptions) {
  33. return;
  34. }
  35. root.walkAtRules(checkAtRuleParams);
  36. root.walkDecls(checkDeclParams);
  37. function checkDeclParams(decl) {
  38. functionArgumentsSearch(decl.toString().toLowerCase(), 'url', (args, index) => {
  39. checkArgs(args, decl, index, 'url');
  40. });
  41. }
  42. function checkAtRuleParams(atRule) {
  43. const atRuleParamsLowerCase = atRule.params.toLowerCase();
  44. functionArgumentsSearch(atRuleParamsLowerCase, 'url', (args, index) => {
  45. checkArgs(args, atRule, index + atRuleParamIndex(atRule), 'url');
  46. });
  47. functionArgumentsSearch(atRuleParamsLowerCase, 'url-prefix', (args, index) => {
  48. checkArgs(args, atRule, index + atRuleParamIndex(atRule), 'url-prefix');
  49. });
  50. functionArgumentsSearch(atRuleParamsLowerCase, 'domain', (args, index) => {
  51. checkArgs(args, atRule, index + atRuleParamIndex(atRule), 'domain');
  52. });
  53. }
  54. function checkArgs(args, node, index, functionName) {
  55. let shouldHasQuotes = expectation === 'always';
  56. const leftTrimmedArgs = args.trimStart();
  57. if (!isStandardSyntaxUrl(leftTrimmedArgs)) {
  58. return;
  59. }
  60. const complaintIndex = index + args.length - leftTrimmedArgs.length;
  61. const hasQuotes = leftTrimmedArgs.startsWith("'") || leftTrimmedArgs.startsWith('"');
  62. const trimmedArg = args.trim();
  63. const isEmptyArgument = ['', "''", '""'].includes(trimmedArg);
  64. if (optionsMatches(options, 'except', 'empty') && isEmptyArgument) {
  65. shouldHasQuotes = !shouldHasQuotes;
  66. }
  67. if (shouldHasQuotes) {
  68. if (hasQuotes) {
  69. return;
  70. }
  71. complain(messages.expected(functionName), node, complaintIndex);
  72. } else {
  73. if (!hasQuotes) {
  74. return;
  75. }
  76. complain(messages.rejected(functionName), node, complaintIndex);
  77. }
  78. }
  79. function complain(message, node, index) {
  80. report({
  81. message,
  82. node,
  83. index,
  84. result,
  85. ruleName,
  86. });
  87. }
  88. };
  89. }
  90. rule.ruleName = ruleName;
  91. rule.messages = messages;
  92. module.exports = rule;