From 44064880b4582606be211aafb89e43f3907a7130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Thu, 31 Mar 2022 06:30:30 -0600 Subject: [PATCH] Normalize newline characters reading README in scripts (#7292) --- scripts/lint/ourlint.js | 4 ++-- scripts/utils.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/lint/ourlint.js b/scripts/lint/ourlint.js index 293bc0e9c..677775a4a 100644 --- a/scripts/lint/ourlint.js +++ b/scripts/lint/ourlint.js @@ -6,7 +6,7 @@ */ import fakeDiff from 'fake-diff'; -import { getIconsDataString } from '../utils.js'; +import { getIconsDataString, normalizeNewlines } from '../utils.js'; /** * Contains our tests so they can be isolated from each other. @@ -47,7 +47,7 @@ const TESTS = { /* Check the formatting of the data file */ prettified: async (data, dataString) => { - const normalizedDataString = dataString.replace(/\r\n/g, '\n'); + const normalizedDataString = normalizeNewlines(dataString); const dataPretty = `${JSON.stringify(data, null, ' ')}\n`; if (normalizedDataString !== dataPretty) { diff --git a/scripts/utils.js b/scripts/utils.js index a38c863f5..1193310af 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -118,13 +118,23 @@ export const getIconsData = async () => { export const getDirnameFromImportMeta = (importMetaUrl) => path.dirname(fileURLToPath(importMetaUrl)); +/** + * Replace Windows newline characters by Unix ones. + * @param {String} text The text to replace + */ +export const normalizeNewlines = (text) => { + return text.replace(/\r\n/g, '\n'); +}; + /** * Get information about third party extensions. */ export const getThirdPartyExtensions = async () => { const __dirname = getDirnameFromImportMeta(import.meta.url); const readmePath = path.resolve(__dirname, '..', 'README.md'); - const readmeContent = await fs.readFile(readmePath, 'utf8'); + const readmeContent = normalizeNewlines( + await fs.readFile(readmePath, 'utf8'), + ); return readmeContent .split('## Third-Party Extensions\n\n')[1] .split('\n\n')[0]