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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // @ts-nocheck
  2. 'use strict';
  3. const _ = require('lodash');
  4. const eachDeclarationBlock = require('../../utils/eachDeclarationBlock');
  5. const isCustomProperty = require('../../utils/isCustomProperty');
  6. const isStandardSyntaxProperty = require('../../utils/isStandardSyntaxProperty');
  7. const optionsMatches = require('../../utils/optionsMatches');
  8. const report = require('../../utils/report');
  9. const ruleMessages = require('../../utils/ruleMessages');
  10. const validateOptions = require('../../utils/validateOptions');
  11. const ruleName = 'declaration-block-no-duplicate-properties';
  12. const messages = ruleMessages(ruleName, {
  13. rejected: (property) => `Unexpected duplicate "${property}"`,
  14. });
  15. function rule(on, options) {
  16. return (root, result) => {
  17. const validOptions = validateOptions(
  18. result,
  19. ruleName,
  20. { actual: on },
  21. {
  22. actual: options,
  23. possible: {
  24. ignore: ['consecutive-duplicates', 'consecutive-duplicates-with-different-values'],
  25. ignoreProperties: [_.isString],
  26. },
  27. optional: true,
  28. },
  29. );
  30. if (!validOptions) {
  31. return;
  32. }
  33. eachDeclarationBlock(root, (eachDecl) => {
  34. const decls = [];
  35. const values = [];
  36. eachDecl((decl) => {
  37. const prop = decl.prop;
  38. const value = decl.value;
  39. if (!isStandardSyntaxProperty(prop)) {
  40. return;
  41. }
  42. if (isCustomProperty(prop)) {
  43. return;
  44. }
  45. // Return early if the property is to be ignored
  46. if (optionsMatches(options, 'ignoreProperties', prop)) {
  47. return;
  48. }
  49. // Ignore the src property as commonly duplicated in at-fontface
  50. if (prop.toLowerCase() === 'src') {
  51. return;
  52. }
  53. const indexDuplicate = decls.indexOf(prop.toLowerCase());
  54. if (indexDuplicate !== -1) {
  55. if (optionsMatches(options, 'ignore', 'consecutive-duplicates-with-different-values')) {
  56. // if duplicates are not consecutive
  57. if (indexDuplicate !== decls.length - 1) {
  58. report({
  59. message: messages.rejected(prop),
  60. node: decl,
  61. result,
  62. ruleName,
  63. });
  64. return;
  65. }
  66. // if values of consecutive duplicates are equal
  67. if (value === values[indexDuplicate]) {
  68. report({
  69. message: messages.rejected(value),
  70. node: decl,
  71. result,
  72. ruleName,
  73. });
  74. return;
  75. }
  76. return;
  77. }
  78. if (
  79. optionsMatches(options, 'ignore', 'consecutive-duplicates') &&
  80. indexDuplicate === decls.length - 1
  81. ) {
  82. return;
  83. }
  84. report({
  85. message: messages.rejected(prop),
  86. node: decl,
  87. result,
  88. ruleName,
  89. });
  90. }
  91. decls.push(prop.toLowerCase());
  92. values.push(value.toLowerCase());
  93. });
  94. });
  95. };
  96. }
  97. rule.ruleName = ruleName;
  98. rule.messages = messages;
  99. module.exports = rule;