Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down Expand Up @@ -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,
) {
Expand Down
Loading