From c03090b7f6ada361ebaaa7e7b97a629ebc509b4e Mon Sep 17 00:00:00 2001
From: Daniel Shuy <daniel_shuy@hotmail.com>
Date: Fri, 19 Jun 2020 21:18:16 +0800
Subject: [PATCH] Enhance config-validator to support JSON5 (#6551)

---
 lib/config-validator.ts | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/config-validator.ts b/lib/config-validator.ts
index 69a2ec2292..eaa5851951 100644
--- a/lib/config-validator.ts
+++ b/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';
@@ -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;
   }
@@ -44,10 +45,10 @@ 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) {
@@ -55,7 +56,7 @@ type PackageJson = {
     }
   }
   try {
-    const pkgJson = JSON.parse(
+    const pkgJson = JSON5.parse(
       readFileSync('package.json', 'utf8')
     ) as PackageJson;
     if (pkgJson.renovate) {
-- 
GitLab