MCPcopy Index your code
hub / github.com/SchemaStore/schemastore / assertCatalogJsonHasNoBadFields

Function assertCatalogJsonHasNoBadFields

cli.js:1315–1371  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1313}
1314
1315function assertCatalogJsonHasNoBadFields() {
1316 for (const catalogEntry of Catalog.schemas) {
1317 if (
1318 SchemaValidation.catalogEntryNoLintNameOrDescription.includes(
1319 catalogEntry.url,
1320 )
1321 ) {
1322 continue
1323 }
1324
1325 for (const property of /** @type {const} */ (['name', 'description'])) {
1326 if (
1327 /$[,. \t-]/u.test(catalogEntry?.[property]) ||
1328 /[,. \t-]$/u.test(catalogEntry?.[property])
1329 ) {
1330 printErrorAndExit(new Error(), [
1331 `Expected the "name" or "description" properties of catalog entries to not end with characters ",.<space><tab>-"`,
1332 `The invalid entry has a "url" of "${catalogEntry.url}" in file "${CatalogFile}"`,
1333 ])
1334 }
1335 }
1336
1337 for (const property of /** @type {const} */ (['name', 'description'])) {
1338 if (catalogEntry?.[property]?.toLowerCase()?.includes('schema')) {
1339 printErrorAndExit(new Error(), [
1340 `Expected the "name" or "description" properties of entries in "${CatalogFile}" to not include the word "schema"`,
1341 `All specified files are already schemas, so its meaning is implied`,
1342 `If the JSON schema is actually a meta-schema (or some other exception applies), ignore this error by appending to the property "catalogEntryNoLintNameOrDescription" in file "${SchemaValidationFile}"`,
1343 `The invalid entry has a "url" of "${catalogEntry.url}" in file "${CatalogFile}"`,
1344 ])
1345 }
1346 }
1347
1348 for (const property of /** @type {const} */ (['name', 'description'])) {
1349 if (catalogEntry?.[property]?.toLowerCase()?.includes('\n')) {
1350 printErrorAndExit(new Error(), [
1351 `Expected the "name" or "description" properties of catalog entries to not include a newline character"`,
1352 `The invalid entry has a "url" of "${catalogEntry.url}" in file "${CatalogFile}"`,
1353 ])
1354 }
1355 }
1356
1357 for (const fileGlob of catalogEntry.fileMatch ?? []) {
1358 if (fileGlob.includes('/')) {
1359 // A folder must start with **/
1360 if (!fileGlob.startsWith('**/')) {
1361 printErrorAndExit(new Error(), [
1362 'Expected the "fileMatch" values of catalog entries to start with "**/" if it matches a directory',
1363 `The invalid entry has a "url" of "${catalogEntry.url}" in file "${CatalogFile}"`,
1364 ])
1365 }
1366 }
1367 }
1368 }
1369
1370 console.info(`✔️ catalog.json has no fields that break guidelines`)
1371}
1372

Callers 1

taskCheckFunction · 0.85

Calls 1

printErrorAndExitFunction · 0.85

Tested by

no test coverage detected