Skip to content

Commit

Permalink
Enhance config-validator to support JSON5 (#6551)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-shuy committed Jun 19, 2020
1 parent 86b44db commit c03090b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/config-validator.ts
@@ -1,6 +1,7 @@
#!/usr/bin/env node
// istanbul ignore file
import { readFileSync } from 'fs-extra';
import JSON5 from 'json5';
import { configFileNames } from './config/app-strings';
import { RenovateConfig } from './config/common';
import { getConfig } from './config/file';
Expand All @@ -19,13 +20,13 @@ async function validate(
const res = await validateConfig(massageConfig(config), isPreset);
if (res.errors.length) {
console.log(
`${desc} contains errors:\n\n${JSON.stringify(res.errors, null, 2)}`
`${desc} contains errors:\n\n${JSON5.stringify(res.errors, null, 2)}`
);
returnVal = 1;
}
if (res.warnings.length) {
console.log(
`${desc} contains warnings:\n\n${JSON.stringify(res.warnings, null, 2)}`
`${desc} contains warnings:\n\n${JSON5.stringify(res.warnings, null, 2)}`
);
returnVal = 1;
}
Expand All @@ -44,18 +45,18 @@ type PackageJson = {
const rawContent = readFileSync(file, 'utf8');
console.log(`Validating ${file}`);
try {
const jsonContent = JSON.parse(rawContent) as PackageJson;
const jsonContent = JSON5.parse(rawContent) as PackageJson;
await validate(file, jsonContent);
} catch (err) {
console.log(`${file} is not valid Renovate config`);
console.log(`${file} is not valid Renovate config`, err);
returnVal = 1;
}
} catch (err) {
// file does not exist
}
}
try {
const pkgJson = JSON.parse(
const pkgJson = JSON5.parse(
readFileSync('package.json', 'utf8')
) as PackageJson;
if (pkgJson.renovate) {
Expand Down

0 comments on commit c03090b

Please sign in to comment.