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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // @ts-nocheck
  2. 'use strict';
  3. const declarationValueIndex = require('../../utils/declarationValueIndex');
  4. const isStandardSyntaxDeclaration = require('../../utils/isStandardSyntaxDeclaration');
  5. const report = require('../../utils/report');
  6. const ruleMessages = require('../../utils/ruleMessages');
  7. const validateOptions = require('../../utils/validateOptions');
  8. const whitespaceChecker = require('../../utils/whitespaceChecker');
  9. const ruleName = 'declaration-colon-newline-after';
  10. const messages = ruleMessages(ruleName, {
  11. expectedAfter: () => 'Expected newline after ":"',
  12. expectedAfterMultiLine: () => 'Expected newline after ":" with a multi-line declaration',
  13. });
  14. function rule(expectation, options, context) {
  15. const checker = whitespaceChecker('newline', expectation, messages);
  16. return (root, result) => {
  17. const validOptions = validateOptions(result, ruleName, {
  18. actual: expectation,
  19. possible: ['always', 'always-multi-line'],
  20. });
  21. if (!validOptions) {
  22. return;
  23. }
  24. root.walkDecls((decl) => {
  25. if (!isStandardSyntaxDeclaration(decl)) {
  26. return;
  27. }
  28. // Get the raw prop, and only the prop
  29. const endOfPropIndex = declarationValueIndex(decl) + (decl.raws.between || '').length - 1;
  30. // The extra characters tacked onto the end ensure that there is a character to check
  31. // after the colon. Otherwise, with `background:pink` the character after the
  32. const propPlusColon = `${decl.toString().slice(0, endOfPropIndex)}xxx`;
  33. for (let i = 0, l = propPlusColon.length; i < l; i++) {
  34. if (propPlusColon[i] !== ':') {
  35. continue;
  36. }
  37. const indexToCheck = /^[^\S\r\n]*\/\*/.test(propPlusColon.slice(i + 1))
  38. ? propPlusColon.indexOf('*/', i) + 1
  39. : i;
  40. checker.afterOneOnly({
  41. source: propPlusColon,
  42. index: indexToCheck,
  43. lineCheckStr: decl.value,
  44. err: (m) => {
  45. if (context.fix) {
  46. const between = decl.raws.between;
  47. const betweenStart = declarationValueIndex(decl) - between.length;
  48. const sliceIndex = indexToCheck - betweenStart + 1;
  49. const betweenBefore = between.slice(0, sliceIndex);
  50. const betweenAfter = between.slice(sliceIndex);
  51. if (/^\s*\r?\n/.test(betweenAfter)) {
  52. decl.raws.between = betweenBefore + betweenAfter.replace(/^[^\S\r\n]*/, '');
  53. } else {
  54. decl.raws.between = betweenBefore + context.newline + betweenAfter;
  55. }
  56. return;
  57. }
  58. report({
  59. message: m,
  60. node: decl,
  61. index: indexToCheck,
  62. result,
  63. ruleName,
  64. });
  65. },
  66. });
  67. }
  68. });
  69. };
  70. }
  71. rule.ruleName = ruleName;
  72. rule.messages = messages;
  73. module.exports = rule;