simple-icons/scripts/lint/jsonlint.js

21 lines
623 B
JavaScript
Raw Normal View History

/**
* @fileoverview
* 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 14:19:22 +00:00
import process from 'node:process';
import { Validator } from 'jsonschema';
import { getIconsData } from '../../sdk.mjs';
2023-04-19 13:23:13 +00:00
import { getJsonSchemaData } from '../utils.js';
const icons = await getIconsData();
const schema = await getJsonSchemaData();
const validator = new Validator();
const result = validator.validate({ icons }, schema);
if (result.errors.length > 0) {
result.errors.forEach((error) => console.error(error));
console.error(`Found ${result.errors.length} error(s) in simple-icons.json`);
process.exit(1);
}