( language: string, fileName: string, fileJson: Record<string, unknown>, schemaKeys: string[] )
| 195 | * @param {String[]} schemaKeys Array of matching schema's keys |
| 196 | */ |
| 197 | const schemaValidation = ( |
| 198 | language: string, |
| 199 | fileName: string, |
| 200 | fileJson: Record<string, unknown>, |
| 201 | schemaKeys: string[] |
| 202 | ) => { |
| 203 | const fileKeys = Object.keys(flattenAnObject(fileJson)); |
| 204 | findMissingKeys(fileKeys, schemaKeys, `${language}/${fileName}.json`); |
| 205 | findExtraneousKeys(fileKeys, schemaKeys, `${language}/${fileName}.json`); |
| 206 | const emptyKeys = noEmptyObjectValues(fileJson); |
| 207 | if (emptyKeys.length) { |
| 208 | console.warn( |
| 209 | `${language}/${fileName}.json has these empty keys: ${emptyKeys.join( |
| 210 | ', ' |
| 211 | )}` |
| 212 | ); |
| 213 | } |
| 214 | // Special line to assert that objects in motivational quote are correct |
| 215 | if ( |
| 216 | fileName === 'motivation' && |
| 217 | !(fileJson.motivationalQuotes as MotivationalQuotes).every( |
| 218 | object => |
| 219 | Object.prototype.hasOwnProperty.call(object, 'quote') && |
| 220 | Object.prototype.hasOwnProperty.call(object, 'author') |
| 221 | ) |
| 222 | ) { |
| 223 | console.warn(`${language}/${fileName}.json has malformed quote objects.`); |
| 224 | } |
| 225 | console.info(`${language} ${fileName}.json validation complete`); |
| 226 | }; |
| 227 | |
| 228 | const readJsonFile = async (language: string, fileName: string) => { |
| 229 | const filePath = path.join( |
no test coverage detected