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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // @ts-nocheck
  2. 'use strict';
  3. const blockString = require('../../utils/blockString');
  4. const nextNonCommentNode = require('../../utils/nextNonCommentNode');
  5. const rawNodeString = require('../../utils/rawNodeString');
  6. const report = require('../../utils/report');
  7. const ruleMessages = require('../../utils/ruleMessages');
  8. const validateOptions = require('../../utils/validateOptions');
  9. const whitespaceChecker = require('../../utils/whitespaceChecker');
  10. const ruleName = 'declaration-block-semicolon-newline-after';
  11. const messages = ruleMessages(ruleName, {
  12. expectedAfter: () => 'Expected newline after ";"',
  13. expectedAfterMultiLine: () => 'Expected newline after ";" in a multi-line declaration block',
  14. rejectedAfterMultiLine: () => 'Unexpected newline after ";" in a multi-line declaration block',
  15. });
  16. function rule(expectation, options, context) {
  17. const checker = whitespaceChecker('newline', expectation, messages);
  18. return (root, result) => {
  19. const validOptions = validateOptions(result, ruleName, {
  20. actual: expectation,
  21. possible: ['always', 'always-multi-line', 'never-multi-line'],
  22. });
  23. if (!validOptions) {
  24. return;
  25. }
  26. root.walkDecls((decl) => {
  27. // Ignore last declaration if there's no trailing semicolon
  28. const parentRule = decl.parent;
  29. if (!parentRule.raws.semicolon && parentRule.last === decl) {
  30. return;
  31. }
  32. const nextNode = decl.next();
  33. if (!nextNode) {
  34. return;
  35. }
  36. // Allow end-of-line comment
  37. const nodeToCheck = nextNonCommentNode(nextNode);
  38. if (!nodeToCheck) {
  39. return;
  40. }
  41. checker.afterOneOnly({
  42. source: rawNodeString(nodeToCheck),
  43. index: -1,
  44. lineCheckStr: blockString(parentRule),
  45. err: (m) => {
  46. if (context.fix) {
  47. if (expectation.startsWith('always')) {
  48. const index = nodeToCheck.raws.before.search(/\r?\n/);
  49. if (index >= 0) {
  50. nodeToCheck.raws.before = nodeToCheck.raws.before.slice(index);
  51. } else {
  52. nodeToCheck.raws.before = context.newline + nodeToCheck.raws.before;
  53. }
  54. return;
  55. }
  56. if (expectation === 'never-multi-line') {
  57. nodeToCheck.raws.before = '';
  58. return;
  59. }
  60. }
  61. report({
  62. message: m,
  63. node: decl,
  64. index: decl.toString().length + 1,
  65. result,
  66. ruleName,
  67. });
  68. },
  69. });
  70. });
  71. };
  72. }
  73. rule.ruleName = ruleName;
  74. rule.messages = messages;
  75. module.exports = rule;