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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // @ts-nocheck
  2. 'use strict';
  3. const getRuleSelector = require('../../utils/getRuleSelector');
  4. const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
  5. const parseSelector = require('../../utils/parseSelector');
  6. const report = require('../../utils/report');
  7. const ruleMessages = require('../../utils/ruleMessages');
  8. const validateOptions = require('../../utils/validateOptions');
  9. const ruleName = 'selector-attribute-quotes';
  10. const messages = ruleMessages(ruleName, {
  11. expected: (value) => `Expected quotes around "${value}"`,
  12. rejected: (value) => `Unexpected quotes around "${value}"`,
  13. });
  14. const acceptedQuoteMark = '"';
  15. function rule(expectation, secondary, context) {
  16. return (root, result) => {
  17. const validOptions = validateOptions(result, ruleName, {
  18. actual: expectation,
  19. possible: ['always', 'never'],
  20. });
  21. if (!validOptions) {
  22. return;
  23. }
  24. root.walkRules((ruleNode) => {
  25. if (!isStandardSyntaxRule(ruleNode)) {
  26. return;
  27. }
  28. if (!ruleNode.selector.includes('[') || !ruleNode.selector.includes('=')) {
  29. return;
  30. }
  31. parseSelector(getRuleSelector(ruleNode), result, ruleNode, (selectorTree) => {
  32. let selectorFixed = false;
  33. selectorTree.walkAttributes((attributeNode) => {
  34. if (!attributeNode.operator) {
  35. return;
  36. }
  37. if (!attributeNode.quoted && expectation === 'always') {
  38. if (context.fix) {
  39. selectorFixed = true;
  40. attributeNode.quoteMark = acceptedQuoteMark;
  41. } else {
  42. complain(
  43. messages.expected(attributeNode.value),
  44. attributeNode.sourceIndex + attributeNode.offsetOf('value'),
  45. );
  46. }
  47. }
  48. if (attributeNode.quoted && expectation === 'never') {
  49. if (context.fix) {
  50. selectorFixed = true;
  51. attributeNode.quoteMark = null;
  52. } else {
  53. complain(
  54. messages.rejected(attributeNode.value),
  55. attributeNode.sourceIndex + attributeNode.offsetOf('value'),
  56. );
  57. }
  58. }
  59. });
  60. if (selectorFixed) {
  61. ruleNode.selector = selectorTree.toString();
  62. }
  63. });
  64. function complain(message, index) {
  65. report({
  66. message,
  67. index,
  68. result,
  69. ruleName,
  70. node: ruleNode,
  71. });
  72. }
  73. });
  74. };
  75. }
  76. rule.ruleName = ruleName;
  77. rule.messages = messages;
  78. module.exports = rule;