getDescription.js 1008 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const _ = require('lodash');
  2. module.exports = function getDescription(item) {
  3. const descriptions = {
  4. 'custom-properties': 'custom property',
  5. 'dollar-variables': '$-variable',
  6. 'at-variables': '@-variable',
  7. 'less-mixins': 'Less mixin',
  8. declarations: 'declaration',
  9. };
  10. if (_.isPlainObject(item)) {
  11. let text;
  12. if (item.type === 'at-rule') {
  13. text = 'at-rule';
  14. if (item.name) {
  15. text = `@${item.name}`;
  16. }
  17. if (item.parameter) {
  18. text += ` "${item.parameter}"`;
  19. }
  20. if (item.hasOwnProperty('hasBlock')) {
  21. if (item.hasBlock) {
  22. text += ' with a block';
  23. } else {
  24. text = `blockless ${text}`;
  25. }
  26. }
  27. }
  28. if (item.type === 'rule') {
  29. text = 'rule';
  30. if (item.name) {
  31. // Prefer 'name' property for better error messaging
  32. text += ` "${item.name}"`;
  33. } else if (item.selector) {
  34. text += ` with selector matching "${item.selector}"`;
  35. }
  36. }
  37. return text;
  38. }
  39. // Return description for keyword patterns
  40. return descriptions[item];
  41. };