From 3e20fc244c6b54b445d8a0a99c515953af9e69a2 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Sat, 14 Nov 2020 12:45:30 +0800 Subject: [PATCH] Lint: Report duplicated changelog (#9666) --- scripts/lint-changelog.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/lint-changelog.js b/scripts/lint-changelog.js index 66348a2f0..fbb1a78e5 100644 --- a/scripts/lint-changelog.js +++ b/scripts/lint-changelog.js @@ -2,6 +2,7 @@ "use strict"; const fs = require("fs"); const path = require("path"); +const { outdent } = require("outdent"); const CHANGELOG_DIR = "changelog_unreleased"; const TEMPLATE_FILE = "TEMPLATE.md"; @@ -61,6 +62,7 @@ const template = fs.readFileSync( ); const [templateComment] = template.match(//); const [templateAuthorLink] = template.match(authorRegex); +const checkedFiles = new Map(); for (const category of CHANGELOG_CATEGORIES) { const files = fs.readdirSync(path.join(CHANGELOG_ROOT, category)); @@ -85,11 +87,21 @@ for (const category of CHANGELOG_CATEGORIES) { continue; } const [, prNumber] = match; + const prLink = `#${prNumber}`; + if (checkedFiles.has(prNumber)) { + showErrorMessage( + outdent` + Duplicate files for ${prLink} found. + - ${checkedFiles.get(prNumber)} + - ${displayPath} + ` + ); + } + checkedFiles.set(prNumber, displayPath); const content = fs.readFileSync( path.join(CHANGELOG_DIR, category, prFile), "utf8" ); - const prLink = `#${prNumber}`; if (!content.includes(prLink)) { showErrorMessage(`[${displayPath}]: PR link "${prLink}" is missing.`);