1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-11-16 00:59:07 +02:00
simple-icons/scripts/lint/jsonlint.js

22 lines
628 B
JavaScript
Raw Normal View History

2024-03-24 19:38:18 +02:00
#!/usr/bin/env node
/**
2024-06-06 14:40:35 +02:00
* @file
* CLI tool to run jsonschema on the simple-icons.json data file.
*/
Add icon license to JSON linting (and change JSON linting dependency) (#4945) * Add "license" object to the data file JSON schema * Add license to GNU and GNU social As an example, based on the discussion in: https://github.com/simple-icons/simple-icons/issues/1167 * Use `"additionalProperties": false` in JSON schema ... to detect properties in the data file that shouldn't be there. For more info, see: https://json-schema.org/understanding-json-schema/reference/object.html * Update JSON scheme descriptions * Switch from jsonlint2 to jsonschema This gives is better support for advanced features of JSON schema. A couple of clarifications: - There does exist a jsonschema-cli package, but it is rather limited and crucially doens't exit with a non-zero exit code if there is an error. (it is also pretty old and not maintained), hence the custom script. - I renamed .jsonlintschema 1) for clarity (lint is no longer accurate) and 2) the .json extension allows easy imorting in the script and 3) it adds syntax highlighting. - The script outputs the number of errors in the end because the output gets pretty big pretty quickly, this way you can see it easily from your CLI. - We could customize how the errors are logged, but I feel that is beyond this PR. * Two minor changes * Use `oneOf` to require URL for custom licenses The updated configuration allows the `"license"` field to be either 1) a SPDX license, optional with a URL 2) a "custom" license with a required URL Read more about the "oneOf" feature of jsonschema at: https://json-schema.org/understanding-json-schema/reference/combining.html#oneof * Include license field in Contributing Guidelines
2021-02-19 16:19:22 +02:00
import process from 'node:process';
2024-03-24 19:38:18 +02:00
import {Validator} from 'jsonschema';
import {getIconsData} from '../../sdk.mjs';
import {getJsonSchemaData} from '../utils.js';
const icons = await getIconsData();
const schema = await getJsonSchemaData();
const validator = new Validator();
2024-03-24 19:38:18 +02:00
const result = validator.validate({icons}, schema);
if (result.errors.length > 0) {
2024-03-24 19:38:18 +02:00
for (const error of result.errors) console.error(error);
console.error(`Found ${result.errors.length} error(s) in simple-icons.json`);
process.exit(1);
}