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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const declarationValueIndex = require('../../utils/declarationValueIndex');
  5. const getDeclarationValue = require('../../utils/getDeclarationValue');
  6. const isStandardSyntaxFunction = require('../../utils/isStandardSyntaxFunction');
  7. const keywordSets = require('../../reference/keywordSets');
  8. const matchesStringOrRegExp = require('../../utils/matchesStringOrRegExp');
  9. const report = require('../../utils/report');
  10. const ruleMessages = require('../../utils/ruleMessages');
  11. const setDeclarationValue = require('../../utils/setDeclarationValue');
  12. const validateOptions = require('../../utils/validateOptions');
  13. const valueParser = require('postcss-value-parser');
  14. const ruleName = 'function-name-case';
  15. const messages = ruleMessages(ruleName, {
  16. expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
  17. });
  18. const mapLowercaseFunctionNamesToCamelCase = new Map();
  19. keywordSets.camelCaseFunctionNames.forEach((func) => {
  20. mapLowercaseFunctionNamesToCamelCase.set(func.toLowerCase(), func);
  21. });
  22. function rule(expectation, options, context) {
  23. return (root, result) => {
  24. const validOptions = validateOptions(
  25. result,
  26. ruleName,
  27. {
  28. actual: expectation,
  29. possible: ['lower', 'upper'],
  30. },
  31. {
  32. actual: options,
  33. possible: {
  34. ignoreFunctions: [_.isString, _.isRegExp],
  35. },
  36. optional: true,
  37. },
  38. );
  39. if (!validOptions) {
  40. return;
  41. }
  42. root.walkDecls((decl) => {
  43. let needFix = false;
  44. const parsed = valueParser(getDeclarationValue(decl));
  45. parsed.walk((node) => {
  46. if (node.type !== 'function' || !isStandardSyntaxFunction(node)) {
  47. return;
  48. }
  49. const functionName = node.value;
  50. const functionNameLowerCase = functionName.toLowerCase();
  51. const ignoreFunctions = (options && options.ignoreFunctions) || [];
  52. if (ignoreFunctions.length > 0 && matchesStringOrRegExp(functionName, ignoreFunctions)) {
  53. return;
  54. }
  55. let expectedFunctionName = null;
  56. if (
  57. expectation === 'lower' &&
  58. mapLowercaseFunctionNamesToCamelCase.has(functionNameLowerCase)
  59. ) {
  60. expectedFunctionName = mapLowercaseFunctionNamesToCamelCase.get(functionNameLowerCase);
  61. } else if (expectation === 'lower') {
  62. expectedFunctionName = functionNameLowerCase;
  63. } else {
  64. expectedFunctionName = functionName.toUpperCase();
  65. }
  66. if (functionName === expectedFunctionName) {
  67. return;
  68. }
  69. if (context.fix) {
  70. needFix = true;
  71. node.value = expectedFunctionName;
  72. return;
  73. }
  74. report({
  75. message: messages.expected(functionName, expectedFunctionName),
  76. node: decl,
  77. index: declarationValueIndex(decl) + node.sourceIndex,
  78. result,
  79. ruleName,
  80. });
  81. });
  82. if (context.fix && needFix) {
  83. setDeclarationValue(decl, parsed.toString());
  84. }
  85. });
  86. };
  87. }
  88. rule.ruleName = ruleName;
  89. rule.messages = messages;
  90. module.exports = rule;