All files / packages/sds-stylelint-config/src/utils validateElement.js

0% Statements 0/14
0% Branches 0/12
0% Functions 0/1
0% Lines 0/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27                                                     
const { removeFromSet } = require('./search');
 
/**
 * Validate the existence of an element
 * @param {Object} obj The object from the first Promise that has valuable information about the custom prop
 * @returns {Object} Validation object or original object to pass along to next function or definition to skip if no element
 */
const validateElement = (obj) => {
  if (obj.validate.scope.isGlobal || obj.validate.scope.isShared) return { skip: true };
  // If the context has a key of 2 and the category has a key of 4, we know its an element
  if (obj.fuzzyKeys.has(obj.keys.context + 1) && obj.keys.category === 4) {
    obj.keys.element = 3;
    obj.fuzzyKeys = removeFromSet(obj.fuzzyKeys, obj.keys.element);
    return { valid: true, received: obj.groups[obj.keys.element] };
  } else if (obj.fuzzyKeys.has(obj.keys.context + 1) && obj.keys.category === 5) {
    obj.keys.element = 4;
    obj.fuzzyKeys = removeFromSet(obj.fuzzyKeys, obj.keys.element);
    return { valid: true, received: obj.groups[obj.keys.element] };
  }
  // Skip because we can't determine an element exists
  else {
    return { skip: true };
  }
};
 
module.exports = validateElement;