Files
react-native-devtools-frontend/scripts/json_validator/validate_module_json.js
T
Mathias Bynens cdcfba01d1 Restore npm run check-json functionality
Without this patch:

```
$ npm run check-json

> chrome-devtools-frontend@ check-json ~/projects/devtools/devtools-frontend
> node scripts/json_validator/validate_module_json.js

schema id ignored http://json-schema.org/draft-04/schema#
schema id ignored http://json-schema.org/draft-04/schema#
~/projects/devtools/devtools-frontend/node_modules/ajv/lib/ajv.js:92
    if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
            ^

Error: no schema with key or ref "http://json-schema.org/draft-04/schema#"
    at Ajv.validate (~/projects/devtools/devtools-frontend/node_modules/ajv/lib/ajv.js:92:19)
    at Ajv.validateSchema (~/projects/devtools/devtools-frontend/node_modules/ajv/lib/ajv.js:173:20)
    at Ajv._addSchema (~/projects/devtools/devtools-frontend/node_modules/ajv/lib/ajv.js:306:10)
    at Ajv.addSchema (~/projects/devtools/devtools-frontend/node_modules/ajv/lib/ajv.js:136:29)
    at Ajv.addMetaSchema (~/projects/devtools/devtools-frontend/node_modules/ajv/lib/ajv.js:151:8)
    at Object.<anonymous> (~/projects/devtools/devtools-frontend/scripts/json_validator/validate_module_json.js:20:5)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
```

After applying this patch:

```
$ npm run check-json

> chrome-devtools-frontend@ check-json ~/projects/devtools/devtools-frontend
> node scripts/json_validator/validate_module_json.js

schema $id ignored http://json-schema.org/draft-07/schema#
schema $id ignored http://json-schema.org/draft-07/schema#
schema $id ignored http://json-schema.org/draft-07/schema#
```

Fixed: chromium:1030215
Change-Id: Ie799ffbc9dfe50bdfedb18a0d9ac2ce63a9e4439
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1953774
Auto-Submit: Mathias Bynens <mathias@chromium.org>
Commit-Queue: Mathias Bynens <mathias@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
2019-12-09 14:28:12 +00:00

41 lines
1.4 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const utils = require('../utils');
const FRONTEND_PATH = path.resolve(__dirname, '..', '..', 'front_end');
const modules = [];
for (let dir of fs.readdirSync(FRONTEND_PATH)) {
if (!utils.isDir(path.resolve(FRONTEND_PATH, dir)))
continue;
let module = path.resolve(dir, 'module.json');
if (utils.isFile(path.resolve(FRONTEND_PATH, dir, 'module.json')))
modules.push(dir);
}
const Ajv = require('ajv');
const ajv = new Ajv({schemaId: 'id'});
// This seems to be the most widely supported version of the schema.
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
const schema = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'module.schema.json')));
const validate = ajv.compile(schema);
let totalErrors = 0;
for (let module of modules) {
const moduleObject = JSON.parse(fs.readFileSync(path.resolve(FRONTEND_PATH, module, 'module.json')));
const valid = validate(moduleObject);
if (!valid) {
console.log('Issue with ./front_end/' + module + '/module.json:');
totalErrors++;
validate.errors.sort((a, b) => b.dataPath.length - a.dataPath.length);
const error = validate.errors[0];
console.log(' ', error.dataPath, error.message, error.params);
console.log('');
}
}
if (totalErrors)
console.log('module.json errors:', totalErrors);
process.exit(totalErrors);