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 | const metadata = require('../metadata/metadata.js'); const validateScope = require('./validateScope'); /** * Validate context * @param {Object[]} arr An array of words from the css custom property * @param {String} location The file system path * @param {Object} keys An object of keys based on metadata * @returns {Object} Validation object */ const validateContext = (arr, location, keys) => { // if (obj.validate.scope.isGlobal || obj.validate.scope.isShared) return { skip: true }; const scope = validateScope(arr, keys); if (scope.isGlobal || scope.isShared) return { skip: true }; // Component scope checks & Shared scope checks if ( (location && location.toLowerCase() === arr[2]) || (location && location.split(/(?=[A-Z])/)[0] === arr[2]) || (location && location.split('-').join('') === arr[2]) ) { // Since we know where the context is coming from, lets update the keys to help validate other elements keys.context = 2; return { valid: true, received: arr[2] }; // Skip if global since we dont require context at the moment } else if (scope.isGlobal) { return { skip: true }; } else { keys.context = 2; return { valid: false, expected: scope.isComponent ? location.split('-').join('').toLowerCase() : scope.isShared ? metadata.global.shared : null, received: arr[2], }; } }; module.exports = validateContext; |