From 5862062cd6cb6feec81e068d5b70917efe1381c6 Mon Sep 17 00:00:00 2001 From: ya7010 Date: Thu, 30 Apr 2026 19:35:36 +0900 Subject: [PATCH] feat: add validation to ensure schemas do not use json.schemastore.org URL --- cli.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cli.js b/cli.js index ab590e593e8..d622d4cae39 100644 --- a/cli.js +++ b/cli.js @@ -697,6 +697,7 @@ async function taskCheck() { assertFileHasNoBom(schema) assertFileHasCorrectExtensions(schema.path, ['.json']) await assertFilePassesJsonLint(schema) + await assertSchemaDoesNotUseJsonSchemaStoreUrl(schema) await assertSchemaHasValidIdField(schema) await assertSchemaHasValidSchemaField(schema) }, @@ -1738,6 +1739,35 @@ async function assertFileValidatesAgainstSchema( } } +async function assertSchemaDoesNotUseJsonSchemaStoreUrl( + /** @type {SchemaFile} */ schema, +) { + const allowedUrl = 'https://www.schemastore.org' + const forbiddenUrl = 'https://json.schemastore.org' + + if (!schema.text.includes(forbiddenUrl)) { + return + } + + const matches = [] + const forbiddenUrlRegex = /https:\/\/json\.schemastore\.org/g + + for (const [index, line] of schema.text.split('\n').entries()) { + for (const match of line.matchAll(forbiddenUrlRegex)) { + const lineNumber = index + 1 + const columnStart = (match.index ?? 0) + 1 + matches.push(`${schema.path}:${lineNumber}:${columnStart}`) + } + } + + printErrorAndExit(new Error(), [ + `Expected schema file "./${schema.path}" to not use "${forbiddenUrl}"`, + `Use "${allowedUrl}" instead`, + `Failed to successfully validate file "./${schema.path}"`, + ...matches.map((match) => ` - ${match}`), + ]) +} + async function assertSchemaHasValidSchemaField( /** @type {SchemaFile} */ schema, ) {