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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | const chalk = require('chalk'); const metadata = require('../../metadata/metadata.js'); const { analyzeFuzzy, removeFromSet } = require('../search'); /** * Validate Pairing * @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 */ const validateGlobalPairing = (obj) => { if (obj.validate.scope.isComponent || obj.validate.scope.isShared) return { skip: true }; const results = analyzeFuzzy(obj).filter((item) => item.word); // --slds-g-font-size-on-surface-1 if (obj.keys.category && obj.validate.category.received !== 'color' && obj.keys.role >= 4) { obj.customMessage.push( `We received "${chalk.bold( obj.groups[obj.keys.pairing], )}" to be paired with a category other than ${chalk.bold( 'color', )}. We only support pairings for ${chalk.bold('color')} on a ${chalk.bold('role')}.`, ); return { valid: false, }; } // --slds-g-color-on if (obj.keys.pairing === 3 && obj.lastKey === 3) { obj.customMessage.push( `We received "${chalk.bold( obj.groups[obj.keys.pairing], )}" as the last value in the custom property. A global styling hook requires a numerical range as the last value.`, ); return { valid: false, }; } // --slds-g-color-on-1 else if (obj.keys.pairing === 3 && obj.lastKey === 4) { obj.customMessage.push( `We received "${chalk.bold( obj.groups[obj.keys.pairing], )}" as the pairing key but no role has been set. Please combined a pairing key with a role, available options are ${chalk.bold( metadata.global.valid.role, )}.`, ); return { valid: false, }; } // --slds-g-color-on-surface-1 else if (obj.keys.pairing === 3 && obj.lastKey >= 5) { return { valid: true, received: obj.groups[obj.keys.pairing] }; } // We have a previous customMessage, meaning we have already failed a validation else if (obj.customMessage.length > 0) { return { skip: true }; } // We have unknown keys, lets check if they are optional else if (obj.fuzzyKeys.size > 0 && results.length > 0) { let valid; results.map((item) => { if (obj.keys.property === 3 && obj.keys.role === 4) { valid = { skip: true }; } // --slds-g-color-onnnn-surface-1 else if (obj.keys.category === 2 && obj.keys.role === 4) { obj.keys.pairing = obj.keys.category + 1; obj.fuzzyKeys = removeFromSet(obj.fuzzyKeys, obj.keys.pairing); valid = { valid: false, expected: metadata.global.valid.pairing, received: obj.groups[obj.keys.pairing], }; } // --slds-g-color-foo-border-1, --slds-g-color-foo-bar-border-1 else if ((obj.keys.property === 4 && item.key === 3) || results.length >= 2) { valid = { skip: true }; } else { valid = { skip: true }; } }); return valid; } else { // This is an optional key so skip return { skip: true }; } }; module.exports = validateGlobalPairing; |