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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | const chalk = require('chalk'); const { analyzeFuzzy, removeFromSet } = require('./search'); const metadata = require('../metadata/metadata.js'); /** * Validate Property * @param {Object} obj The object from the first Promise that has valuable information about the custom prop * @todo Skip scope validation based on stylelint option * @returns {Object} Validation object or definition to skip if not found */ const validateProperty = (obj) => { if (obj.validate.scope.isGlobal || obj.validate.scope.isShared) return { skip: true }; const results = analyzeFuzzy(obj).filter((item) => item.word); // If key has already been stored, we know its valid if (obj.keys.property) { return { valid: true, received: obj.groups[obj.keys.property] }; } // Check that something exists after the category key while ensuring its not an attribute, state, or psuedoState else if (obj.fuzzyKeys.size > 0 && results.length > 0) { let valid; results.map((item) => { if (obj.keys.category && obj.keys.attribute && metadata.component.valid.attribute.includes(item.word)) { valid = { valid: false, received: item.word }; obj.customMessage.push( `We received "${chalk.bold( item.word, )}" and have determine you are using more than one attribute. Please use only one of the following: ${chalk.bold( metadata.component.valid.attribute, )}.`, ); } else if (obj.keys.category && item.key === obj.keys.category + 1) { obj.keys.property = obj.keys.category + 1; obj.fuzzyKeys = removeFromSet(obj.fuzzyKeys, obj.keys.property); valid = { valid: false, expected: metadata.component.valid.property, received: obj.groups[obj.keys.property], }; } else if (obj.keys.category && obj.keys.attribute) { valid = { skip: true }; } }); return valid; } else { return { skip: true }; } }; module.exports = validateProperty; |