From a932cc1db29ac563f5e96b63467537115df49191 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Mon, 24 Apr 2023 13:59:08 -0400 Subject: [PATCH] Add Yaml parsing error to translation health report (#36581) --- lib/read-frontmatter.js | 2 +- script/i18n/create-translation-health-report.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/read-frontmatter.js b/lib/read-frontmatter.js index 712a2a347d..82779b5ee9 100644 --- a/lib/read-frontmatter.js +++ b/lib/read-frontmatter.js @@ -40,7 +40,7 @@ function readFrontmatter(markdown, opts = {}) { if (filepath) error.filepath = filepath errors.push(error) - console.log(errors) + console.warn(errors) return { errors } } diff --git a/script/i18n/create-translation-health-report.js b/script/i18n/create-translation-health-report.js index 17dd6432a0..080940a233 100755 --- a/script/i18n/create-translation-health-report.js +++ b/script/i18n/create-translation-health-report.js @@ -41,6 +41,20 @@ console.warn = console.error = (...args) => { } else if (args[0]?.constructor === Object) { const path = args[0].path?.replace('/index.md', '').replace('.md', '') issues.push({ path, message: args[0].message, score: scores[path] || 0 }) + } else if (Array.isArray(args[0]) && args[0][0]?.constructor === Object && args[0][0].filepath) { + // This is a YML parsing error. It's serious enough to bump the score. + let message = args[0][0].message + if (args[0][0].reason) { + message += ` (reason: ${args[0][0].reason})` + } + const path = args[0][0].filepath + // By giving it a +100 on the score, it at least stands above all the + // other issues which are mostly score 0. It's artificial but it works. + issues.push({ path, message, score: (scores[path] || 0) + 100 }) + } else { + // Don't use .warn() because this logging here is for the engineer + // working on this script. + console.log("WARNING: Don't know how to turn these args into an issue", args) } }