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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // @ts-nocheck
  2. 'use strict';
  3. const hasBlock = require('../../utils/hasBlock');
  4. const optionsMatches = require('../../utils/optionsMatches');
  5. const report = require('../../utils/report');
  6. const ruleMessages = require('../../utils/ruleMessages');
  7. const validateOptions = require('../../utils/validateOptions');
  8. const ruleName = 'declaration-block-trailing-semicolon';
  9. const messages = ruleMessages(ruleName, {
  10. expected: 'Expected a trailing semicolon',
  11. rejected: 'Unexpected trailing semicolon',
  12. });
  13. function rule(expectation, options, context) {
  14. return (root, result) => {
  15. const validOptions = validateOptions(
  16. result,
  17. ruleName,
  18. {
  19. actual: expectation,
  20. possible: ['always', 'never'],
  21. },
  22. {
  23. actual: options,
  24. possible: {
  25. ignore: ['single-declaration'],
  26. },
  27. optional: true,
  28. },
  29. );
  30. if (!validOptions) {
  31. return;
  32. }
  33. root.walkAtRules((atRule) => {
  34. if (atRule.parent === root) {
  35. return;
  36. }
  37. if (atRule !== atRule.parent.last) {
  38. return;
  39. }
  40. if (hasBlock(atRule)) {
  41. return;
  42. }
  43. checkLastNode(atRule);
  44. });
  45. root.walkDecls((decl) => {
  46. if (decl.parent.type === 'object') {
  47. return;
  48. }
  49. if (decl !== decl.parent.last) {
  50. return;
  51. }
  52. checkLastNode(decl);
  53. });
  54. function checkLastNode(node) {
  55. const hasSemicolon = node.parent.raws.semicolon;
  56. const ignoreSingleDeclaration = optionsMatches(options, 'ignore', 'single-declaration');
  57. let message;
  58. if (ignoreSingleDeclaration && node.parent.first === node) {
  59. return;
  60. }
  61. if (expectation === 'always') {
  62. if (hasSemicolon) {
  63. return;
  64. }
  65. // auto-fix
  66. if (context.fix) {
  67. node.parent.raws.semicolon = true;
  68. if (node.type === 'atrule') {
  69. node.raws.between = '';
  70. node.parent.raws.after = ' ';
  71. }
  72. return;
  73. }
  74. message = messages.expected;
  75. } else if (expectation === 'never') {
  76. if (!hasSemicolon) {
  77. return;
  78. }
  79. // auto-fix
  80. if (context.fix) {
  81. node.parent.raws.semicolon = false;
  82. return;
  83. }
  84. message = messages.rejected;
  85. }
  86. report({
  87. message,
  88. node,
  89. index: node.toString().trim().length - 1,
  90. result,
  91. ruleName,
  92. });
  93. }
  94. };
  95. }
  96. rule.ruleName = ruleName;
  97. rule.messages = messages;
  98. module.exports = rule;