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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // @ts-nocheck
  2. 'use strict';
  3. const blockString = require('../../utils/blockString');
  4. const hasBlock = require('../../utils/hasBlock');
  5. const hasEmptyBlock = require('../../utils/hasEmptyBlock');
  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 = 'block-closing-brace-space-before';
  11. const messages = ruleMessages(ruleName, {
  12. expectedBefore: () => 'Expected single space before "}"',
  13. rejectedBefore: () => 'Unexpected whitespace before "}"',
  14. expectedBeforeSingleLine: () => 'Expected single space before "}" of a single-line block',
  15. rejectedBeforeSingleLine: () => 'Unexpected whitespace before "}" of a single-line block',
  16. expectedBeforeMultiLine: () => 'Expected single space before "}" of a multi-line block',
  17. rejectedBeforeMultiLine: () => 'Unexpected whitespace before "}" of a multi-line block',
  18. });
  19. function rule(expectation, options, context) {
  20. const checker = whitespaceChecker('space', expectation, messages);
  21. return (root, result) => {
  22. const validOptions = validateOptions(result, ruleName, {
  23. actual: expectation,
  24. possible: [
  25. 'always',
  26. 'never',
  27. 'always-single-line',
  28. 'never-single-line',
  29. 'always-multi-line',
  30. 'never-multi-line',
  31. ],
  32. });
  33. if (!validOptions) {
  34. return;
  35. }
  36. // Check both kinds of statement: rules and at-rules
  37. root.walkRules(check);
  38. root.walkAtRules(check);
  39. function check(statement) {
  40. // Return early if blockless or has empty block
  41. if (!hasBlock(statement) || hasEmptyBlock(statement)) {
  42. return;
  43. }
  44. const source = blockString(statement);
  45. const statementString = statement.toString();
  46. let index = statementString.length - 2;
  47. if (statementString[index - 1] === '\r') {
  48. index -= 1;
  49. }
  50. checker.before({
  51. source,
  52. index: source.length - 1,
  53. err: (msg) => {
  54. if (context.fix) {
  55. if (expectation.startsWith('always')) {
  56. statement.raws.after = statement.raws.after.replace(/\s*$/, ' ');
  57. return;
  58. }
  59. if (expectation.startsWith('never')) {
  60. statement.raws.after = statement.raws.after.replace(/\s*$/, '');
  61. return;
  62. }
  63. }
  64. report({
  65. message: msg,
  66. node: statement,
  67. index,
  68. result,
  69. ruleName,
  70. });
  71. },
  72. });
  73. }
  74. };
  75. }
  76. rule.ruleName = ruleName;
  77. rule.messages = messages;
  78. module.exports = rule;